예제 #1
1
bool saveXMLFile(const QString& path, VirtualDataSceneData::XmlMap* map)
{
	QFile xmlFile(path);
	if (!xmlFile.open(QIODevice::WriteOnly | QIODevice::Text))
		return false;
	QDomDocument domTree;
	QDomText text;
	domTree.documentElement().clear();
	QDomProcessingInstruction instruction;
	instruction = domTree.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
	domTree.appendChild(instruction);
	QDomElement mapElement = domTree.createElement(XML_ELEMENT_MAP);
	domTree.appendChild(mapElement);
	QDomElement eventsElement = domTree.createElement(XML_ELEMENT_EVENTS);
	mapElement.appendChild(eventsElement);
	QDomElement actorsElement = domTree.createElement(XML_ELEMENT_ACTORS);
	mapElement.appendChild(actorsElement);

	std::vector< VirtualDataSceneBase::ActorBase* > allActors;
	map->getAllActors(allActors);
	for (unsigned int i = 0; i < allActors.size(); ++i)
	{
		VirtualDataSceneBase::ActorBase* curActor = allActors.at(i);
		QDomElement actorElement = domTree.createElement(XML_ELEMENT_ACTOR);
		actorsElement.appendChild(actorElement);
		actorElement.setAttribute(XML_ELEMENT_TYPE, chineseTextUTF8ToQString(curActor->getClassName()));
		QDomElement actorIdElement = domTree.createElement(XML_ELEMENT_ID);
		text = domTree.createTextNode(chineseTextUTF8ToQString(curActor->getId()));
		actorIdElement.appendChild(text);
		actorElement.appendChild(actorIdElement);
		QDomElement actorNameElement = domTree.createElement(XML_ELEMENT_NAME);
		text = domTree.createTextNode(chineseTextUTF8ToQString(curActor->getActorName()));
		actorNameElement.appendChild(text);
		actorElement.appendChild(actorNameElement);
		//property
		std::vector< VirtualDataSceneBase::ActorProperty* > propertyList;
		curActor->getPropertyList(propertyList);
		for (unsigned int j = 0; j < propertyList.size(); ++j)
		{
			VirtualDataSceneBase::ActorProperty* curProperty = propertyList.at(j);
			QDomElement actorPropertyElement = domTree.createElement(XML_ELEMENT_PROPERTY);
			actorElement.appendChild(actorPropertyElement);
			QDomElement propertyNameElement = domTree.createElement(XML_ELEMENT_NAME);
			text = domTree.createTextNode(chineseTextUTF8ToQString(curProperty->getName()));
			propertyNameElement.appendChild(text);
			actorPropertyElement.appendChild(propertyNameElement);
			QDomElement propertyValueElement = domTree.createElement(chineseTextUTF8ToQString(curProperty->getDataType()));
			QString qTextValue = chineseTextUTF8ToQString(curProperty->toString());
			//if (qTextValue.contains('<') || qTextValue.contains('>') || qTextValue.contains('&') || qTextValue.contains('\'') || qTextValue.contains('"'))
			//	qTextValue = "<![CDATA[" + qTextValue + "]]>";
			text = domTree.createTextNode(qTextValue);
			propertyValueElement.appendChild(text);
			actorPropertyElement.appendChild(propertyValueElement);
		}
	}
	QTextStream out(&xmlFile);
	domTree.save(out, 4, QDomNode::EncodingFromTextStream);
	xmlFile.close();
	return true;
}
/**
* \brief This function save an \b XML \b file from a \b QDomDocument
* \author Jules Gorny - ALCoV team, ISIT, UMR 6284 UdA – CNRS
* \param filename : path of the file we will write
* \param XSDpath : path of the XSD file to check the xml validity
* \param doc : our xml tree in a QDomDocument
* \param indent : number of spaces for an indentation
*/
void writeXML(QString filename, QDomDocument doc, int indent)
{
	QFile file(filename);
	file.open(QIODevice::WriteOnly);
	QTextStream ts(&file);
	doc.save(ts, indent);
}
예제 #3
0
void readers::writeSetting(){
    QSettings sett("Skyrim", "lib");
    QString path(QString("%1/setting.xml").arg(sett.value("path").toString()));
    QFile file(path);
    QTextStream in(&file);
    QTextStream out(&file);

    QDomDocument doc;
    file.open(QIODevice::ReadOnly);
    doc.setContent(out.readAll());
    file.close();
    QDomNodeList node = doc.elementsByTagName("readers");
    node.item(0).attributes().namedItem("width").setNodeValue(QString("%1").arg(geometry().size().width()));
    node.item(0).attributes().namedItem("height").setNodeValue(QString("%1").arg(geometry().size().height()));
    node.item(0).attributes().namedItem("x").setNodeValue(QString("%1").arg(geometry().x()));
    node.item(0).attributes().namedItem("y").setNodeValue(QString("%1").arg(geometry().y()));
    node.item(0).attributes().namedItem("fam").setNodeValue(QString("%1").arg(ui.checkBox_fam->isChecked()));
    node.item(0).attributes().namedItem("ima").setNodeValue(QString("%1").arg(ui.checkBox_ima->isChecked()));
    node.item(0).attributes().namedItem("otc").setNodeValue(QString("%1").arg(ui.checkBox_otc->isChecked()));
    node.item(0).attributes().namedItem("date_r").setNodeValue(QString("%1").arg(ui.checkBox_data_r->isChecked()));
    node.item(0).attributes().namedItem("num").setNodeValue(QString("%1").arg(ui.checkBox_num->isChecked()));
    node.item(0).attributes().namedItem("phone").setNodeValue(QString("%1").arg(ui.checkBox_phone->isChecked()));
    node.item(0).attributes().namedItem("address").setNodeValue(QString("%1").arg(ui.checkBox_address->isChecked()));
    node.item(0).attributes().namedItem("doc").setNodeValue(QString("%1").arg(ui.checkBox_doc->isChecked()));
    file.open(QIODevice::WriteOnly);
    doc.save(out, 4);
    file.close();
}
void QgsSubstitutionListWidget::mButtonExport_clicked()
{
  QString fileName = QFileDialog::getSaveFileName( this, tr( "Save substitutions" ), QDir::homePath(),
                     tr( "XML files (*.xml *.XML)" ) );
  if ( fileName.isEmpty() )
  {
    return;
  }

  // ensure the user never omitted the extension from the file name
  if ( !fileName.endsWith( QLatin1String( ".xml" ), Qt::CaseInsensitive ) )
  {
    fileName += QLatin1String( ".xml" );
  }

  QDomDocument doc;
  QDomElement root = doc.createElement( QStringLiteral( "substitutions" ) );
  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
  QgsStringReplacementCollection collection = substitutions();
  collection.writeXml( root, doc );
  doc.appendChild( root );

  QFile file( fileName );
  if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
  {
    QMessageBox::warning( nullptr, tr( "Export substitutions" ),
                          tr( "Cannot write file %1:\n%2." ).arg( fileName, file.errorString() ),
                          QMessageBox::Ok,
                          QMessageBox::Ok );
    return;
  }

  QTextStream out( &file );
  doc.save( out, 4 );
}
예제 #5
0
bool FotowallFile::saveV2(const QString & fwFilePath, const Canvas * canvas)
{
    // create the document
    QDomDocument doc;
     doc.appendChild(doc.createProcessingInstruction("xml","version=\"1.0\" "));

    QDomElement rootElement = doc.createElement("fotowall");
     rootElement.setAttribute("format", 2);
     rootElement.setAttribute("version", QCoreApplication::applicationVersion());
     doc.appendChild(rootElement);

    QDomElement canvasElement = doc.createElement("canvas");
     rootElement.appendChild(canvasElement);

    // save current canvas
    Canvas * rwCanvas = (Canvas *)canvas;
    rwCanvas->setFilePath(fwFilePath);
    canvas->saveToXml(canvasElement);

    // open the file for writing
    QFile file(fwFilePath);
    if (!file.open(QIODevice::WriteOnly)) {
        QMessageBox::warning(0, QObject::tr("File Error"), QObject::tr("Error saving to the Fotowall file '%1'").arg(fwFilePath));
        return false;
    }

    // save in the file (2 indent spaces)
    QTextStream outStream(&file);
    doc.save(outStream, 2);
    file.close();

    // store a reference to the just written file
    App::settings->addRecentFotowallUrl(QUrl(fwFilePath));
    return true;
}
예제 #6
0
void XMLOperations::touchDownloadTrashConfigFile()
{
    QFile downloadTrashFile(DOWNLOADTRASHFILE_PATH);
    if (!downloadTrashFile.exists())
    {
        if (!downloadTrashFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
        {
            return;
        }

        QDomDocument domDocument;

        QDomProcessingInstruction instruction;
        instruction=domDocument.createProcessingInstruction("xml","version=\'1.0\' encoding=\'UTF-8\'");

        domDocument.appendChild(instruction);

        //创建MainConfig根节点
        QDomElement downloadTrashNode = domDocument.createElement("DownloadTrashList");
        //添加元素节点到父节点
        domDocument.appendChild(downloadTrashNode);

        //写xml文件
        QTextStream textStream(&downloadTrashFile);

        domDocument.save(textStream,4);

        downloadTrashFile.close();
    }
}
void QgsRasterTerrainAnalysisDialog::on_mExportColorsButton_clicked()
{
  qWarning( "Export colors clicked" );
  QString file = QFileDialog::getSaveFileName( 0, tr( "Export Colors and elevations as xml" ), QDir::homePath() );
  if ( file.isEmpty() )
  {
    return;
  }

  QDomDocument doc;
  QDomElement reliefColorsElem = doc.createElement( "ReliefColors" );
  doc.appendChild( reliefColorsElem );

  QList< QgsRelief::ReliefColor > rColors = reliefColors();
  QList< QgsRelief::ReliefColor >::const_iterator rColorsIt = rColors.constBegin();
  for ( ; rColorsIt != rColors.constEnd(); ++rColorsIt )
  {
    QDomElement classElem = doc.createElement( "ReliefColor" );
    classElem.setAttribute( "MinElevation", QString::number( rColorsIt->minElevation ) );
    classElem.setAttribute( "MaxElevation", QString::number( rColorsIt->maxElevation ) );
    classElem.setAttribute( "red", QString::number( rColorsIt->color.red() ) );
    classElem.setAttribute( "green", QString::number( rColorsIt->color.green() ) );
    classElem.setAttribute( "blue", QString::number( rColorsIt->color.blue() ) );
    reliefColorsElem.appendChild( classElem );
  }

  QFile outputFile( file );
  if ( !outputFile.open( QIODevice::WriteOnly ) )
  {
    return;
  }
  QTextStream outStream( &outputFile );
  doc.save( outStream, 2 );
}
예제 #8
0
void XMLOperations::insertDownloadTrash(SDownloadTrash tmpStruct)
{
    QDomDocument domDocument;
    QFile downloadTrashFile(DOWNLOADTRASHFILE_PATH);
    if (downloadTrashFile.open(QIODevice::ReadOnly))
    {
        // 此处需做错误判断
        if (!domDocument.setContent(&downloadTrashFile))
            return;
    }
    else
        return;

    downloadTrashFile.close();

    QDomElement fileElement = domDocument.createElement("File");

    fileElement.appendChild(createChildElement("Name", tmpStruct.name));
    fileElement.appendChild(createChildElement("URL", tmpStruct.URL));
    fileElement.appendChild(createChildElement("DLToolsType", tmpStruct.dlToolsType));
    fileElement.appendChild(createChildElement("TotalSize", tmpStruct.totalSize));
    fileElement.appendChild(createChildElement("IconPath",tmpStruct.iconPath));

    QDomElement rootElement = domDocument.documentElement();
    rootElement.appendChild(fileElement);

    //写xml文件
    if (!downloadTrashFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
        return;
    QTextStream textStream(&downloadTrashFile);

    domDocument.save(textStream,4);

    downloadTrashFile.close();
}
예제 #9
0
bool PkExampleHelper::setValue(const QString &action)
{
    // This action must be authorized first. It will set the implicit
    // authorization for the Shout action by editing the .policy file
    QDomDocument doc = QDomDocument("policy");
    QFile file("/usr/share/polkit-1/actions/org.qt.policykit.examples.policy");
    if (!file.open(QIODevice::ReadOnly))
        return false;
    doc.setContent(&file);
    file.close();
    QDomElement el = doc.firstChildElement("policyconfig").
                     firstChildElement("action");
    while (!el.isNull() && el.attribute("id", QString()) != "org.qt.policykit.examples.shout") {
        el = el.nextSiblingElement("action");
    }
    el = el.firstChildElement("defaults");
    el = el.firstChildElement("allow_active");
    if (el.isNull())
        return false;
    el.firstChild().toText().setData(action);
    if (!file.open(QIODevice::WriteOnly))
        return false;
    QTextStream stream(&file);
    doc.save(stream, 2);
    file.close();
    return true;
}
예제 #10
0
ConnectDialog::~ConnectDialog(void)
{
    /* Aktuelle Werte als Default speichern */
    QFile file(m_configFile);

    if (file.open(QIODevice::WriteOnly))
    {
        QDomDocument doc;
        QDomElement root = doc.createElement("connection");
        doc.appendChild(root);

        QDomElement tag  = doc.createElement("host");
        QDomText    text = doc.createTextNode(m_ui->m_lineAddress->text());
        root.appendChild(tag);
        tag.appendChild(text);

        tag  = doc.createElement("port");
        text = doc.createTextNode(QString::number(m_ui->m_spinPort->value()));
        root.appendChild(tag);
        tag.appendChild(text);

        QTextStream stream(&file);
        doc.save(stream, 2);
        file.close();
    }
}
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();
}
예제 #12
0
/**
 * 特徴量をxmlファイルに保存する。
 */
void GenericFeature::save(QString filename) {
	QDomDocument doc;

	QDomElement root = doc.createElement("features");
	doc.appendChild(root);

	QDomElement node_feature = doc.createElement("feature");
	node_feature.setAttribute("type", "generic");
	root.appendChild(node_feature);

	// write avenue node
	QDomElement node_avenue = doc.createElement("avenue");
	node_feature.appendChild(node_avenue);
	saveAvenue(doc, node_avenue);

	// write street node
	QDomElement node_street = doc.createElement("street");
	node_feature.appendChild(node_street);
	saveStreet(doc, node_street);

	// write the dom to the file
	QFile file(filename);
	file.open(QIODevice::WriteOnly);

	QTextStream out(&file);
	doc.save(out, 4);
}
예제 #13
0
void schedulexmldata::deleteonescheduledata(QString tmpscheduledate, QString tmpid)
{
    QFile file("/home/user/.scheduledata.xml");
    if(!file.open(QIODevice::ReadOnly))  return;
    QDomDocument doc;
    if(!doc.setContent(&file)){
        file.close();
        return;
    }
    file.close();

    QDomElement root = doc.documentElement();
    QDomNode n = root.firstChild();
    while(!n.isNull()){
        if(tmpscheduledate == n.toElement().attribute(QString("scheduledateattr"))){
            QDomNodeList schedulelist = n.toElement().elementsByTagName(QString("schedule"));
            for(int m=0; m<schedulelist.count(); m++){
                if(schedulelist.at(m).toElement().attribute(QString("id")) == tmpid){
                    qDebug() << n.toElement().tagName();
                    n.toElement().removeChild(schedulelist.at(m));
                }
            }
        }
        n = n.nextSibling();
    }

    if( !file.open(QIODevice::WriteOnly | QIODevice::Truncate)) return;
    QTextStream out(&file);
    doc.save(out, 4);
    file.close();
}
void FavouriteManagerPrivate::save()
{
    QDomDocument document;
    QDomElement rootElement = document.createElement("favourites");

    QListIterator<QPair<QString, Station> > iterator
            = QListIterator<QPair<QString, Station> >(data);
    while (iterator.hasNext()) {
        QPair<QString, Station> entry = iterator.next();
        QDomElement element = XmlConversionHelper::toXml(entry.second, &document);
        element.setAttribute(BACKEND_ATTRIBUTE, entry.first);
        rootElement.appendChild(element);
    }
    document.appendChild(rootElement);

    QDir favouriteDir = QDir(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
    if (!favouriteDir.exists()) {
        QDir::root().mkpath(favouriteDir.absolutePath());
    }


    QFile file (favouriteDir.absoluteFilePath(fileName));
    if (!file.open(QIODevice::WriteOnly)) {
        return;
    }

    QTextStream stream(&file);
    document.save(stream, 2);
    file.close();
}
예제 #15
0
파일: dom.cpp 프로젝트: gavalda/CalcPolo
void Dom::ecrire(QString fileName)
{
    QFile file;
    QDomDocument doc;
    QDomElement sauvegarde;
    QDomElement racine;

    QTextStream out;

    doc.clear();
    racine=doc.createElement("sauvegardes");
    doc.appendChild(racine); // filiation de la balise "sauvegarde"

    file.setFileName(fileName);
    if (!file.open(QIODevice::WriteOnly)) // ouverture du fichier de sauvegarde
        return; // en écriture
    out.setDevice(&file); // association du flux au fichier


    for(int i=0; i<p.size(); i++){
        sauvegarde=doc.createElement("sauvegarde");
        sauvegarde.setAttribute("valeur", p.at(i)->toQString());
        racine.appendChild(sauvegarde);
    }

    QDomNode noeud = doc.createProcessingInstruction("xml","version=\"1.0\"");
    doc.insertBefore(noeud,doc.firstChild());
    // sauvegarde dans le flux (deux espaces de décalage dans l'arborescence)
    doc.save(out,2);
    file.close();
}
예제 #16
0
void XMLOperations::removeDownloadTrashFileNode(QString URL)
{
    QDomDocument domDocument;
    QFile downloadTrashFile(DOWNLOADTRASHFILE_PATH);
    if (downloadTrashFile.open(QIODevice::ReadOnly))
    {
        // 此处需做错误判断
        if (!domDocument.setContent(&downloadTrashFile))
            return;
    }
    else
        return;

    downloadTrashFile.close();
    qDebug() << "remove trash item";

    domDocument.documentElement().removeChild(getMatchFileNode(domDocument,URL));

    //写xml文件
    if (!downloadTrashFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
        return;
    QTextStream textStream(&downloadTrashFile);
    domDocument.save(textStream,4);
    downloadTrashFile.close();
}
예제 #17
0
void
TagColorEditor::copyGradientFile(QString stopsflnm)
{
  QString sflnm = ":/images/gradientstops.xml";
  QFileInfo fi(sflnm);
  if (! fi.exists())
    {
      QMessageBox::information(0, "Gradient Stops",
			       QString("Gradient Stops file does not exit at %1").arg(sflnm));
      
      return;
    }

  // copy information from gradientstops.xml to HOME/.drishtigradients.xml
  QDomDocument document;
  QFile f(sflnm);
  if (f.open(QIODevice::ReadOnly))
    {
      document.setContent(&f);
      f.close();
    }
  
  QFile fout(stopsflnm);
  if (fout.open(QIODevice::WriteOnly))
    {
      QTextStream out(&fout);
      document.save(out, 2);
      fout.close();
    }
}
예제 #18
0
QByteArray BasketModel::indexesToXML(const QModelIndexList &indexes) const
{
    QDomDocument doc;
    QDomElement	root = doc.createElement( "basket-passwords-items" );

    doc.appendChild( root );

    foreach(QModelIndex idx, indexes) {
        if ( !idx.isValid() )
            continue;
        if ( idx.column() != 0 )
            continue;

        BasketBaseItem *item = static_cast<BasketBaseItem *>(idx.internalPointer());
        if ( !item )
            continue;

        QDomElement child = convertBasketItemToDomElement(item, doc);
        root.appendChild(child);
    }

    QByteArray clearBuffer;
    QBuffer clearFile ( &clearBuffer );
    if ( !clearFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
        return QByteArray();

    QTextStream clearStream(&clearFile);
    doc.save(clearStream, 4);
    clearFile.close();

    return clearBuffer;
}
예제 #19
0
bool QgsScaleUtils::saveScaleList( const QString &fileName, const QStringList &scales, QString &errorMessage )
{
  QDomDocument doc;
  QDomElement root = doc.createElement( "qgsScales" );
  root.setAttribute( "version", "1.0" );
  doc.appendChild( root );

  for ( int i = 0; i < scales.count(); ++i )
  {
    QDomElement el = doc.createElement( "scale" );
    el.setAttribute( "value", scales.at( i ) );
    root.appendChild( el );
  }

  QFile file( fileName );
  if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
  {
    errorMessage = QString( "Cannot write file %1:\n%2." ).arg( fileName, file.errorString() );
    return false;
  }

  QTextStream out( &file );
  doc.save( out, 4 );
  return true;
}
예제 #20
0
void QgsSearchQueryBuilder::saveQuery()
{
  QgsSettings s;
  QString lastQueryFileDir = s.value( QStringLiteral( "/UI/lastQueryFileDir" ), QDir::homePath() ).toString();
  //save as qqt (QGIS query file)
  QString saveFileName = QFileDialog::getSaveFileName( nullptr, tr( "Save query to file" ), lastQueryFileDir, QStringLiteral( "*.qqf" ) );
  if ( saveFileName.isNull() )
  {
    return;
  }

  if ( !saveFileName.endsWith( QLatin1String( ".qqf" ), Qt::CaseInsensitive ) )
  {
    saveFileName += QLatin1String( ".qqf" );
  }

  QFile saveFile( saveFileName );
  if ( !saveFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
  {
    QMessageBox::critical( nullptr, tr( "Error" ), tr( "Could not open file for writing" ) );
    return;
  }

  QDomDocument xmlDoc;
  QDomElement queryElem = xmlDoc.createElement( QStringLiteral( "Query" ) );
  QDomText queryTextNode = xmlDoc.createTextNode( txtSQL->text() );
  queryElem.appendChild( queryTextNode );
  xmlDoc.appendChild( queryElem );

  QTextStream fileStream( &saveFile );
  xmlDoc.save( fileStream, 2 );

  QFileInfo fi( saveFile );
  s.setValue( QStringLiteral( "/UI/lastQueryFileDir" ), fi.absolutePath() );
}
예제 #21
0
void
TransferFunctionManager::save(const char *flnm)
{
  QDomDocument document;
  QFile f(flnm);
  if (f.open(QIODevice::ReadOnly))
    {
      document.setContent(&f);
      f.close();
    }
  QDomElement topElement = document.documentElement();
  for(int i=0; i<m_tfContainer->count(); i++)
    {
      QDomElement de = m_tfContainer->transferFunctionPtr(i)->domElement(document);
      topElement.appendChild(de);
    }

  QFile fout(flnm);
  if (fout.open(QIODevice::WriteOnly))
    {
      QTextStream out(&fout);
      document.save(out, 2);
      fout.close();
    }
}
예제 #22
0
//modify the flight information (modify cabin's remain tickets or specific tag's value)
//if tag = remain, then value is the variable (include positive or negative number)
bool editDB(QString depc, QString arrc, QString date, QString ID, QString tag, QString value, QString cabin = ""){
	QDomDocument doc;
	QFile file("Resources\\" + date + ".xml");
	if(!file.open(QFile::ReadOnly))return false;
	if(!doc.setContent(&file))return false;

	QDomElement elem = doc.documentElement();
	for(elem = elem.firstChildElement(); !elem.isNull() && elem.attribute("name") != depc; elem = elem.nextSiblingElement());
	for(elem = elem.firstChildElement(); !elem.isNull() && elem.attribute("name") != arrc; elem = elem.nextSiblingElement());
	for(elem = elem.firstChildElement(); !elem.isNull() && elem.attribute("ID") != ID; elem = elem.nextSiblingElement());
	if(elem.isNull())return false;
	if(cabin == "")elem.setAttribute(tag, value);
	else {
		for(elem = elem.firstChildElement(); !elem.isNull() && elem.attribute("name") != cabin; elem = elem.nextSiblingElement());
		if(tag == "remain"){         //number variable is passed 
			int curr = elem.attribute("remain").toInt();
			elem.setAttribute("remain", curr + value.toInt());
		}
		else elem.setAttribute(tag, value);
	}
	file.close();
	if(!file.open(QFile::WriteOnly | QFile::Truncate))return false;
	QTextStream out(&file);
	doc.save(out,4);
	file.close();
	return true;
}
예제 #23
0
//update the whole database in 30 days from today
bool updateDB(){
	//if not exist root directory then create
	QDir dbdir(".");
	dbdir.mkdir("Resources");

	QDateTime dt;
	QDate d;
	dt.setDate(d.currentDate());   //get current date
	QFileInfo dbfile;
	for(int x = 0; x < 31; x ++){
		QString date = dt.addDays(x).toString("yyyy-MM-dd");
		//qDebug() << date;
		dbfile.setFile("Resources\\" + date + ".xml");
		if(dbfile.exists())continue;     //check if data file existed
		else if(!createDB(date))return false;
	}

	//create user data file
	dbfile.setFile("Resources\\userDB.xml");
	if(!dbfile.exists()){
		QFile file("Resources\\userDB.xml");
		if(!file.open(QFile::WriteOnly | QFile::Text))return false;
		QDomDocument doc;
		QDomProcessingInstruction instruction;
		instruction = doc.createProcessingInstruction("xml","version=\"1.0\"");
		doc.appendChild(instruction);
		QDomElement root = doc.createElement("userIndex");
		doc.appendChild(root);
		QTextStream out(&file);
		doc.save(out,4);
		file.close();
	}

	return true;
}
예제 #24
0
bool KisWorkspaceResource::saveToDevice(QIODevice *dev) const
{
    QDomDocument doc;
    QDomElement root = doc.createElement("Workspace");
    root.setAttribute("name", name() );
    root.setAttribute("version", WORKSPACE_VERSION);
    QDomElement state = doc.createElement("state");
    state.appendChild(doc.createCDATASection(m_dockerState.toBase64()));
    root.appendChild(state);

    // Save KisPropertiesConfiguration settings
    QDomElement settings = doc.createElement("settings");
    KisPropertiesConfiguration::toXML(doc, settings);
    root.appendChild(settings);
    doc.appendChild(root);

    QTextStream textStream(dev);
    textStream.setCodec("UTF-8");
    doc.save(textStream, 4);

    KoResource::saveToDevice(dev);

    return true;

}
예제 #25
0
QByteArray BasketModel::modelDataToXML(bool encrypted)
{
    QDomDocument doc;
    QDomElement	root = doc.createElement( "basket-passwords" );
    root.setAttribute(QString("ident"), identifier());
    setTimeModified(QDateTime::currentDateTime());
    //lastDBModified = QDateTime::currentDateTime();
    root.setAttribute(QString("modified"), lastDBModified.toString(DATE_TIME_FORMAT));

    doc.appendChild( root );
    for ( int i = 0; i < rootItem->childCount(); i++ ) {
        QDomElement child = convertBasketItemToDomElement(rootItem->childItemAt(i), doc);
        root.appendChild(child);
    }

    QByteArray clearBuffer;
    QBuffer clearFile ( &clearBuffer );
    if ( !clearFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
        return QByteArray();

    QTextStream clearStream(&clearFile);
    doc.save(clearStream, 4);
    clearFile.close();

    if ( !encrypted )
        return clearBuffer;

    BasketUtils butil;
    QByteArray encryptedBuffer = butil.crypt(clearBuffer, hash());

    return encryptedBuffer;
}
예제 #26
0
void MainWindow::on_pushButtonDeleteEvaluationData_clicked()
{
  for (int i = 0; i < ui->listWidget->count(); i++)
  {
    QString fileName = ui->listWidget->item(i)->text();
    QFile* file = new QFile(fileName);

    if (!file->open(QIODevice::ReadOnly))
    {
      QMessageBox messageBox;
      messageBox.setText(tr("could not open file: %1 for reading").arg(fileName));
      messageBox.exec();
      continue;
    }

    ui->statusBar->showMessage(fileName);

    QString errorStr;
    int errorLine;
    int errorColumn;

    QDomDocument domDocument;

    if (!domDocument.setContent(file, true, &errorStr, &errorLine, &errorColumn))
    {
      QString errorString = tr("Parse error at line %1, column %2:\n%3").arg(errorLine).arg(errorColumn).arg(errorStr);
      QMessageBox::information(window(), tr("XML parse error"), errorString);
      return;
    }

    file->close();

    // remove EvalutationData
    QDomNodeList domNodeList = domDocument.elementsByTagName("EvaluationData");

    for (int j = 0; j < domNodeList.length(); j++)
    {
      QApplication::processEvents(); // keeping the GUI responsive
      QDomNode domNode = domNodeList.at(j);
      domNode.parentNode().removeChild(domNode);
    }

    if (!file->open(QIODevice::WriteOnly))
    {
      QMessageBox messageBox;
      messageBox.setText(tr("could not open file: %1 for writing").arg(fileName));
      messageBox.exec();
      continue;
    }

    QTextStream out(file);
    domDocument.save(out, 2);

    file->close();
  }

  ui->statusBar->showMessage(tr("ready"));
}
/*!
  Renders the XML document \a document.
*/
bool TActionController::renderXml(const QDomDocument &document)
{
    QByteArray xml;
    QTextStream ts(&xml);

    ts.setCodec("UTF-8");
    document.save(ts, 1, QDomNode::EncodingFromTextStream);
    return sendData(xml, "text/xml");
}
예제 #28
0
void XMLOperations::touchMainConfigFile()
{
    QFile mainConfigFile(MAINCONFIGFILE_PATH);
    if (!mainConfigFile.exists())
    {
        if (!mainConfigFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
        {
            return;
        }

        QDomDocument domDocument;

        QDomProcessingInstruction instruction;
        instruction=domDocument.createProcessingInstruction("xml","version=\'1.0\' encoding=\'UTF-8\'");

        domDocument.appendChild(instruction);

        //创建MainConfig根节点
        QDomElement mainConfigNode = domDocument.createElement("MainConfig");

        //将各个子节点添加到@mainConfigNode节点上
#ifdef Q_OS_LINUX
        mainConfigNode.appendChild(createChildElement("OperatingSystem", "Linux"));
#elif Q_OS_WIN
        mainConfigNode.appendChild(createChildElement("OperatingSystem", "Windows"));
#else
        mainConfigNode.appendChild(createChildElement("OperatingSystem", "UnSupport"));
#endif
        mainConfigNode.appendChild(createChildElement("Version", "1.0.0"));
        mainConfigNode.appendChild(createChildElement("DownloadSpeed", "2000"));
        mainConfigNode.appendChild(createChildElement("UploadSpeed", "500"));
        mainConfigNode.appendChild(createChildElement("WindowsSavePath",
                                                      QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).at(0) + "/PointDownload"));
        mainConfigNode.appendChild(createChildElement("LinuxSavePath",
                                                      QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).at(0) + "/PointDownload"));
        mainConfigNode.appendChild(createChildElement("Beep", "true"));
        mainConfigNode.appendChild(createChildElement("EnableUpload", "true"));
        mainConfigNode.appendChild(createChildElement("ThreadCount", "5"));
        mainConfigNode.appendChild(createChildElement("VideoDetectType", "mov;mkv;swf;flv;mp4;avi;rmvb;rm;3gp"));
        mainConfigNode.appendChild(createChildElement("AudioDetectType", "mp3;wma;flac;ape;wav;acc"));
        mainConfigNode.appendChild(createChildElement("MaxJobCount", "10"));
        mainConfigNode.appendChild(createChildElement("clipboard", "true"));
        mainConfigNode.appendChild(createChildElement("exitOnClose", "false"));
        mainConfigNode.appendChild(createChildElement("aria2Path", ""));
        mainConfigNode.appendChild(createChildElement("yougetPath", ""));

        //添加元素节点到父节点
        domDocument.appendChild(mainConfigNode);

        //写xml文件
        QTextStream textStream(&mainConfigFile);

        domDocument.save(textStream,4);

        mainConfigFile.close();
    }
}
예제 #29
0
파일: main.cpp 프로젝트: qlands/GOBLET
void genXML(QString fileName, QSqlQuery query)
{
    QDomDocument doc;
    QDomElement root;

    doc = QDomDocument("GOBLETXML");

    root = doc.createElement("SQLResultXML");
    root.setAttribute("version", "1.0");
    doc.appendChild(root);

    QDomElement varName;
    QDomText varValue;

    QDomElement querycols;
    querycols = doc.createElement("ResultColumns");
    root.appendChild(querycols);
    int pos;
    for (pos = 0; pos <= query.record().count()-1;pos++)
    {
        varName = doc.createElement("Column");
        querycols.appendChild(varName);
        varValue = doc.createTextNode(query.record().field(pos).name());
        varName.appendChild(varValue);
    }


    QDomElement querydata;
    querydata = doc.createElement("ResultData");
    root.appendChild(querydata);

    while (query.next())
    {
        QDomElement queryRow;
        queryRow = doc.createElement("Row");
        querydata.appendChild(queryRow);
        for (pos = 0; pos <= query.record().count()-1;pos++)
        {
            varName = doc.createElement("Column");
            varName.setAttribute("name",query.record().field(pos).name());
            queryRow.appendChild(varName);
            varValue = doc.createTextNode(query.value(getFieldIndex(query,query.record().field(pos).name())).toString());
            varName.appendChild(varValue);
        }
    }

    QFile file(fileName);
    if (file.open(QIODevice::WriteOnly | QIODevice::Text))
    {
        QTextStream out(&file);
        out.setCodec("UTF-8");
        doc.save(out,1,QDomNode::EncodingFromTextStream);
        file.close();
    }

}
예제 #30
0
QString QgsMapLayer::saveSldStyle( const QString &theURI, bool &theResultFlag )
{
  QString errorMsg;
  QDomDocument myDocument;
  exportSldStyle( myDocument, errorMsg );
  if ( !errorMsg.isNull() )
  {
    theResultFlag = false;
    return errorMsg;
  }
  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this );

  // check if the uri is a file or ends with .sld,
  // which indicates that it should become one
  QString filename;
  if ( vlayer->providerType() == "ogr" )
  {
    QStringList theURIParts = theURI.split( "|" );
    filename = theURIParts[0];
  }
  else if ( vlayer->providerType() == "delimitedtext" )
  {
    filename = QUrl::fromEncoded( theURI.toAscii() ).toLocalFile();
  }
  else
  {
    filename = theURI;
  }

  QFileInfo myFileInfo( filename );
  if ( myFileInfo.exists() || filename.endsWith( ".sld", Qt::CaseInsensitive ) )
  {
    QFileInfo myDirInfo( myFileInfo.path() );  //excludes file name
    if ( !myDirInfo.isWritable() )
    {
      return tr( "The directory containing your dataset needs to be writable!" );
    }

    // now construct the file name for our .sld style file
    QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + ".sld";

    QFile myFile( myFileName );
    if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
    {
      QTextStream myFileStream( &myFile );
      // save as utf-8 with 2 spaces for indents
      myDocument.save( myFileStream, 2 );
      myFile.close();
      theResultFlag = true;
      return tr( "Created default style file as %1" ).arg( myFileName );
    }
  }

  theResultFlag = false;
  return tr( "ERROR: Failed to created SLD style file as %1. Check file permissions and retry." ).arg( filename );
}