本文整理汇总了C++中QDomElement::replaceChild方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomElement::replaceChild方法的具体用法?C++ QDomElement::replaceChild怎么用?C++ QDomElement::replaceChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomElement
的用法示例。
在下文中一共展示了QDomElement::replaceChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setStatusAndMessage
void SapoRemoteOptionsMgr::setStatusAndMessage(const QString &show, const QString &status)
{
if (!_remotelySavedXML.isNull() && (show != _remotelySavedShow || status != _remotelySavedStatus)) {
_remotelySavedShow = show;
_remotelySavedStatus = status;
QDomElement presenceNode = _remotelySavedXML.firstChildElement("mod_presence");
QDomElement oldStatusNode = presenceNode.firstChildElement("var_status");
QDomElement oldShowNode = presenceNode.firstChildElement("var_show");
QDomElement newShowNode = _client->doc()->createElement("var_show");
QDomText newShowNodeContents = _client->doc()->createTextNode(show);
newShowNode.appendChild(newShowNodeContents);
presenceNode.replaceChild(newShowNode, oldShowNode);
QDomElement newStatusNode = _client->doc()->createElement("var_status");
QDomText newStatusNodeContents = _client->doc()->createTextNode(status);
newStatusNode.appendChild(newStatusNodeContents);
presenceNode.replaceChild(newStatusNode, oldStatusNode);
setRemoteOptions(_remotelySavedXML);
}
}
示例2: updateDomElement
void Bookmarks::updateDomElement(QTreeWidgetItem* item, int column)
{
QDomElement element = m_domElementForItem.value(item);
if (!element.isNull()) {
if (column == 0) {
QDomElement oldTitleElement = element.firstChildElement("title");
QDomElement newTitleElement = m_domDocument.createElement("title");
QDomText newTitleText = m_domDocument.createTextNode(item->text(0));
newTitleElement.appendChild(newTitleText);
element.replaceChild(newTitleElement, oldTitleElement);
}
else {
if (element.tagName() == "bookmark") {
QDomElement oldDescElement = element.firstChildElement("desc");
QDomElement newDescElement = m_domDocument.createElement("desc");
QDomText newDesc = m_domDocument.createTextNode(item->text(1));//setAttribute("href", item->text(1));
newDescElement.appendChild(newDesc);
element.replaceChild(newDescElement, oldDescElement);
element.setAttribute("href", item->data(1, Qt::UserRole).toString());
}
}
}
}
示例3: SetXmlNodeContent
bool XmlHelper::SetXmlNodeContent(const QString &tag_name, const QString &text)
{
QDomElement root = doc_.documentElement();
QDomNodeList node_list = root.elementsByTagName(tag_name);
if (node_list.count() > 0)
{
QDomElement elems = node_list.at(0).toElement();
QDomNode old_node = elems.firstChild();
if (elems.firstChild().isText())
{
elems.firstChild().setNodeValue(text);
QDomNode new_node = elems.firstChild();
elems.replaceChild(new_node, old_node);
}
else
{
// elems.firstChild().setNodeValue(text);
// QDomText text_node;
// text_node.setNodeValue(text);
// QDomNode new_node = elems.firstChild();
// new_node.appendChild(text_node);
// elems.replaceChild(new_node, old_node);
QDomText text_node = doc_.createTextNode(text);
node_list.at(0).appendChild(text_node);
}
return true;
}
return false;
}
示例4: SetChildNodeValue
bool XmlHelper::SetChildNodeValue(const QString &parent_tag, const QString &child_tag, QString &text)
{
QDomElement root = doc_.documentElement();
QDomNodeList nodelist = root.elementsByTagName(parent_tag);
if (nodelist.count() == 0)
{
return false;
}
QDomNodeList childs = nodelist.at(0).childNodes();
for (int i = 0; i < childs.count(); i++)
{
QDomNode child = childs.at(i);
if (child.nodeName() == child_tag)
{
QDomElement elems = child.toElement();
if (elems.firstChild().isText())
{
elems.firstChild().setNodeValue(text);
}
else
{
QDomText text_node;
text_node.setNodeValue(text);
elems.replaceChild(text_node, elems.firstChild());
}
return true;
}
}
return false;
}
示例5:
void QgsProjectFileTransform::transform1400to1500()
{
//Adapt the XML description of the composer legend model to version 1.5
if ( mDom.isNull() )
{
return;
}
//Add layer id to <VectorClassificationItem>
QDomNodeList layerItemList = mDom.elementsByTagName( "LayerItem" );
QDomElement currentLayerItemElem;
QString currentLayerId;
for ( int i = 0; i < layerItemList.size(); ++i )
{
currentLayerItemElem = layerItemList.at( i ).toElement();
if ( currentLayerItemElem.isNull() )
{
continue;
}
currentLayerId = currentLayerItemElem.attribute( "layerId" );
QDomNodeList vectorClassificationList = currentLayerItemElem.elementsByTagName( "VectorClassificationItem" );
QDomElement currentClassificationElem;
for ( int j = 0; j < vectorClassificationList.size(); ++j )
{
currentClassificationElem = vectorClassificationList.at( j ).toElement();
if ( !currentClassificationElem.isNull() )
{
currentClassificationElem.setAttribute( "layerId", currentLayerId );
}
}
//replace the text items with VectorClassification or RasterClassification items
QDomNodeList textItemList = currentLayerItemElem.elementsByTagName( "TextItem" );
QDomElement currentTextItem;
for ( int j = 0; j < textItemList.size(); ++j )
{
currentTextItem = textItemList.at( j ).toElement();
if ( currentTextItem.isNull() )
{
continue;
}
QDomElement classificationElement;
if ( vectorClassificationList.size() > 0 ) //we guess it is a vector layer
{
classificationElement = mDom.createElement( "VectorClassificationItem" );
}
else
{
classificationElement = mDom.createElement( "RasterClassificationItem" );
}
classificationElement.setAttribute( "layerId", currentLayerId );
classificationElement.setAttribute( "text", currentTextItem.attribute( "text" ) );
currentLayerItemElem.replaceChild( classificationElement, currentTextItem );
}
}
}
示例6: parsePropertyHideElement
void writeJob::parsePropertyHideElement(QDomElement property,bool checked)
{
QDomElement oldHideEle=property.firstChildElement("hide");
QDomElement newHideEle = doc.createElement("hide");
// newHideEle.setAttribute("name",oldDisplayType.attribute("name")); //保留控件类型
if(checked==true)
{
QDomText newHideTxt = doc.createTextNode("NO");
newHideEle.appendChild(newHideTxt);
property.replaceChild(newHideEle,oldHideEle);
}
if(checked==false)
{
QDomText newHideTxt = doc.createTextNode("YES");
newHideEle.appendChild(newHideTxt);
property.replaceChild(newHideEle,oldHideEle);
}
}
示例7: myPrinter
void QgsProjectFileTransform::transform0100to0110()
{
if ( ! mDom.isNull() )
{
#ifndef QT_NO_PRINTER
//Change 'outlinewidth' in QgsSymbol
QPrinter myPrinter( QPrinter::ScreenResolution );
int screenDpi = myPrinter.resolution();
double widthScaleFactor = 25.4 / screenDpi;
QDomNodeList outlineWidthList = mDom.elementsByTagName( QStringLiteral( "outlinewidth" ) );
for ( int i = 0; i < outlineWidthList.size(); ++i )
{
//calculate new width
QDomElement currentOutlineElem = outlineWidthList.at( i ).toElement();
double outlineWidth = currentOutlineElem.text().toDouble();
outlineWidth *= widthScaleFactor;
//replace old text node
QDomNode outlineTextNode = currentOutlineElem.firstChild();
QDomText newOutlineText = mDom.createTextNode( QString::number( outlineWidth ) );
currentOutlineElem.replaceChild( newOutlineText, outlineTextNode );
}
//Change 'pointsize' in QgsSymbol
QDomNodeList pointSizeList = mDom.elementsByTagName( QStringLiteral( "pointsize" ) );
for ( int i = 0; i < pointSizeList.size(); ++i )
{
//calculate new size
QDomElement currentPointSizeElem = pointSizeList.at( i ).toElement();
double pointSize = currentPointSizeElem.text().toDouble();
pointSize *= widthScaleFactor;
//replace old text node
QDomNode pointSizeTextNode = currentPointSizeElem.firstChild();
QDomText newPointSizeText = mDom.createTextNode( QString::number( static_cast< int >( pointSize ) ) );
currentPointSizeElem.replaceChild( newPointSizeText, pointSizeTextNode );
}
#endif
}
}
示例8: arg
// Convenience to create a Dom Widget from widget box xml code.
DomUI *QDesignerWidgetBox::xmlToUi(const QString &name, const QString &xml, bool insertFakeTopLevel, QString *errorMessage)
{
QDomDocument doc;
int errorLine, errorColumn;
if (!doc.setContent(xml, errorMessage, &errorLine, &errorColumn)) {
*errorMessage = QObject::tr("A parse error occurred at line %1, column %2 of the XML code specified for the widget %3: %4\n%5").
arg(errorLine).arg(errorColumn).arg(name).arg(*errorMessage).arg(xml);
return 0;
}
if (!doc.hasChildNodes()) {
*errorMessage = QObject::tr("The XML code specified for the widget %1 does not contain any widget elements.\n%2").arg(name).arg(xml);
return 0;
}
QDomElement rootElement = doc.firstChildElement();
const QString rootNode = rootElement.nodeName();
const QString widgetTag = QLatin1String("widget");
if (rootNode == widgetTag) { // 4.3 legacy ,wrap into DomUI
DomUI *rc = new DomUI;
DomWidget *widget = new DomWidget;
widget->read(rootElement);
if (insertFakeTopLevel) {
DomWidget *fakeTopLevel = new DomWidget;
QList<DomWidget *> children;
children.push_back(widget);
fakeTopLevel->setElementWidget(children);
rc->setElementWidget(fakeTopLevel);
} else {
rc->setElementWidget(widget);
}
return rc;
}
if (rootNode == QLatin1String("ui")) { // 4.4
QDomElement widgetChild = rootElement.firstChildElement(widgetTag);
if (widgetChild.isNull()) {
*errorMessage = QObject::tr("The XML code specified for the widget %1 does not contain valid widget element\n%2").arg(name).arg(xml);
return 0;
}
if (insertFakeTopLevel) {
QDomElement fakeTopLevel = doc.createElement(widgetTag);
rootElement.replaceChild(fakeTopLevel, widgetChild);
fakeTopLevel.appendChild(widgetChild);
}
DomUI *rc = new DomUI;
rc->read(rootElement);
return rc;
}
*errorMessage = QObject::tr("The XML code specified for the widget %1 contains an invalid root element %2.\n%3").arg(name).arg(rootNode).arg(xml);
return 0;
}
示例9: SetXmlNodeContent
bool XmlHelper::SetXmlNodeContent(const QString &tag_name, const QString &text)
{
if (!LoadXmlFile())
{
return false;
}
QDomElement root = doc_.documentElement();
QDomNodeList node_list = root.elementsByTagName(tag_name);
if (node_list.count() > 0)
{
QDomElement elems = node_list.at(0).toElement();
QDomNode old_node = elems.firstChild();
if (elems.firstChild().isText())
{
elems.firstChild().setNodeValue(text);
QDomNode new_node = elems.firstChild();
elems.replaceChild(new_node, old_node);
}
else
{
elems.firstChild().setNodeValue(text);
QDomText text_node;
text_node.setNodeValue(text);
QDomNode new_node = elems.firstChild();
new_node.appendChild(text_node);
elems.replaceChild(new_node, old_node);
}
QFile file(file_name_);
if (!file.open(QIODevice::WriteOnly))
{
return false;
}
QTextStream out(&file);
doc_.save(out, 4);
file.close();
return true;
}
return false;
}
示例10: saveChanges
bool plotsDialog::saveChanges()
{
#ifdef Q_OS_WIN32
QFile ofile(globalpara.caseName),file("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
QDir dir = qApp->applicationDirPath();
/*dir.cdUp();*/
/*dir.cdUp();*/
/*dir.cdUp();*/
QString bundleDir(dir.absolutePath());
QFile ofile(globalpara.caseName),file(bundleDir+"/plotTemp.xml");
#endif
QDomDocument odoc,doc;
QDomElement oroot;
QTextStream stream;
stream.setDevice(&ofile);
if(!ofile.open(QIODevice::ReadWrite|QIODevice::Text))
{
globalpara.reportError("Fail to open case file to update plot data.",this);
return false;
}
else if(!odoc.setContent(&ofile))
{
globalpara.reportError("Fail to load xml document from case file to update plot data.",this);
return false;
}
if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
{
globalpara.reportError("Fail to open plot temp file to update plot data.",this);
return false;
}
else if(!doc.setContent(&file))
{
globalpara.reportError("Fail to load xml document from plot temp file to update plot data..",this);
return false;
}
else
{
QDomElement plotData = doc.elementsByTagName("plotData").at(0).toElement();
QDomNode copiedPlot = plotData.cloneNode(true);
oroot = odoc.elementsByTagName("root").at(0).toElement();
oroot.replaceChild(copiedPlot,odoc.elementsByTagName("plotData").at(0));
ofile.resize(0);
odoc.save(stream,4);
file.close();
ofile.close();
stream.flush();
return true;
}
}
示例11: f
void
XmlHeaderFunctions::replaceInHeader(QString pvlFilename,
QString attname, QString value)
{
QDomDocument doc;
QFile f(pvlFilename);
if (f.open(QIODevice::ReadOnly))
{
doc.setContent(&f);
f.close();
}
int replace = -1;
QDomElement topElement = doc.documentElement();
QDomNodeList dlist = topElement.childNodes();
for(int i=0; i<dlist.count(); i++)
{
if (dlist.at(i).nodeName() == attname)
{
replace = i;
break;
}
}
if (replace > -1)
{
QDomElement de = doc.createElement(attname);
QDomText tn = doc.createTextNode(value);
de.appendChild(tn);
topElement.replaceChild(de, dlist.at(replace));
}
else
{
QDomElement de = doc.createElement(attname);
QDomText tn = doc.createTextNode(value);
de.appendChild(tn);
topElement.appendChild(de);
}
QFile fout(pvlFilename);
if (fout.open(QIODevice::WriteOnly))
{
QTextStream out(&fout);
doc.save(out, 2);
fout.close();
}
else
{
QMessageBox::information(0, "", QString("Cannot write to "+pvlFilename));
}
}
示例12: setInputParametersXml
void OpenModelica::setInputParametersXml(QDomDocument &doc,MOParameters *parameters)
{
QDomElement xfmi = doc.firstChildElement("fmiModelDescription");
QDomElement oldxfmi = xfmi;
QDomElement xExp = xfmi.firstChildElement("DefaultExperiment");
QDomElement oldxExp = xExp;
double starttime = parameters->value(OpenModelicaParameters::str(OpenModelicaParameters::STARTTIME),0).toDouble();
double stoptime = parameters->value(OpenModelicaParameters::str(OpenModelicaParameters::STOPTIME),1).toDouble();
int nbIntervals = parameters->value(OpenModelicaParameters::str(OpenModelicaParameters::NBINTERVALS),2).toInt();
double stepSize = (stoptime-starttime)/nbIntervals;
MOParameter * curParam;
MOParameterListed* curParamListed;
for(int i=0;i<parameters->size();i++)
{
curParam = parameters->at(i);
if(!curParam->name().contains(" ")) // remove old parameters, temporary
{
if(curParam->name()==OpenModelicaParameters::str(OpenModelicaParameters::SOLVER))
{
curParamListed = dynamic_cast<MOParameterListed*>(curParam);
xExp.setAttribute(curParamListed->name(),curParamListed->strValue());
}
else if(curParam->name()==OpenModelicaParameters::str(OpenModelicaParameters::OUTPUT))
{
curParamListed = dynamic_cast<MOParameterListed*>(curParam);
xExp.setAttribute(curParamListed->name(),curParamListed->strValue());
}
else if (curParam->name()==OpenModelicaParameters::str(OpenModelicaParameters::NBINTERVALS))
{
xExp.setAttribute("stepSize",QString::number(stepSize));
}
else
{
xExp.setAttribute(curParam->name(),curParam->value().toString());
}
}
}
// update xfmi with new vars
xfmi.replaceChild(xExp,oldxExp);
doc.replaceChild(xfmi,oldxfmi);
}
示例13: addependTextById
void QQMlDom::addependTextById(QDomDocument nDocument, QString element, QString text)
{
QDomElement root = nDocument.documentElement();
QDomNodeList nList = root.elementsByTagName(element);
QDomNode nNode = nList.at(0);
QDomElement nodeTag = nNode.toElement();
// create a new node with a QDomText child
QDomElement newNodeTag = nDocument.createElement(QString(element));
QDomText newNodeText = nDocument.createTextNode(QString(text));
newNodeTag.appendChild(newNodeText);
// replace existing node with new node
root.replaceChild(newNodeTag, nodeTag);
}
示例14: updateDomElement
void XbelTree::updateDomElement(QTreeWidgetItem *item, int column)
{
QDomElement element = domElementForItem.value(item);
if (!element.isNull()) {
if (column == 0) {
QDomElement oldTitleElement = element.firstChildElement("title");
QDomElement newTitleElement = domDocument.createElement("title");
QDomText newTitleText = domDocument.createTextNode(item->text(0));
newTitleElement.appendChild(newTitleText);
element.replaceChild(newTitleElement, oldTitleElement);
} else {
if (element.tagName() == "bookmark")
element.setAttribute("href", item->text(1));
}
}
}
示例15: writeCurrentInAlbum
void ParserAlbum::writeCurrentInAlbum(int _current)
{
m_pFile->close();
if(!m_pFile->open(QIODevice::WriteOnly))
{
return;
}
QDomElement element = m_pDoc->documentElement();
QDomElement node = element.firstChild().toElement();
while(node.tagName() != "current")
{
node = node.nextSibling().toElement();
}
QDomElement CurrentElement = createElement("current",QString::number(_current));
element.replaceChild(CurrentElement,node);
if(m_pFile->isOpen())
{
QTextStream(m_pFile) << m_pDoc->toString();
m_pFile->close();
}
}