void Properties::save(QDomDocument &doc, QDomElement &parent) { QDomElement propertiesElem = doc.createElement(XML_TAGNAME.c_str()); parent.appendChild(propertiesElem); QDomAttr propertieAttr; for (std::map<std::string, Property*>::iterator it = _properties.begin(); it != _properties.end(); ++it) { // to save string lists, we save each value the format property_name[index] const std::vector<std::string> &lst = it->second->valueStrList(); if(lst.size()>1) { for(unsigned int i=0;i<lst.size(); i++) { QString index; index.sprintf("%i",i); propertieAttr = doc.createAttribute(QString(it->second->name().c_str()).replace(' ', WHITESPACE_REPLACEMENT)+index); propertieAttr.setValue(lst[i].c_str()); propertiesElem.setAttributeNode(propertieAttr); } } else { propertieAttr = doc.createAttribute(QString(it->second->name().c_str()).replace(' ', WHITESPACE_REPLACEMENT)); propertieAttr.setValue(it->second->valueStr().c_str()); propertiesElem.setAttributeNode(propertieAttr); } } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QFile file("test.xml"); if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate )) return; else qDebug()<<"ths file is existing!"; QDomDocument doc; QDomText text; QDomProcessingInstruction instruction; instruction=doc.createProcessingInstruction("xml", "version = \'1.0\'"); doc.appendChild(instruction); QDomElement school=doc.createElement("school"); doc.appendChild(school); QDomElement schoolGuangMing=doc.createElement("schoolGuangMing"); school.appendChild(schoolGuangMing); QDomElement grate1=doc.createElement("grate1"); text=doc.createTextNode("一年级"); grate1.appendChild(text); schoolGuangMing.appendChild(grate1); QDomElement student= doc.createElement("student1"); QDomAttr name=doc.createAttribute("name"); name.setValue("李明"); QDomAttr number=doc.createAttribute("number"); number.setValue("0x12313"); student.setAttributeNode(name); student.setAttributeNode(number); schoolGuangMing.appendChild(student); QDomElement grate2=doc.createElement("grate2"); text=doc.createTextNode("二年级"); grate2.appendChild(text); schoolGuangMing.appendChild(grate2); QDomElement grate3=doc.createElement("grate3"); text=doc.createTextNode("三年级"); grate3.appendChild(text); schoolGuangMing.appendChild(grate3); QDomElement grate4=doc.createElement("grate4"); text=doc.createTextNode("四年级"); grate4.appendChild(text); schoolGuangMing.appendChild(grate4); QTextStream out( &file ); doc.save( out, 7 ); file.close(); }
QDomAttr QDomDocumentProto::createAttribute(const QString& name) { QDomDocument *item = qscriptvalue_cast<QDomDocument*>(thisObject()); if (item) return item->createAttribute(name); return QDomAttr(); }
void Gear_ListBox::internalSave(QDomDocument &doc, QDomElement &gearElem) { std::ostringstream strValue; strValue << getValue(); QDomAttr attrListBoxPos = doc.createAttribute("ListBoxPos"); attrListBoxPos.setValue(strValue.str().c_str()); gearElem.setAttributeNode(attrListBoxPos); }
void Schema::Connection::save(QDomDocument &doc, QDomElement &parent) { QDomElement connectionElem = doc.createElement("Connection"); parent.appendChild(connectionElem); QDomAttr gearA = doc.createAttribute("GearA"); gearA.setValue(_gearA.c_str()); connectionElem.setAttributeNode(gearA); QDomAttr input = doc.createAttribute("Input"); input.setValue(_input.c_str()); connectionElem.setAttributeNode(input); QDomAttr gearB = doc.createAttribute("GearB"); gearB.setValue(_gearB.c_str()); connectionElem.setAttributeNode(gearB); QDomAttr output = doc.createAttribute("Output"); output.setValue(_output.c_str()); connectionElem.setAttributeNode(output); }
void MainWindow::on_btn_select_clicked() { ui->listWidget->clear(); ui->listWidget->addItem(tr("无法添加")); QFile file("my.xml"); if(!file.open(QIODevice::ReadOnly())) { return; } QDomDocument doc; if(!doc.setContent(&file)) { file.close(); return ; } file.close(); QDomElement root = doc.documentElement(); QDomElement book = doc.documentElement(tr("图书")); QDomAttr id = doc.createAttribute(tr("编号")); QDomElement title = doc.documentElement(tr("书名")); QDomElement author = doc.documentElement(tr("作者")); QDomText text; QString num = root.lastChild().toElement().attribute(tr("编号")); int count = num.toInt() +1; id.setValue(QString::number(count)); book.setAttributeNode(id); text = doc.createTextNode(ui->lineEdit_name->text()); title.appendChild(text); text = doc.createTextNode(ui->lineEdit_author->text()); author.appendChild(text); book.appendChild(title); book.appendChild(author); root.appendChild(book); if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { return; } QTextStream out(&file); doc.save(out, 4); file.close(); ui->listWidget->clear(); ui->listWidget->addItem(tr("添加成功")); }
QDomElement ExerciseWindow::getBlocks(const FCWidget *fc, QDomDocument &doc, QString Name) { int n = fc->layout()->count(); int i = 0; QDomElement domElement = doc.createElement(Name); while (i < n) { QDomElement block; QDomAttr attr = doc.createAttribute("text"); QString tag = fc->layout()->itemAt(i)->widget()->metaObject()->className(); if (tag != "FCLine" && tag != "FCLeftLine" && tag != "RightLine") { block = doc.createElement(tag); FCWidget *widget = (FCWidget*)fc->layout()->itemAt(i)->widget(); attr.setValue(widget->getText()); block.setAttributeNode(attr); domElement.appendChild(block); if (tag == "FCDivarWidget") { FCDivarWidget *divar = (FCDivarWidget*)widget; QDomElement left = getBlocks(divar->getRightLine(), doc, "Left"); QDomElement right = getBlocks(divar->getLeftLine(), doc, "Right"); block.appendChild(left); block.appendChild(right); } else if (tag == "FCPrefixCycleWidget") { FCPrefixCycleWidget *cycle = (FCPrefixCycleWidget*)widget; QDomElement body = getBlocks(cycle->getCycleBody(), doc, "Body"); block.appendChild(body); } else if (tag == "FCPostfixCycleWidget") { FCPostfixCycleWidget *cycle = (FCPostfixCycleWidget*)widget; QDomElement body = getBlocks(cycle->getCycleBody(), doc, "Body"); block.appendChild(body); } else if (tag == "FCParameterCycleWidget") { FCParameterCycleWidget *cycle = (FCParameterCycleWidget*)widget; QDomElement body = getBlocks(cycle->getCycleBody(), doc, "Body"); block.appendChild(body); } } i++; } return domElement; }
QDomElement makeElement( QDomDocument& domDoc, const QString& strName, const QString& strAttr = QString::null, const QString& strText = QString::null ) { QDomElement domElement = domDoc.createElement(strName); if (!strAttr.isEmpty()) { QDomAttr domAttr = domDoc.createAttribute("number"); domAttr.setValue(strAttr); domElement.setAttributeNode(domAttr); } if (!strText.isEmpty()) { QDomText domText = domDoc.createTextNode(strText); domElement.appendChild(domText); } return domElement; }
void XmlDataPersistance::saveDegree(Degree *degree, QDomElement &element, QDomDocument &dom) { QDomElement degreeElement = dom.createElement("item"); degreeElement.setAttribute("type",degree->type()); element.appendChild(degreeElement); QDomElement titleElement = dom.createElement("titre"); titleElement.appendChild(dom.createTextNode(degree->title())); degreeElement.appendChild(titleElement); QDomElement typeElement = dom.createElement("type"); typeElement.appendChild(dom.createTextNode(degree->type())); degreeElement.appendChild(typeElement); const QList<const Uv*> &uvs = degree->uvs(); for(int i = 0; i < uvs.size(); i++) { QDomElement uvElement = dom.createElement("uv"); uvElement.appendChild(dom.createTextNode(uvs.at(i)->code())); degreeElement.appendChild(uvElement); } const QMap<QString,int> "as = degree->quotas(); QMapIterator<QString,int> it(quotas); while(it.hasNext()) { it.next(); QDomElement quotaElement = dom.createElement("quota"); QDomAttr cat = dom.createAttribute("categorie"); cat.setNodeValue(it.key()); quotaElement.setAttributeNode(cat); quotaElement.appendChild(dom.createTextNode(QString::number(it.value()))); degreeElement.appendChild(quotaElement); } const QList<Degree*> &children = degree->children(); for(int i = 0; i < children.size(); i++) saveDegree(children.at(i),degreeElement,dom); }
QDomElement SettingsObj::makeElement(QDomDocument &dom_doc, const QString &name, const QString &attr, const QString &text) { QDomElement dom_element = dom_doc.createElement(name); if(!attr.isEmpty()) { QDomAttr dom_attr = dom_doc.createAttribute("id"); dom_attr.setValue(attr); dom_element.setAttributeNode(dom_attr); } if(!text.isEmpty()) { QDomText dom_text = dom_doc.createTextNode(text); dom_element.appendChild(dom_text); } return dom_element; }
void RedisConnectionConfig::saveXmlAttribute(QDomDocument & document, QDomElement & root, const QString& name, const QString& value) { QDomAttr attr = document.createAttribute(name); attr.setValue(value); root.setAttributeNode(attr); }
int main(int argc, char *argv[]) {QCoreApplication a(argc,argv); QFile file( "domwrite.kdevelop" ); if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) ){ return 0; }else{ qDebug()<<"OPEN!"; } QDomDocument doc; QDomText text; QDomElement element; QDomProcessingInstruction instruction; instruction = doc.createProcessingInstruction( "xml", "version = \'1.0\'" ); doc.appendChild( instruction ); QDomElement root = doc.createElement( "kdevelop" ); doc.appendChild( root ); QDomElement general = doc.createElement( "general" ); root.appendChild( general ); element = doc.createElement( "author" ); text = doc.createTextNode( "zeki" ); general.appendChild( element ); element.appendChild( text ); element = doc.createElement( "email" ); text = doc.createTextNode( "*****@*****.**" ); element.appendChild( text ); general.appendChild( element ); element = doc.createElement( "version" ); text = doc.createTextNode( "$VERSION" ); element.appendChild( text ); general.appendChild( element ); QDomElement keywords = doc.createElement( "keywords" ); element = doc.createElement( "keyword" ); text = doc.createTextNode( "C++" ); element.appendChild( text ); keywords.appendChild( element ); general.appendChild( keywords ); element = doc.createElement( "ignoreparts" ); general.appendChild( element ); QDomElement kdevfileview = doc.createElement( "kdevfileview" ); QDomElement groups = doc.createElement( "groups" ); element = doc.createElement( "group" ); QDomAttr pattern = doc.createAttribute( "pattern" ); pattern.setValue( "*.cpp;*.cxx;*.h" ); QDomAttr name = doc.createAttribute( "name" ); name.setValue( "Sources" ); element.setAttributeNode( pattern ); element.setAttributeNode( name ); groups.appendChild( element ); kdevfileview.appendChild( groups ); root.appendChild( kdevfileview ); QTextStream out( &file ); doc.save( out, 4 ); file.close(); a.exec(); }
void schedulexmldata::initschedulexmldata() { QFile file("/home/user/.scheduledata.xml"); if( !file.open(QIODevice::ReadWrite)) return; QFileInfo fileinfo(file); if(fileinfo.size() == 0){ file.close(); QDomDocument doc; QDomProcessingInstruction instruction; instruction = doc.createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\""); doc.appendChild(instruction); QDomElement root = doc.createElement(QString("scheduledata")); doc.appendChild(root); QDomText text; QDomElement scheduledate = doc.createElement(QString("scheduledate")); root.appendChild(scheduledate); QDomAttr scheduledateattr = doc.createAttribute(QString("scheduledateattr")); scheduledateattr.setValue(QString("00000000")); scheduledate.setAttributeNode(scheduledateattr); QDomElement schedule = doc.createElement(QString("schedule")); scheduledate.appendChild(schedule); QDomAttr scheduleid = doc.createAttribute(QString("id")); scheduleid.setValue(QString("0")); schedule.setAttributeNode(scheduleid); QDomElement theme = doc.createElement(QString("theme")); text = doc.createTextNode(QString("")); theme.appendChild(text); schedule.appendChild(theme); QDomElement occurtime = doc.createElement(QString("occurtime")); text = doc.createTextNode(QString("")); occurtime.appendChild(text); schedule.appendChild(occurtime); QDomElement occuraddress = doc.createElement(QString("occuraddress")); text = doc.createTextNode(QString("")); schedule.appendChild(occuraddress); // QDomElement remindtime = doc.createElement(QString("remindtime")); // text = doc.createTextNode(QString("")); // remindtime.appendChild(text); // schedule.appendChild(remindtime); // QDomElement remindway = doc.createElement(QString("remindway")); // text = doc.createTextNode(QString("")); // remindway.appendChild(text); // schedule.appendChild(remindway); // QDomElement remindsequence = doc.createElement(QString("remindsequence")); // text = doc.createTextNode(QString("")); // remindsequence.appendChild(text); // schedule.appendChild(remindsequence); QDomElement eventrepeat = doc.createElement(QString("eventrepeat")); text = doc.createTextNode(QString("")); eventrepeat.appendChild(text); schedule.appendChild(eventrepeat); QDomElement detail = doc.createElement(QString("detail")); text = doc.createTextNode(QString("")); detail.appendChild(text); schedule.appendChild(detail); if( !file.open(QIODevice::WriteOnly | QIODevice::Truncate)) return; QTextStream out(&file); doc.save(out, 4); file.close(); }else{ file.close(); } }
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(); }
void TwoDRenderer::saveMap( QString filePath ) { QFile file( filePath ); if( false == file.open(QFile::WriteOnly) ) return; #define MAP_STRUCTURE "<?xml version=\"1.0\" ?>" \ "<delleriumMap>" \ "<walls></walls>" \ "<bushes></bushes>" \ "<me>" \ "<balls></balls>" \ "<targets></targets>" \ "</me>" \ "<enemy>" \ "<balls></balls>" \ "<targets></targets>" \ "</enemy>" \ "</delleriumMap>" // here we build the XML strucuture for the map QDomDocument domDocument; domDocument.setContent( QString(MAP_STRUCTURE) ); QDomNode rootNode = domDocument.documentElement(); QDomNode wallsNode = getChildByName( rootNode, "walls" ); QDomNode bushesNode = getChildByName( rootNode, "bushes" ); QDomNode meBallsNode = getChildByName( getChildByName(rootNode,"me"), "balls" ); QDomNode meTargetsNode = getChildByName( getChildByName(rootNode,"me"), "targets" ); QDomNode enemyBallsNode = getChildByName( getChildByName(rootNode,"enemy"), "balls" ); QDomNode enemyTargetsNode = getChildByName( getChildByName(rootNode,"enemy"), "targets" ); QList<QGraphicsItem*> gameObjects = _scene->items(); foreach( QGraphicsItem* item, gameObjects ) { GameObject* gameObject = static_cast<GameObject*>( item ); if( 0 != gameObject ) { switch( gameObject->getObjectType() ) { case GameObject::ObjectWall: { QDomElement element = domDocument.createElement( "wall" ); QDomAttr attributeX = domDocument.createAttribute( "x" ); attributeX.setValue( QString("%1").arg(gameObject->x()) ); QDomAttr attributeY = domDocument.createAttribute( "y" ); attributeY.setValue( QString("%1").arg(gameObject->y()) ); element.setAttributeNode( attributeX ); element.setAttributeNode( attributeY ); wallsNode.appendChild( element ); } break; case GameObject::ObjectBush: { QDomElement element = domDocument.createElement( "bush" ); QDomAttr attributeX = domDocument.createAttribute( "x" ); attributeX.setValue( QString("%1").arg(gameObject->x()) ); QDomAttr attributeY = domDocument.createAttribute( "y" ); attributeY.setValue( QString("%1").arg(gameObject->y()) ); element.setAttributeNode( attributeX ); element.setAttributeNode( attributeY ); bushesNode.appendChild( element ); } break; case GameObject::ObjectBall: { QDomElement element = domDocument.createElement( "ball" ); QDomAttr attributeX = domDocument.createAttribute( "x" ); attributeX.setValue( QString("%1").arg(gameObject->x()) ); QDomAttr attributeY = domDocument.createAttribute( "y" ); attributeY.setValue( QString("%1").arg(gameObject->y()) ); element.setAttributeNode( attributeX ); element.setAttributeNode( attributeY ); meBallsNode.appendChild( element ); } break; case GameObject::ObjectTarget: { QDomElement element = domDocument.createElement( "target" ); QDomAttr attributeX = domDocument.createAttribute( "x" ); attributeX.setValue( QString("%1").arg(gameObject->x()) ); QDomAttr attributeY = domDocument.createAttribute( "y" ); attributeY.setValue( QString("%1").arg(gameObject->y()) ); element.setAttributeNode( attributeX ); element.setAttributeNode( attributeY ); meTargetsNode.appendChild( element ); } break; case GameObject::ObjectEnemyBall: { QDomElement element = domDocument.createElement( "ball" ); QDomAttr attributeX = domDocument.createAttribute( "x" ); attributeX.setValue( QString("%1").arg(gameObject->x()) ); QDomAttr attributeY = domDocument.createAttribute( "y" ); attributeY.setValue( QString("%1").arg(gameObject->y()) ); element.setAttributeNode( attributeX ); element.setAttributeNode( attributeY ); enemyBallsNode.appendChild( element ); } break; case GameObject::ObjectEnemyTarget: { QDomElement element = domDocument.createElement( "target" ); QDomAttr attributeX = domDocument.createAttribute( "x" ); attributeX.setValue( QString("%1").arg(gameObject->x()) ); QDomAttr attributeY = domDocument.createAttribute( "y" ); attributeY.setValue( QString("%1").arg(gameObject->y()) ); element.setAttributeNode( attributeX ); element.setAttributeNode( attributeY ); enemyTargetsNode.appendChild( element ); } break; case GameObject::ObjectNone: default: break; } } }
bool MdiEditor::WriteXmlFile(QString filename) { //getParameters(); QFile file(filename); if(file.open(QIODevice::WriteOnly | QIODevice::Truncate |QIODevice::Text)) { QString str; QDomDocument doc; QDomText text; QDomElement element; QDomAttr attribute; QDomProcessingInstruction instruction = doc.createProcessingInstruction("xml","version=\'1.0\'"); doc.appendChild(instruction); QDomElement root = doc.createElement("project"); doc.appendChild(root); //Images QDomElement eimages=doc.createElement("images"); root.appendChild(eimages); attribute=doc.createAttribute("image1"); attribute.setValue("/image1.png"); eimages.setAttributeNode(attribute); QString filename; filename.sprintf("%s/image1.png",pro_path.toLatin1().data()); cv::imwrite(filename.toLatin1().data(),image1); attribute=doc.createAttribute("image2"); attribute.setValue("\\image2.png"); eimages.setAttributeNode(attribute); filename.sprintf("%s\\image2.png",pro_path.toLatin1().data()); cv::imwrite(filename.toLatin1().data(),image2); //layer QDomElement elayers=doc.createElement("layers"); root.appendChild(elayers); attribute=doc.createAttribute("num"); attribute.setValue(str.sprintf("%d",layer_num)); elayers.setAttributeNode(attribute); for(int index=0;index<layer_num;index++) { QDomElement elayer=doc.createElement(str.sprintf("l%d",index)); elayers.appendChild(elayer); QDir dir; QString filename; filename.sprintf("%s\\%d",pro_path.toLatin1().data(),index); dir.mkdir(filename); //masks QDomElement emask=doc.createElement("masks"); elayer.appendChild(emask); attribute=doc.createAttribute("mask1"); attribute.setValue(str.sprintf("\\%d\\mask1.png",index)); emask.setAttributeNode(attribute); filename.sprintf("%s\\%d\\mask1.png",pro_path.toLatin1().data(),index); cv::imwrite(filename.toLatin1().data(),parameters[index].mask1); attribute=doc.createAttribute("mask2"); attribute.setValue(str.sprintf("\\%d\\mask2.png",index)); emask.setAttributeNode(attribute); filename.sprintf("%s\\%d\\mask2.png",pro_path.toLatin1().data(),index); cv::imwrite(filename.toLatin1().data(),parameters[index].mask2); //parameters QDomElement epara=doc.createElement("parameters"); elayer.appendChild(epara); //weight element=doc.createElement("weight"); epara.appendChild(element); attribute=doc.createAttribute("ssim"); attribute.setValue(str.sprintf("%f",parameters[index].w_ssim)); element.setAttributeNode(attribute); attribute=doc.createAttribute("tps"); attribute.setValue(str.sprintf("%f",parameters[index].w_tps)); element.setAttributeNode(attribute); attribute=doc.createAttribute("ui"); attribute.setValue(str.sprintf("%f",parameters[index].w_ui)); element.setAttributeNode(attribute); attribute=doc.createAttribute("ssimclamp"); attribute.setValue(str.sprintf("%f",1.0-parameters[index].ssim_clamp)); element.setAttributeNode(attribute); //control points element=doc.createElement("points"); epara.appendChild(element); attribute=doc.createAttribute("image1"); str=""; for(size_t i=0;i<parameters[index].ui_points.size();i++) { QString num; str.append(num.sprintf("%f ",parameters[index].ui_points[i].lp.x)); str.append(num.sprintf("%f ",parameters[index].ui_points[i].lp.y)); } attribute.setValue(str); element.setAttributeNode(attribute); attribute=doc.createAttribute("image2"); str=""; for(size_t i=0;i<parameters[index].ui_points.size();i++) { QString num; str.append(num.sprintf("%f ",parameters[index].ui_points[i].rp.x)); str.append(num.sprintf("%f ",parameters[index].ui_points[i].rp.y)); } attribute.setValue(str); element.setAttributeNode(attribute); //boundary element=doc.createElement("boundary"); epara.appendChild(element); attribute=doc.createAttribute("lock"); int bcond=0; switch(parameters[index].bcond) { case BCOND_NONE: bcond=0; break; case BCOND_CORNER: bcond=1; break; case BCOND_BORDER: bcond=2; break; } attribute.setValue(str.sprintf("%d",bcond)); element.setAttributeNode(attribute); //debug element=doc.createElement("debug"); epara.appendChild(element); attribute=doc.createAttribute("iternum"); attribute.setValue(str.sprintf("%d",parameters[index].max_iter)); element.setAttributeNode(attribute); attribute=doc.createAttribute("dropfactor"); attribute.setValue(str.sprintf("%f",parameters[index].max_iter_drop_factor)); element.setAttributeNode(attribute); attribute=doc.createAttribute("eps"); attribute.setValue(str.sprintf("%f",parameters[index].eps)); element.setAttributeNode(attribute); attribute=doc.createAttribute("startres"); attribute.setValue(str.sprintf("%d",parameters[index].start_res)); element.setAttributeNode(attribute); } QTextStream out(&file); out.setCodec("UTF-8"); doc.save(out,4); file.close(); return true; } return false; }
int main(int argc, char *argv[]) { QFile file("domwrite.kdevelop"); if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { cout << "Can't create file!" << endl; return 1; } QDomDocument doc; QDomText text; QDomElement element; QDomProcessingInstruction instruction; instruction = doc.createProcessingInstruction("xml","version=\'1.0\'"); doc.appendChild(instruction); QDomElement root = doc.createElement("kdevelop"); doc.appendChild(root); QDomElement general = doc.createElement("general"); root.appendChild(general); element = doc.createElement("author"); text = doc.createTextNode("zeki"); element.appendChild(text); general.appendChild(element); element = doc.createElement("email"); text = doc.createTextNode("*****@*****.**"); element.appendChild(text); general.appendChild(element); element = doc.createElement("version"); text = doc.createTextNode("$VERSION"); element.appendChild(text); general.appendChild(element); element = doc.createElement("projectmanagement"); text = doc.createTextNode("KdevTrollProject"); element.appendChild(text); general.appendChild(element); element = doc.createElement("primarylanguage"); text = doc.createTextNode("C++"); element.appendChild(text); general.appendChild(element); QDomElement keywords = doc.createElement("keywords"); element = doc.createElement("keyword"); text = doc.createTextNode("C++"); element.appendChild(text); keywords.appendChild(element); general.appendChild(keywords); element = doc.createElement("projectname"); text = doc.createTextNode("domwrite"); element.appendChild(text); general.appendChild(element); element = doc.createElement("ignoreparts"); general.appendChild(element); element = doc.createElement("projectdirectory"); text = doc.createTextNode("."); element.appendChild(text); general.appendChild(element); element = doc.createElement("absoluteprojectpath"); text = doc.createTextNode("false"); element.appendChild(text); general.appendChild(element); element = doc.createElement("description"); general.appendChild(element); element = doc.createElement("defaultencoding"); general.appendChild(element); QDomElement kdevfileview = doc.createElement("kdevfileview"); QDomElement groups = doc.createElement("groups"); element = doc.createElement("group"); QDomAttr pattern = doc.createAttribute("pattern"); pattern.setValue("*.cpp;*.cxx;*.h"); QDomAttr name = doc.createAttribute("name"); name.setValue("Sources"); element.setAttributeNode(pattern); element.setAttributeNode(name); groups.appendChild(element); kdevfileview.appendChild(groups); root.appendChild(kdevfileview); QTextStream out(&file); doc.save(out, 4); return 0; }
void ExerciseWindow::generateXML(QDomElement &domElement, QDomDocument &doc) { int length = rand()%10+5; int choice = 0; int var_choice = 0; int i = 0; QDomElement block = doc.createElement("FCBeginWidget"); QString sAttr = "operator()"; QDomAttr attr = doc.createAttribute("text"); domElement.appendChild(block); while (i < length) { choice = rand()%7; attr = doc.createAttribute("text"); var_choice = rand()%vars.size(); QString var = vars[var_choice]; switch(choice) { case 0: { block = doc.createElement("FCActionWidget"); sAttr = var + " = " + QString::number(rand()%10); attr.setValue(sAttr); } break; case 1: { block = doc.createElement("FCInputWidget"); attr.setValue(var); } break; case 2: { block = doc.createElement("FCOutputWidget"); attr.setValue(var); } break; case 3: { block = doc.createElement("FCDivarWidget"); QString decision = var + " == " + QString::number(5); if (i%2 == 0) decision = var + " < " + QString::number(10); else decision = var + " > " + QString::number(0); attr.setValue(decision); QDomElement left = doc.createElement("Left"); QDomElement right = doc.createElement("Right"); block.appendChild(left); block.appendChild(right); QDomElement blockTrue = doc.createElement("FCActionWidget"); QDomElement blockFalse = doc.createElement("FCActionWidget"); QDomAttr attribute = doc.createAttribute("text"); attribute.setValue(var + "++"); blockTrue.setAttributeNode(attribute); attribute = doc.createAttribute("text"); attribute.setValue(var + "--"); blockFalse.setAttributeNode(attribute); left.appendChild(blockTrue); right.appendChild(blockFalse); } break; case 4: { block = doc.createElement("FCPrefixCycleWidget"); QString decision = var + " < " + QString::number(i * 5); attr.setValue(decision); QDomElement body = doc.createElement("Body"); block.appendChild(body); QDomElement blockTrue = doc.createElement("FCActionWidget"); QDomAttr attribute = doc.createAttribute("text"); attribute.setValue(var + "++"); blockTrue.setAttributeNode(attribute); body.appendChild(blockTrue); } break; case 5: { block = doc.createElement("FCPostfixCycleWidget"); QString decision = var + " < " + QString::number(i * 5); attr.setValue(decision); QDomElement body = doc.createElement("Body"); block.appendChild(body); QDomElement blockTrue = doc.createElement("FCActionWidget"); QDomAttr attribute = doc.createAttribute("text"); attribute.setValue(var + "++"); blockTrue.setAttributeNode(attribute); body.appendChild(blockTrue); } break; case 6: { block = doc.createElement("FCParameterCycleWidget"); QString decision = "int i = 0; i < " + QString::number(i * 5) + "; i++"; attr.setValue(decision); QDomElement body = doc.createElement("Body"); block.appendChild(body); QDomElement blockTrue = doc.createElement("FCActionWidget"); QDomAttr attribute = doc.createAttribute("text"); attribute.setValue(var + "++"); blockTrue.setAttributeNode(attribute); body.appendChild(blockTrue); } } block.setAttributeNode(attr); domElement.appendChild(block); i++; } block = doc.createElement("FCEndWidget"); domElement.appendChild(block); }
void MainWindowTask::saveCourseFile() { qDebug()<<"Save cource file"; QDomDocument saveXml; QDomElement crsEl=saveXml.createElement("COURSE"); QDomElement fileEl=saveXml.createElement("FILE"); QDomAttr crsAtt=saveXml.createAttribute("fileName"); crsAtt.setValue(cursFile); fileEl.setAttributeNode(crsAtt); crsEl.appendChild(fileEl); saveXml.appendChild(crsEl); QDomElement mrksEl=saveXml.createElement("MARKS"); //USER PROGRAMS n TESTED PROGRAMS for(int i=0;i<progChange.count();i++){ QDomElement prgEl=saveXml.createElement("USER_PRG"); QDomAttr testIdprg=saveXml.createAttribute("testId"); testIdprg.setValue(QString::number(progChange[i])); QDomAttr userPrg=saveXml.createAttribute("prg"); userPrg.setValue(course->getUserText(progChange[i])); prgEl.setAttributeNode(testIdprg); prgEl.setAttributeNode(userPrg); crsEl.appendChild(prgEl); QDomElement prgElT=saveXml.createElement("TESTED_PRG"); QDomAttr testIdprgT=saveXml.createAttribute("testId"); testIdprgT.setValue(QString::number(progChange[i])); QDomAttr userPrgT=saveXml.createAttribute("prg"); userPrgT.setValue(course->getUserTestedText(progChange[i])); prgElT.setAttributeNode(testIdprg); prgElT.setAttributeNode(userPrgT); crsEl.appendChild(prgElT); } //END USER PROGRAMS QMapIterator<int, int> i(changes.marksChanged); while (i.hasNext()) { i.next(); QDomElement mrk=saveXml.createElement("MARK"); QDomAttr testId=saveXml.createAttribute("testId"); testId.setValue(QString::number(i.key())); QDomAttr mvalue=saveXml.createAttribute("mark"); mvalue.setValue(QString::number(i.value())); mrk.setAttributeNode(testId); mrk.setAttributeNode(mvalue); mrksEl.appendChild(mrk); } crsEl.appendChild(mrksEl); if (!cursWorkFile.open(QIODevice::WriteOnly)) { QMessageBox::information( 0, "", trUtf8("Ошибка записи: ") + cursWorkFile.fileName(), 0,0,0); return; }; cursWorkFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); cursWorkFile.write(saveXml.toByteArray()); cursWorkFile.close(); };