本文整理汇总了C++中QDomElement::insertBefore方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomElement::insertBefore方法的具体用法?C++ QDomElement::insertBefore怎么用?C++ QDomElement::insertBefore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomElement
的用法示例。
在下文中一共展示了QDomElement::insertBefore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addElement
SimXmlElement SimXmlDoc::addElement(const std::string& elementName)
{
QSharedPointer<QDomElement> elementImpl(new QDomElement(impl()->createElement(QString::fromStdString(elementName))));
elementImpl->setAttribute("RefId", QUuid::createUuid().toString());
SimXmlElement result(elementImpl, *this);
QDomElement documentElement = impl()->documentElement();
// insert in alphabetical order
QDomNode n = documentElement.firstChild();
while (!n.isNull()) {
if (n.isElement()) {
QDomElement e = n.toElement();
// if element name is greater than new one
if (e.tagName().toStdString() > elementName){
documentElement.insertBefore(*elementImpl, n);
return result;
}
}
n = n.nextSibling();
}
documentElement.appendChild(*elementImpl);
return result;
}
示例2: stream
StyleItem::StyleItem( QDomElement el, QString colors[], QDomElement defs )
{
QDomElement name = el.firstChildElement("name");
this->name = name.text();
QDomElement svg = el.firstChildElement("svg");
if ( svg.isNull() ) {
this->renderer = NULL;
} else {
if ( !defs.isNull() ) svg.insertBefore( defs, QDomNode() );
QDomDocument doc;
doc.setContent( css );
svg.insertBefore( doc, QDomNode() );
QTextStream stream(&(this->svg));
svg.save(stream, 0);
this->renderer = new QSvgRenderer( this->makeSvg( colors, STYLE_KEY_COLOR ).toAscii() );
}
}
示例3: createAnnotationElement
/*!
* \brief TLMEditor::createAnnotationElement
* Creates an Annotation tag for SubModel.
* \param subModel
* \param visible
* \param origin
* \param extent
* \param rotation
*/
void TLMEditor::createAnnotationElement(QDomElement subModel, QString visible, QString origin, QString extent, QString rotation)
{
QDomElement annotation = mXmlDocument.createElement("Annotation");
annotation.setAttribute("Visible", visible);
annotation.setAttribute("Origin", origin);
annotation.setAttribute("Extent", extent);
annotation.setAttribute("Rotation", rotation);
subModel.insertBefore(annotation, QDomNode());
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
}
示例4: load
bool XdgMenuReader::load(const QString& fileName, const QString& baseDir)
{
if (fileName.isEmpty())
{
mErrorStr = tr("Menu file not defined.");
return false;
}
QFileInfo fileInfo(QDir(baseDir), fileName);
mFileName = fileInfo.canonicalFilePath();
mDirName = fileInfo.canonicalPath();
if (mBranchFiles.contains(mFileName))
return false; // Recursive loop detected
mBranchFiles << mFileName;
QFile file(mFileName);
if (!file.open(QFile::ReadOnly | QFile::Text))
{
mErrorStr = tr("%1 not loading: %2").arg(fileName).arg(file.errorString());
return false;
}
//qDebug() << "Load file:" << mFileName;
mMenu->addWatchPath(mFileName);
QString errorStr;
int errorLine;
int errorColumn;
if (!mXml.setContent(&file, true, &errorStr, &errorLine, &errorColumn))
{
mErrorStr = tr("Parse error at line %1, column %2:\n%3")
.arg(errorLine)
.arg(errorColumn)
.arg(errorStr);
return false;
}
QDomElement root = mXml.documentElement();
QDomElement debugElement = mXml.createElement("FileInfo");
debugElement.setAttribute("file", mFileName);
if (mParentReader)
debugElement.setAttribute("parent", mParentReader->fileName());
QDomNode null;
root.insertBefore(debugElement, null);
processMergeTags(root);
return true;
}
示例5: setEleNodeText
void XmlFloTransBase::setEleNodeText(QDomElement &elenode, const QString &text)
{
if(elenode.firstChild().isNull() || !elenode.firstChild().isText())
{
QDomText textnode = domDocument.createTextNode(text);
elenode.insertBefore(textnode,elenode.firstChild());
}
else
{
elenode.firstChild().setNodeValue(text);
}
}
示例6: on_actionPage_backward_activated
void MainWindow::on_actionPage_backward_activated()
{
QDomElement root = document->documentElement();
QDomElement picture = album.toElement();
root.insertBefore(picture, picture.previousSiblingElement("photo"));
if(album.previousSibling().isNull())
{
ui->actionMove_backward->setEnabled(false);
ui->actionPage_backward->setEnabled(false);
}
if(!album.nextSibling().isNull())
{
ui->actionMove_forward->setEnabled(true);
ui->actionPage_forward->setEnabled(true);
}
ui->statusBar->showMessage("Moved photo back one in album");
}
示例7: resetModuleName
void writeJob::resetModuleName(const QString name)
{
qDebug()<<"writeJob::resetModuleName";
QDomElement root = doc.documentElement();
QDomElement modEle = root.firstChildElement("Module");
while (!modEle.isNull())
{
if(modEle.attribute("name")==name && modEle.attribute("id")==moduleID)
{
/// 采用的替换法,多替换几次???难道仅仅是这个函数多执行几次???
QDomElement prevModEle=modEle.previousSiblingElement("Module");
root.insertBefore(modEle,prevModEle);
break;
}
modEle = modEle.nextSiblingElement("Module");
}
if(!write())
qDebug()<<"writeJob::reset job failed";
}
示例8: prependNode
//节点最前插入
bool MainWindow::prependNode(const QString &strFilePath, const QString &strNodeName, const QMap<QString,QString> &nodeMap)
{
QDomDocument doc; //整个文档
QFile file(strFilePath); //xml文件
if (!file.open(QFile::ReadOnly | QFile::Text))
{
return false ;
}
if(!doc.setContent(&file,true))
{
file.close();
return false;
}
file.close(); //读结束
QDomElement root = doc.documentElement(); //根节点
QDomElement node = doc.createElement(strNodeName); //子节点
if (root.hasChildNodes()) //具有子节点
{
QDomElement firstNode = root.firstChild().toElement(); //第一个子节点
root.insertBefore(node,firstNode); //插在前面
}
else //不具有子节点
{
root.appendChild(node); //直接插入
}
QStringList tagNameList = nodeMap.keys(); //所有的tagName
foreach(QString strTagName, tagNameList)
{
QString strTextNode = nodeMap.value(strTagName);
QDomElement nodeElement = doc.createElement(strTagName);
node.appendChild(nodeElement); //子节点的各节点(属性)
QDomText textNode = doc.createTextNode(strTextNode);
nodeElement.appendChild(textNode); //属性的内容
}
示例9: prependChilds
void XdgMenuPrivate::prependChilds(QDomElement& srcElement, QDomElement& destElement)
{
MutableDomElementIterator it(srcElement);
it.toBack();
while(it.hasPrevious())
{
QDomElement n = it.previous();
destElement.insertBefore(n, destElement.firstChild());
}
if (srcElement.attributes().contains("deleted") &&
!destElement.attributes().contains("deleted")
)
destElement.setAttribute("deleted", srcElement.attribute("deleted"));
if (srcElement.attributes().contains("onlyUnallocated") &&
!destElement.attributes().contains("onlyUnallocated")
)
destElement.setAttribute("onlyUnallocated", srcElement.attribute("onlyUnallocated"));
}
示例10: Section
void
ConfigDocumentXML::onAddSection(int _n)
{
QDomElement config = document_.documentElement();
QDomElement e = document_.createElement(Section::XML_TAG);
e.setAttribute(Section::XML_ATTRIBUTE_KEY, menuAddSection_->text(_n));
QDomNode n = config.firstChild();
QDomNode newChild;
if (config.firstChild().isNull())
newChild = config.appendChild(e);
else
newChild = config.insertBefore(e, n);
MIRO_ASSERT(!newChild.isNull());
new Section(newChild,
listViewItem(), NULL,
this, menuAddSection_->text(_n));
setModified();
}
示例11: Section
void
ConfigDocumentXML::onAddSection(int _n)
{
QDomElement config = document_.documentElement();
QDomElement e = document_.createElement(Section::XML_TAG);
e.setAttribute(Section::XML_ATTRIBUTE_KEY, menuAddSection_->text(_n));
QDomNode n = config.firstChild();
QDomNode newChild;
if (config.firstChild().isNull())
newChild = config.appendChild(e);
else
newChild = config.insertBefore(e, n);
assert(!newChild.isNull());
// The constructor registers the constructed element
new Section(newChild,
treeWidgetItem(), // QTreeWidget for the ConfigDocumentXML
NULL,
this, // parent QObject
menuAddSection_->text(_n));
setModified();
}
示例12: toSld
void QgsSingleBandGrayRenderer::toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const
{
QgsStringMap newProps = props;
// create base structure
QgsRasterRenderer::toSld( doc, element, props );
// look for RasterSymbolizer tag
QDomNodeList elements = element.elementsByTagName( QStringLiteral( "sld:RasterSymbolizer" ) );
if ( elements.size() == 0 )
return;
// there SHOULD be only one
QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();
// add Channel Selection tags
// Need to insert channelSelection in the correct sequence as in SLD standard e.g.
// after opacity or geometry or as first element after sld:RasterSymbolizer
QDomElement channelSelectionElem = doc.createElement( QStringLiteral( "sld:ChannelSelection" ) );
elements = rasterSymbolizerElem.elementsByTagName( QStringLiteral( "sld:Opacity" ) );
if ( elements.size() != 0 )
{
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at( 0 ) );
}
else
{
elements = rasterSymbolizerElem.elementsByTagName( QStringLiteral( "sld:Geometry" ) );
if ( elements.size() != 0 )
{
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at( 0 ) );
}
else
{
rasterSymbolizerElem.insertBefore( channelSelectionElem, rasterSymbolizerElem.firstChild() );
}
}
// for gray band
QDomElement channelElem = doc.createElement( QStringLiteral( "sld:GrayChannel" ) );
channelSelectionElem.appendChild( channelElem );
// set band
QDomElement sourceChannelNameElem = doc.createElement( QStringLiteral( "sld:SourceChannelName" ) );
sourceChannelNameElem.appendChild( doc.createTextNode( QString::number( grayBand() ) ) );
channelElem.appendChild( sourceChannelNameElem );
// set ContrastEnhancement
if ( contrastEnhancement() )
{
QDomElement contrastEnhancementElem = doc.createElement( QStringLiteral( "sld:ContrastEnhancement" ) );
contrastEnhancement()->toSld( doc, contrastEnhancementElem );
// do changes to minValue/maxValues depending on stretching algorithm. This is necessary because
// geoserver do a first stretch on min/max, then apply colo map rules. In some combination is necessary
// to use real min/max values and in othere the actual edited min/max values
switch ( contrastEnhancement()->contrastEnhancementAlgorithm() )
{
case QgsContrastEnhancement::StretchAndClipToMinimumMaximum:
case QgsContrastEnhancement::ClipToMinimumMaximum:
{
// with this renderer export have to be check against real min/max values of the raster
QgsRasterBandStats myRasterBandStats = mInput->bandStatistics( grayBand(), QgsRasterBandStats::Min | QgsRasterBandStats::Max );
// if minimum range differ from the real minimum => set is in exported SLD vendor option
if ( !qgsDoubleNear( contrastEnhancement()->minimumValue(), myRasterBandStats.minimumValue ) )
{
// look for VendorOption tag to look for that with minValue attribute
QDomNodeList elements = contrastEnhancementElem.elementsByTagName( QStringLiteral( "sld:VendorOption" ) );
for ( int i = 0; i < elements.size(); ++i )
{
QDomElement vendorOption = elements.at( i ).toElement();
if ( vendorOption.attribute( QStringLiteral( "name" ) ) != QStringLiteral( "minValue" ) )
continue;
// remove old value and add the new one
vendorOption.removeChild( vendorOption.firstChild() );
vendorOption.appendChild( doc.createTextNode( QString::number( myRasterBandStats.minimumValue ) ) );
}
}
break;
}
case QgsContrastEnhancement::UserDefinedEnhancement:
break;
case QgsContrastEnhancement::NoEnhancement:
break;
case QgsContrastEnhancement::StretchToMinimumMaximum:
break;
}
channelElem.appendChild( contrastEnhancementElem );
}
// for each color set a ColorMapEntry tag nested into "sld:ColorMap" tag
// e.g. <ColorMapEntry color="#EEBE2F" quantity="-300" label="label" opacity="0"/>
QList< QPair< QString, QColor > > classes;
legendSymbologyItems( classes );
// add ColorMap tag
QDomElement colorMapElem = doc.createElement( QStringLiteral( "sld:ColorMap" ) );
rasterSymbolizerElem.appendChild( colorMapElem );
//.........这里部分代码省略.........
示例13: addschedulexmldata
void schedulexmldata::addschedulexmldata(QString tmpscheduledate, QString tmpid, QString tmptheme, QString tmpoccurtime, QString tmpoccuraddress,
/*QString tmpremindtime, QString tmpremindway, QString tmpremindsequence,*/ QString tmpeventrepeat, QString tmpdetail)
{
QFile file("/home/user/.scheduledata.xml");
if(!file.open(QIODevice::ReadOnly)) return;
QDomDocument doc;
if(!doc.setContent(&file)){
file.close();
return;
}
file.close();
QDomText text;
QDomElement root = doc.documentElement();
QDomElement scheduledate = doc.createElement(QString("scheduledate"));
QDomAttr scheduledateattr = doc.createAttribute(QString("scheduledateattr"));
scheduledate.setAttributeNode(scheduledateattr);
QDomElement schedule = doc.createElement(QString("schedule"));
QDomNode n = root.firstChild();
if(n.toElement().attribute(QString("scheduledateattr")) == "00000000"){
root.removeChild(n);
root.appendChild(scheduledate);
scheduledateattr.setValue(tmpscheduledate);
scheduledate.appendChild(schedule);
}else{
bool scheduledateisexistence = false;
while(!n.isNull()){
if((n.previousSibling().toElement().attribute(QString("scheduledateattr")) < tmpscheduledate) &&( tmpscheduledate < n.toElement().attribute(QString("scheduledateattr")))){
root.insertBefore(scheduledate, n);
scheduledateattr.setValue(tmpscheduledate);
scheduledate.appendChild(schedule);
scheduledateisexistence = true;
}else if(tmpscheduledate == n.toElement().attribute(QString("scheduledateattr"))){
n.toElement().appendChild(schedule);
scheduledateisexistence = true;
}
n = n.nextSibling();
}
if(!scheduledateisexistence){
root.appendChild(scheduledate);
scheduledateattr.setValue(tmpscheduledate);
scheduledate.appendChild(schedule);
}
}
if(tmpid == "-10"){
QDomNode nn = root.firstChild();
while(!nn.isNull()){
if(tmpscheduledate == nn.toElement().attribute(QString("scheduledateattr"))){
QDomNodeList schedulelist = nn.toElement().elementsByTagName(QString("schedule"));
tmpid.setNum(schedulelist.count() - 1);
qDebug() << tmpid;
}
nn = nn.nextSibling();
}
}
QDomAttr scheduleid = doc.createAttribute(QString("id"));
scheduleid.setValue(QString(tmpid));
schedule.setAttributeNode(scheduleid);
QDomElement theme = doc.createElement(QString("theme"));
text = doc.createTextNode(QString(tmptheme));
theme.appendChild(text);
schedule.appendChild(theme);
QDomElement occurtime = doc.createElement(QString("occurtime"));
text = doc.createTextNode(QString(tmpoccurtime));
occurtime.appendChild(text);
schedule.appendChild(occurtime);
QDomElement occuraddress = doc.createElement(QString("occuraddress"));
text = doc.createTextNode(QString(tmpoccuraddress));
occuraddress.appendChild(text);
schedule.appendChild(occuraddress);
// QDomElement remindtime = doc.createElement(QString("remindtime"));
// text = doc.createTextNode(QString(tmpremindtime));
// remindtime.appendChild(text);
// schedule.appendChild(remindtime);
// QDomElement remindway = doc.createElement(QString("remindway"));
// text = doc.createTextNode(QString(tmpremindway));
// remindway.appendChild(text);
// schedule.appendChild(remindway);
// QDomElement remindsequence = doc.createElement(QString("remindsequence"));
// text = doc.createTextNode(QString(tmpremindsequence));
// remindsequence.appendChild(text);
// schedule.appendChild(remindsequence);
QDomElement eventrepeat = doc.createElement(QString("eventrepeat"));
text = doc.createTextNode(QString(tmpeventrepeat));
eventrepeat.appendChild(text);
schedule.appendChild(eventrepeat);
QDomElement detail = doc.createElement(QString("detail"));
text = doc.createTextNode(QString(tmpdetail));
detail.appendChild(text);
schedule.appendChild(detail);
if( !file.open(QIODevice::WriteOnly | QIODevice::Truncate)) return;
QTextStream out(&file);
doc.save(out, 4);
file.close();
//.........这里部分代码省略.........
示例14: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
if (a.arguments().count() <= 1) {
qWarning() << "Argument expected: url to open";
return 1;
}
new KHTMLGlobal;
KXmlGuiWindow *toplevel = new KXmlGuiWindow();
KHTMLPart *doc = new KHTMLPart(toplevel, toplevel, KHTMLPart::BrowserViewGUI);
Dummy *dummy = new Dummy(doc);
QObject::connect(doc->browserExtension(), SIGNAL(openUrlRequest(QUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)),
dummy, SLOT(slotOpenURL(QUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)));
QObject::connect(doc, SIGNAL(completed()), dummy, SLOT(handleDone()));
QUrl url = QUrl::fromUserInput(a.arguments().at(1)); // TODO support for relative paths
if (url.path().right(4).toLower() == ".xml") {
KParts::OpenUrlArguments args(doc->arguments());
args.setMimeType("text/xml");
doc->setArguments(args);
}
doc->openUrl(url);
toplevel->setCentralWidget(doc->widget());
toplevel->resize(800, 600);
QDomDocument d = doc->domDocument();
QDomElement viewMenu = d.documentElement().firstChild().childNodes().item(2).toElement();
QDomElement e = d.createElement("action");
e.setAttribute("name", "debugRenderTree");
viewMenu.appendChild(e);
e = d.createElement("action");
e.setAttribute("name", "debugDOMTree");
viewMenu.appendChild(e);
e = d.createElement("action");
e.setAttribute("name", "debugDoBenchmark");
viewMenu.appendChild(e);
QDomElement toolBar = d.documentElement().firstChild().nextSibling().toElement();
e = d.createElement("action");
e.setAttribute("name", "editable");
toolBar.insertBefore(e, toolBar.firstChild());
e = d.createElement("action");
e.setAttribute("name", "navigable");
toolBar.insertBefore(e, toolBar.firstChild());
e = d.createElement("action");
e.setAttribute("name", "reload");
toolBar.insertBefore(e, toolBar.firstChild());
e = d.createElement("action");
e.setAttribute("name", "print");
toolBar.insertBefore(e, toolBar.firstChild());
QAction *action = new QAction(QIcon::fromTheme("view-refresh"), "Reload", doc);
doc->actionCollection()->addAction("reload", action);
QObject::connect(action, SIGNAL(triggered(bool)), dummy, SLOT(reload()));
doc->actionCollection()->setDefaultShortcut(action, Qt::Key_F5);
QAction *bench = new QAction(QIcon(), "Benchmark...", doc);
doc->actionCollection()->addAction("debugDoBenchmark", bench);
QObject::connect(bench, SIGNAL(triggered(bool)), dummy, SLOT(doBenchmark()));
QAction *kprint = new QAction(QIcon::fromTheme("document-print"), "Print", doc);
doc->actionCollection()->addAction("print", kprint);
QObject::connect(kprint, SIGNAL(triggered(bool)), doc->browserExtension(), SLOT(print()));
kprint->setEnabled(true);
KToggleAction *ta = new KToggleAction(QIcon::fromTheme("edit-rename"), "Navigable", doc);
doc->actionCollection()->addAction("navigable", ta);
ta->setShortcuts(QList<QKeySequence>());
ta->setChecked(doc->isCaretMode());
QWidget::connect(ta, SIGNAL(toggled(bool)), dummy, SLOT(toggleNavigable(bool)));
ta = new KToggleAction(QIcon::fromTheme("document-properties"), "Editable", doc);
doc->actionCollection()->addAction("editable", ta);
ta->setShortcuts(QList<QKeySequence>());
ta->setChecked(doc->isEditable());
QWidget::connect(ta, SIGNAL(toggled(bool)), dummy, SLOT(toggleEditable(bool)));
toplevel->guiFactory()->addClient(doc);
doc->setJScriptEnabled(true);
doc->setJavaEnabled(true);
doc->setPluginsEnabled(true);
doc->setURLCursor(QCursor(Qt::PointingHandCursor));
a.setActiveWindow(doc->widget());
QWidget::connect(doc, SIGNAL(setWindowCaption(QString)),
doc->widget()->topLevelWidget(), SLOT(setCaption(QString)));
doc->widget()->show();
toplevel->show();
doc->view()->viewport()->show();
doc->view()->widget()->show();
int ret = a.exec();
return ret;
}
示例15: save_vec_to_file
void save_vec_to_file(const QVector<word_t*>& vec, const QString& filename)
{
if (vec.isEmpty())
{
return;
}
QDomDocument doc;
QFile file(filename);
//Clear the file and input an empty xml structure
if (!file.open(QIODevice::WriteOnly))
{
return;
}
QTextStream s(&file);
s << "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << "\n";
s << "<WordList/>" << "\n";
file.close();
if (!file.open(QIODevice::ReadOnly))
{
return;
}
QString errorString;
int errorLine;
int errorCol;
if (!doc.setContent(&file, true, &errorString, &errorLine, &errorCol))
{
}
file.close();
QDomElement root = doc.documentElement();
if (root.tagName() != "WordList")
{
return;
}
for (int i = 0; i < vec.size(); ++i)
{
QDomElement newnode = doc.createElement("Word");
newnode.setAttribute("name", vec[i]->name);
newnode.setAttribute("time", vec[i]->time);
newnode.setAttribute("marks", vec[i]->marks);
QDomText defText = doc.createTextNode(vec[i]->def);
newnode.appendChild(defText);
if (root.hasChildNodes())
{
QDomNode child = root.firstChild();
bool bInserted = false;
while (!child.isNull())
{
QDomElement e = child.toElement();
if (e.attribute("name") == vec[i]->name)
{
//the word has been logged, replace it.
//TODO : may need to sum up the marks field.
root.replaceChild(newnode, child);
bInserted = true;
break;
}
else if (e.attribute("name") > vec[i]->name)
{
root.insertBefore(newnode, child);
bInserted = true;
break;
}
child = child.nextSibling();
}
if (!bInserted)
{
root.appendChild(newnode);
bInserted = true;
}
}
else
{
root.appendChild(newnode);
}
}
QString xml = doc.toString();
if (!file.open(QIODevice::WriteOnly))
{
return;
}
QTextStream ts(&file);
ts << xml;
file.flush();
file.close();
}