bool writeXml(const QString &fileName, QTreeWidget *treeWidget)
{
    QFile file(fileName);
    if (!file.open(QFile::WriteOnly | QFile::Text)) {
        std::cerr << "Error: Cannot write file "
                  << qPrintable(fileName) << ": "
                  << qPrintable(file.errorString()) << std::endl;
        return false;
    }

    QXmlStreamWriter xmlWriter(&file);
    xmlWriter.setAutoFormatting(true);
    xmlWriter.writeStartDocument();
    xmlWriter.writeStartElement("bookindex");
    for (int i = 0; i < treeWidget->topLevelItemCount(); ++i)
        writeIndexEntry(&xmlWriter, treeWidget->topLevelItem(i));
    xmlWriter.writeEndDocument();

    file.close();
    if (file.error()) {
        std::cerr << "Error: Cannot write file "
                  << qPrintable(fileName) << ": "
                  << qPrintable(file.errorString()) << std::endl;
        return false;
    }
    return true;
}
void FileManager::salvaUtenti(QMap<QString, Utente*>* utenti) const
{
    QFile file(_fileNameUtenti);
    file.open(QIODevice::WriteOnly);

    QXmlStreamWriter xmlWriter(&file);
    xmlWriter.setAutoFormatting(true);
    xmlWriter.writeStartDocument();
    xmlWriter.writeStartElement("Utenti");

    QMap<QString, Utente*>::iterator it = utenti->begin();
    for(; it != utenti->end(); ++it)
    {
        xmlWriter.writeStartElement("Utente");

        xmlWriter.writeTextElement("Username", (*it)->getUsername());
        xmlWriter.writeTextElement("Password", (*it)->getPassword());        
        xmlWriter.writeTextElement("IsAdmin", (*it)->getIsAmministratore() ? "true" : "false");
        xmlWriter.writeTextElement("Nome", (*it)->getNome());
        xmlWriter.writeTextElement("Cognome", (*it)->getCognome());

        if(typeid(*(*it)) == typeid(UtenteBasic))
            xmlWriter.writeTextElement("Tipo", "1");
        else if(typeid(*(*it)) == typeid(UtenteBusiness))
            xmlWriter.writeTextElement("Tipo", "2");
        else
            xmlWriter.writeTextElement("Tipo", "3");

        xmlWriter.writeEndElement();
    }

    xmlWriter.writeEndElement();
    file.close();
}
示例#3
0
void AlarmRestData::ackAlarm(int id)
{
    QString data;
    QXmlStreamWriter xmlWriter(&data);

    /* Writes a document start with the XML version number. */
    xmlWriter.writeStartDocument();
    xmlWriter.writeStartElement("Alarms");
    xmlWriter.writeAttribute("name","PPM 300");
    xmlWriter.writeAttribute("version","PPM 300");
    xmlWriter.writeAttribute("revision","PPM 300");
    xmlWriter.writeAttribute("rest_version","PPM 300");
    xmlWriter.writeStartElement("Alarm");
    xmlWriter.writeAttribute("id",QString::number(id));
    xmlWriter.writeEndElement();
    xmlWriter.writeEndElement();
    xmlWriter.writeEndDocument();


    HttpRequest * postrequest = new HttpRequest;
    postrequest->setMethod("POST");
    postrequest->addQueryVariable("cmd","Alarms");
    postrequest->setData(data);

    qDebug() << data;
//    dispatchRequest(postrequest);

}
示例#4
0
bool GaussianBeamWindow::writeFile(const QString& fileName)
{
	QFile file(fileName);
	if (!file.open(QFile::WriteOnly | QFile::Text))
	{
		QMessageBox::warning(this, tr("Saving file"), tr("Cannot write file %1:\n%2.").arg(fileName).arg(file.errorString()));
		return false;
	}

	QXmlStreamWriter xmlWriter(&file);
	xmlWriter.setAutoFormatting(true);
	xmlWriter.writeStartDocument("1.0");
	xmlWriter.writeDTD("<!DOCTYPE gaussianBeam>");
	xmlWriter.writeStartElement("gaussianBeam");
	xmlWriter.writeAttribute("version", "1.1");
		xmlWriter.writeStartElement("bench");
		xmlWriter.writeAttribute("id", "0");
			writeBench(xmlWriter);
		xmlWriter.writeEndElement();
		xmlWriter.writeStartElement("view");
		xmlWriter.writeAttribute("id", "0");
		xmlWriter.writeAttribute("bench", "0");
			writeView(xmlWriter);
		xmlWriter.writeEndElement();
	xmlWriter.writeEndElement();
	xmlWriter.writeEndDocument();

	file.close();
	return true;
}
示例#5
0
bool XbelModel::slot_new(QFile *file_new)
{
    QXmlStreamWriter xmlWriter(file_new);
    xmlWriter.setAutoFormatting(true);
    xmlWriter.writeStartDocument();
    xmlWriter.writeStartElement("xbel");
    xmlWriter.writeAttribute(tr("version"),tr("1.0"));
    xmlWriter.writeStartElement("folder");
    xmlWriter.writeAttribute("title",tr("Эргономичность"));
    xmlWriter.writeAttribute("value_ergo","");
    xmlWriter.writeAttribute("value_ves","");
    xmlWriter.writeAttribute("value_number",QString::number(value_number));
    xmlWriter.writeAttribute("folded","1");

    xmlWriter.writeEndDocument();

    file_new->close();

    if(file_new->error())
    {
       return false;
    }

    if(!read(file_new))
    return false;

    return true;
}
示例#6
0
bool ProjectFile::Write(const QString &filename)
{
    if (!filename.isEmpty())
        mFilename = filename;

    QFile file(mFilename);
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
        return false;

    QXmlStreamWriter xmlWriter(&file);
    xmlWriter.setAutoFormatting(true);
    xmlWriter.writeStartDocument("1.0");
    xmlWriter.writeStartElement(ProjectElementName);
    xmlWriter.writeAttribute(ProjectVersionAttrib, ProjectFileVersion);

    if (!mRootPath.isEmpty())
    {
        xmlWriter.writeStartElement(RootPathName);
        xmlWriter.writeAttribute(RootPathNameAttrib, mRootPath);
        xmlWriter.writeEndElement();
    }

    if (!mIncludeDirs.isEmpty())
    {
        xmlWriter.writeStartElement(IncludDirElementName);
        QString incdir;
        foreach(incdir, mIncludeDirs)
        {
            xmlWriter.writeStartElement(DirElementName);
            xmlWriter.writeAttribute(DirNameAttrib, incdir);
            xmlWriter.writeEndElement();
        }
示例#7
0
void KoPAMasterPage::saveOdf( KoShapeSavingContext & context ) const
{
    KoPASavingContext &paContext = static_cast<KoPASavingContext&>( context );

    KoGenStyle pageLayoutStyle = pageLayout().saveOdf();
    pageLayoutStyle.setAutoStyleInStylesDotXml( true );
    pageLayoutStyle.addAttribute( "style:page-usage", "all" );
    QString pageLayoutName( paContext.mainStyles().insert( pageLayoutStyle, "pm" ) );

    KoGenStyle pageMaster( KoGenStyle::MasterPageStyle );
    pageMaster.addAttribute( "style:page-layout-name", pageLayoutName );
    pageMaster.addAttribute( "style:display-name", name() );
    pageMaster.addAttribute( "draw:style-name", saveOdfPageStyle( paContext ) );

    KoXmlWriter &savedWriter = paContext.xmlWriter();

    QBuffer buffer;
    buffer.open( QIODevice::WriteOnly );
    KoXmlWriter xmlWriter( &buffer );

    paContext.setXmlWriter( xmlWriter );

    saveOdfPageContent( paContext );

    paContext.setXmlWriter( savedWriter );

    QString contentElement = QString::fromUtf8( buffer.buffer(), buffer.buffer().size() );
    pageMaster.addChildElement( paContext.masterPageElementName(), contentElement );
    paContext.addMasterPage( this, paContext.mainStyles().insert( pageMaster, "Default" ) );
}
示例#8
0
const QString Filterkpr2odf::createMasterPageStyle(const KXmlNode & objects, const KXmlElement & masterBackground)
{
    //KXmlElement header( m_mainDoc.namedItem( "DOC" ).namedItem( "HEADER" ).toElement() );
    //KXmlElement footer( m_mainDoc.namedItem( "DOC" ).namedItem( "FOOTER" ).toElement() );

    // set that we work on master
    m_sticky = true;

    KOdfGenericStyle style(KOdfGenericStyle::MasterPageStyle, "");
    style.addAttribute("style:page-layout-name", createPageLayout());

    style.addAttribute("draw:style-name", createPageStyle(masterBackground));

    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly);
    KXmlWriter xmlWriter(&buffer);

    convertObjects(&xmlWriter, objects);

    m_sticky = false;

    QString contentElement = QString::fromUtf8(buffer.buffer(), buffer.buffer().size());
    style.addChildElement("master", contentElement);

    return m_styles.insert(style, "Default");
}
示例#9
0
bool XbelTree::slot_new(QFile *file_new)
{
//    QFile *file_ex = new QFile(file_new);
//    file_ex->~QFile();
//    file_ex->setFileName("bla bla bla");

    QXmlStreamWriter xmlWriter(file_new);
    xmlWriter.setAutoFormatting(true);
    xmlWriter.writeStartDocument();
    xmlWriter.writeStartElement("xbel");
    xmlWriter.writeAttribute(tr("version"),tr("1.0"));

    xmlWriter.writeStartElement("folder");
    xmlWriter.writeAttribute("title",tr("Эргономичность"));
    xmlWriter.writeAttribute("value_ergo","");
    xmlWriter.writeAttribute("value_ves","");
    xmlWriter.writeAttribute("value_number","");
    xmlWriter.writeAttribute("folded","");

    xmlWriter.writeEndDocument();

    file_new->close();

    if(file_new->error())
    {
       return false;
    }

    if(!read(file_new))
    return false;

    return true;
}
示例#10
0
void Fixture_Test::loadWrongID()
{
    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly | QIODevice::Text);
    QXmlStreamWriter xmlWriter(&buffer);

    xmlWriter.writeStartElement("Fixture");

    xmlWriter.writeTextElement("Channels", "9");
    xmlWriter.writeTextElement("Name", "Foobar");
    xmlWriter.writeTextElement("Universe", "0");
    xmlWriter.writeTextElement("Model", "MAC250+");
    xmlWriter.writeTextElement("Mode", "Mode 1");
    xmlWriter.writeTextElement("Manufacturer", "Martin");
    xmlWriter.writeTextElement("ID", QString::number(Fixture::invalidId()));
    xmlWriter.writeTextElement("Address", "21");

    xmlWriter.writeEndDocument();
    xmlWriter.setDevice(NULL);
    buffer.close();

    buffer.open(QIODevice::ReadOnly | QIODevice::Text);
    QXmlStreamReader xmlReader(&buffer);
    xmlReader.readNextStartElement();

    Fixture fxi(this);
    QVERIFY(fxi.loadXML(xmlReader, m_doc, m_doc->fixtureDefCache()) == false);
}
示例#11
0
void Fixture_Test::loadWrongUniverse()
{
    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly | QIODevice::Text);
    QXmlStreamWriter xmlWriter(&buffer);

    xmlWriter.writeStartElement("Fixture");

    xmlWriter.writeTextElement("Channels", "18");
    xmlWriter.writeTextElement("Name", "Foobar");
    xmlWriter.writeTextElement("Universe", "4");
    xmlWriter.writeTextElement("Model", "Foobar");
    xmlWriter.writeTextElement("Mode", "Foobar");
    xmlWriter.writeTextElement("Manufacturer", "Foobar");
    xmlWriter.writeTextElement("ID", "42");
    xmlWriter.writeTextElement("Address", "25");

    xmlWriter.writeEndDocument();
    xmlWriter.setDevice(NULL);
    buffer.close();

    buffer.open(QIODevice::ReadOnly | QIODevice::Text);
    QXmlStreamReader xmlReader(&buffer);
    xmlReader.readNextStartElement();

    Fixture fxi(this);
    QVERIFY(fxi.loadXML(xmlReader, m_doc, m_doc->fixtureDefCache()) == true);
    QVERIFY(fxi.name() == "Foobar");
    QVERIFY(fxi.channels() == 18);
    QVERIFY(fxi.address() == 25);
    QVERIFY(fxi.universe() == 4);
}
示例#12
0
bool UserMenuTree::writeXml(const QString &filename)
{
	KILE_DEBUG() << "write xml file " << filename;

	QFile file(filename);
	if ( !file.open(QFile::WriteOnly | QFile::Text) ) {
		KMessageBox::error(this, i18n("File '%1' could not be opened to save the usermenu file.", filename));
		return false;
	}

	QXmlStreamWriter xmlWriter(&file);
	xmlWriter.setAutoFormatting(true);
	xmlWriter.setAutoFormattingIndent(2) ;

	xmlWriter.writeStartDocument();
	xmlWriter.writeStartElement("UserMenu");

	for (int i = 0; i < topLevelItemCount(); ++i) {
		writeXmlItem(&xmlWriter, dynamic_cast<UserMenuItem *>(topLevelItem(i)) );
	}
	xmlWriter.writeEndDocument();

	file.close();
	return true;
}
示例#13
0
void QLCInputProfile_Test::load()
{
    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly | QIODevice::Text);
    QXmlStreamWriter xmlWriter(&buffer);

    xmlWriter.writeStartDocument();
    xmlWriter.writeDTD("<!DOCTYPE InputProfile>");
    xmlWriter.writeStartElement("InputProfile");
    xmlWriter.writeTextElement("Manufacturer", "Behringer");
    xmlWriter.writeTextElement("Model", "BCF2000");
    xmlWriter.writeStartElement("Channel");
    xmlWriter.writeAttribute("Number", "492");
    xmlWriter.writeTextElement("Name", "Foobar");
    xmlWriter.writeTextElement("Type", "Slider");
    xmlWriter.writeEndDocument();
    xmlWriter.setDevice(NULL);
    buffer.close();

    buffer.open(QIODevice::ReadOnly | QIODevice::Text);
    QXmlStreamReader xmlReader(&buffer);

    QLCInputProfile ip;
    QVERIFY(ip.loadXML(xmlReader) == true);
    QVERIFY(ip.manufacturer() == "Behringer");
    QVERIFY(ip.model() == "BCF2000");
    QVERIFY(ip.channels().size() == 1);
    QVERIFY(ip.channel(492) != NULL);
    QVERIFY(ip.channel(492)->name() == "Foobar");
    QVERIFY(ip.channel(492)->type() == QLCInputChannel::Slider);
}
示例#14
0
bool XmlStreamReader::writeXml(const QString &fileName)
{

    //std::cout << "1"<< std::endl;
    QFile file(fileName);
    if (!file.open(QFile::WriteOnly | QFile::Text)) {
        std::cerr << "Error: Cannot write file "
                  << qPrintable(fileName) << ": "
                  << qPrintable(file.errorString()) << std::endl;
        return false;
    }
    QXmlStreamWriter xmlWriter(&file);
    xmlWriter.setAutoFormatting(true);
    xmlWriter.writeStartDocument();
    xmlWriter.writeStartElement("highscore");
    for (int i = 0; i < this->persons->persons.length(); ++i){
        Person *pers = new Person();
        pers->error = this->persons->persons.at(i).error;
        pers->memberSince = this->persons->persons.at(i).memberSince;
        pers->name = this->persons->persons.at(i).name;
        pers->bestScoreTime = this->persons->persons.at(i).bestScoreTime;
        pers->runs = this->persons->persons.at(i).runs;
            writePersonEntry(&xmlWriter,pers);
    }
    xmlWriter.writeEndDocument();
    file.close();
    if (file.error()) {
        std::cerr << "Error: Cannot write file "
                  << qPrintable(fileName) << ": "
                  << qPrintable(file.errorString()) << std::endl;
        return false;
    }
    return true;
}
示例#15
0
void QLCFixtureHead_Test::load()
{
    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly | QIODevice::Text);
    QXmlStreamWriter xmlWriter(&buffer);

    xmlWriter.writeStartElement("Head");
    xmlWriter.writeTextElement("Channel", "0");
    xmlWriter.writeTextElement("Channel", "1");
    xmlWriter.writeTextElement("Channel", "15");
    xmlWriter.writeTextElement("Foo", "25");
    xmlWriter.writeTextElement("Channel", "42");
    xmlWriter.writeEndDocument();
    xmlWriter.setDevice(NULL);
    buffer.close();

    buffer.open(QIODevice::ReadOnly | QIODevice::Text);
    QXmlStreamReader xmlReader(&buffer);
    xmlReader.readNextStartElement();

    QLCFixtureHead head;
    QVERIFY(head.loadXML(xmlReader));
    QCOMPARE(head.channels().size(), 4);
    QVERIFY(head.channels().contains(0));
    QVERIFY(head.channels().contains(1));
    QVERIFY(head.channels().contains(15));
    QVERIFY(head.channels().contains(42));
}
示例#16
0
void VCProperties_Test::loadXMLSad()
{
    QBuffer buffer;
    buffer.open(QIODevice::ReadWrite | QIODevice::Text);
    QXmlStreamWriter xmlWriter(&buffer);

    xmlWriter.writeStartElement("VirtualConsole");

    xmlWriter.writeStartElement("Properties");
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("Frame");
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("Foo");
    xmlWriter.writeEndElement();

    xmlWriter.writeEndDocument();
    xmlWriter.setDevice(NULL);

    buffer.seek(0);
    QXmlStreamReader xmlReader(&buffer);
    xmlReader.readNextStartElement();

    VCProperties p;
    QVERIFY(p.loadXML(xmlReader) == false);
}
示例#17
0
void VCProperties_Test::saveXML()
{
    VCProperties p;
    p.m_size = QSize(33, 44);
    p.m_gmChannelMode = GrandMaster::AllChannels;
    p.m_gmValueMode = GrandMaster::Limit;
    p.m_gmInputUniverse = 3;
    p.m_gmInputChannel = 42;

    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly | QIODevice::Text);
    QXmlStreamWriter xmlWriter(&buffer);

    QVERIFY(p.saveXML(&xmlWriter) == true);

    xmlWriter.setDevice(NULL);
    buffer.close();

    buffer.open(QIODevice::ReadOnly | QIODevice::Text);
    QXmlStreamReader xmlReader(&buffer);
    xmlReader.readNextStartElement();

    VCProperties p2;
    QVERIFY(p2.loadXML(xmlReader) == true);
    QCOMPARE(p2.size(), QSize(33, 44));
    QCOMPARE(p2.grandMasterChannelMode(), GrandMaster::AllChannels);
    QCOMPARE(p2.grandMasterValueMode(), GrandMaster::Limit);
    QCOMPARE(p2.grandMasterInputUniverse(), quint32(3));
    QCOMPARE(p2.grandMasterInputChannel(), quint32(42));
}
void CXmlGameListWriter::writeGameList(CGameListModel* gamelist) const {
   // Save the whole game list as XML into the file defined by the constructor
   QList<CGame>::const_iterator iter = gamelist->getInternalGameList().begin();

   // Open the XML file for writing (create it if necessary)
   QFile* xmlFile = new QFile(m_Filename);
   if (xmlFile->open(QIODevice::WriteOnly) == true) {
      // Create and configure a new QXmlStreamWriter
      QXmlStreamWriter xmlWriter(xmlFile);
      xmlWriter.setAutoFormatting(true);
      xmlWriter.setAutoFormattingIndent(6);
      // serialize the whole game list into the XML stream
      xmlWriter.writeStartDocument("1.0");
      xmlWriter.writeStartElement("gamelist");
      // Loop through the whole gamelist and write each game block separately
      for (;iter != gamelist->getInternalGameList().end();++iter) {
         xmlWriter.writeStartElement("game");
         xmlWriter.writeAttribute("name", iter->getName());
         xmlWriter.writeAttribute("romfile", iter->getFilename());
         // Write the game block with specific options
         writeGameBlock(xmlWriter, *iter);
         xmlWriter.writeEndElement();
      }
      xmlWriter.writeEndElement();
      xmlWriter.writeEndDocument();
      xmlFile->close();
   }
   else {
      // Cannot open file
      return;
      // TODO: Throw exception
   }
}
示例#19
0
void VCProperties_Test::loadXMLInput()
{
    QBuffer buffer;
    buffer.open(QIODevice::ReadWrite | QIODevice::Text);
    QXmlStreamWriter xmlWriter(&buffer);

    xmlWriter.writeStartElement("Input");
    xmlWriter.writeAttribute("Universe", "3");
    xmlWriter.writeAttribute("Channel", "78");
    xmlWriter.writeEndElement();

    xmlWriter.writeEndDocument();
    xmlWriter.setDevice(NULL);

    buffer.seek(0);
    QXmlStreamReader xmlReader(&buffer);
    xmlReader.readNextStartElement();

    quint32 universe = 0;
    quint32 channel = 0;

    QVERIFY(VCProperties::loadXMLInput(xmlReader, &universe, &channel) == true);
    QCOMPARE(universe, quint32(3));
    QCOMPARE(channel, quint32(78));

    buffer.close();
    QByteArray bData = buffer.data();
    bData.replace("<Input", "<Inputt");
    buffer.setData(bData);
    buffer.open(QIODevice::ReadOnly | QIODevice::Text);
    buffer.seek(0);
    xmlReader.setDevice(&buffer);
    xmlReader.readNextStartElement();

    universe = channel = 0;

    QVERIFY(VCProperties::loadXMLInput(xmlReader, &universe, &channel) == false);
    QCOMPARE(universe, quint32(0));
    QCOMPARE(channel, quint32(0));

    QBuffer buffer2;
    buffer2.open(QIODevice::ReadWrite | QIODevice::Text);
    xmlWriter.setDevice(&buffer2);

    xmlWriter.writeStartElement("Input");
    xmlWriter.writeEndElement();

    xmlWriter.writeEndDocument();
    xmlWriter.setDevice(NULL);

    buffer2.seek(0);
    xmlReader.setDevice(&buffer2);
    xmlReader.readNextStartElement();

    universe = channel = 0;
    QVERIFY(VCProperties::loadXMLInput(xmlReader, &universe, &channel) == false);
    QCOMPARE(universe, InputOutputMap::invalidUniverse());
    QCOMPARE(channel, QLCChannel::invalid());
}
示例#20
0
bool XSPF::write(const Entries &list)
{
	Writer *writer = ioCtrl.rawPtr<Writer>();
	const QString playlistPath = getPlaylistPath(writer->getUrl());

	QByteArray buffer;
	QXmlStreamWriter xmlWriter(&buffer);
	xmlWriter.setAutoFormatting(true);
	xmlWriter.setAutoFormattingIndent(-1);

	xmlWriter.writeStartDocument();
	xmlWriter.writeStartElement("playlist");
	xmlWriter.writeStartElement("trackList");

	for (const Entry &entry : list)
	{
		xmlWriter.writeStartElement("track");

		if (entry.GID)
			startExtension(xmlWriter);

		QString url = entry.url;
		if (url.startsWith("file://") && url.mid(7, playlistPath.length()) == playlistPath)
			url.remove(0, playlistPath.length() + 7);
		xmlWriter.writeTextElement("location", url);

		if (!entry.name.isEmpty())
			xmlWriter.writeTextElement("title", entry.name);
		if (entry.length >= 0.0)
			xmlWriter.writeTextElement("duration", QString::number(1000.0 * entry.length, 'f', 0));

		if (entry.flags || entry.queue || entry.GID || entry.parent)
		{
			if (!entry.GID)
				startExtension(xmlWriter);

			if (entry.flags)
				xmlWriter.writeTextElement("f", QString::number(entry.flags));
			if (entry.queue)
				xmlWriter.writeTextElement("q", QString::number(entry.queue));
			if (entry.GID)
				xmlWriter.writeTextElement("g", QString::number(entry.GID));
			if (entry.parent)
				xmlWriter.writeTextElement("p", QString::number(entry.parent));

			xmlWriter.writeEndElement(); // extension
		}

		xmlWriter.writeEndElement(); // track
	}

	xmlWriter.writeEndElement(); // trackList
	xmlWriter.writeEndElement(); // playlist
	xmlWriter.writeEndDocument();

	writer->write(buffer);
	return true;
}
示例#21
0
	void 
	Controller::saveCameras(int nCameras){
		
		for (int i=0; i< nCameras; i++){
			std::ostringstream sTemp;
			sTemp << "camera-" << i << ".cfg";
			std::cout << sTemp.str() << std::endl;
			xmlWriter(cameras[i],sTemp.str().c_str());
		}
	}
    void SubprocessNetworkAccessManager::ClearData(const QString& callback)
    {
        QString WriteString;
        QXmlStreamWriter xmlWriter(&WriteString);
        xmlWriter.writeTextElement("ClearData","");

        Worker->SetScript(callback);
        Worker->SetFailMessage(QString("Timeout during ClearData"));
        Worker->GetWaiter()->WaitForSignal(this,SIGNAL(ClearData()), Worker,SLOT(RunSubScript()), Worker, SLOT(FailBecauseOfTimeout()));
        Worker->GetProcessComunicator()->Send(WriteString);
    }
示例#23
0
    virtual void write()
    {
        StringBuffer rowTag;
        OwnedRoxieString xmlpath(helper->getXmlIteratorPath());
        if (!xmlpath)
        {
            rowTag.append("Row");
        }
        else
        {
            const char *path = xmlpath;
            if (*path == '/') path++;
            if (strchr(path, '/')) UNIMPLEMENTED;
            rowTag.append(path);
        }

        StringBuffer xmlOutput;
        CommonXmlWriter xmlWriter(helper->getXmlFlags());
        if (!dlfn.isExternal() || firstNode()) // if external, 1 header,footer
        {
            OwnedRoxieString header(helper->getHeader());
            if (header)
                xmlOutput.clear().append(header);
            else
                xmlOutput.clear().append("<Dataset>").newline();
            outraw->write(xmlOutput.length(), xmlOutput.toCharArray());
            if (calcFileCrc)
                fileCRC.tally(xmlOutput.length(), xmlOutput.toCharArray());
        }
        while(!abortSoon)
        {
            OwnedConstThorRow row = input->ungroupedNextRow();
            if (!row)
                break;
            xmlWriter.clear().outputBeginNested(rowTag, false);
            helper->toXML((const byte *)row.get(), xmlWriter);
            xmlWriter.outputEndNested(rowTag);
            outraw->write(xmlWriter.length(), xmlWriter.str());
            if (calcFileCrc)
                fileCRC.tally(xmlWriter.length(), xmlWriter.str());
            processed++;
        }
        if (!dlfn.isExternal() || lastNode()) // if external, 1 header,footer
        {
            OwnedRoxieString footer(helper->getFooter());
            if (footer)
                xmlOutput.clear().append(footer);
            else
                xmlOutput.clear().append("</Dataset>").newline();
            outraw->write(xmlOutput.length(), xmlOutput.toCharArray());
            if (calcFileCrc)
                fileCRC.tally(xmlOutput.length(), xmlOutput.toCharArray());
        }
    }
    void SubprocessNetworkAccessManager::IsUrlLoadedByMask(const QString& Mask, const QString& callback)
    {
        QString WriteString;
        QXmlStreamWriter xmlWriter(&WriteString);
        xmlWriter.writeTextElement("IsUrlLoadedByMask",Mask);

        Worker->SetScript(callback);
        Worker->SetFailMessage(QString("Timeout during IsUrlLoadedByMask"));
        Worker->GetWaiter()->WaitForSignal(this,SIGNAL(IsUrlLoadedByMask()), Worker,SLOT(RunSubScript()), Worker, SLOT(FailBecauseOfTimeout()));
        Worker->GetProcessComunicator()->Send(WriteString);
    }
示例#25
0
void Doc_Test::load()
{
    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly | QIODevice::Text);
    QXmlStreamWriter xmlWriter(&buffer);

    xmlWriter.writeStartElement("Engine");

    createFixtureNode(xmlWriter, 0, m_currentAddr, 18);
    m_currentAddr += 18;
    createFixtureNode(xmlWriter, 72, m_currentAddr, 18);
    m_currentAddr += 18;
    createFixtureNode(xmlWriter, 15, m_currentAddr, 18);
    m_currentAddr += 18;

    createFixtureGroupNode(xmlWriter, 0);
    createFixtureGroupNode(xmlWriter, 42);
    createFixtureGroupNode(xmlWriter, 72);

    createCollectionNode(xmlWriter, 5);
    createCollectionNode(xmlWriter, 9);
    createCollectionNode(xmlWriter, 1);
    createCollectionNode(xmlWriter, 7);

    createBusNode(xmlWriter, 0, 1);
    createBusNode(xmlWriter, 7, 2);
    createBusNode(xmlWriter, 12, 3);
    createBusNode(xmlWriter, 29, 4);
    createBusNode(xmlWriter, 31, 500);

    xmlWriter.writeStartElement("ExtraTag");
    xmlWriter.writeEndElement();

    xmlWriter.writeEndDocument();
    xmlWriter.setDevice(NULL);
    buffer.close();

    buffer.open(QIODevice::ReadOnly | QIODevice::Text);
    QXmlStreamReader xmlReader(&buffer);
    xmlReader.readNextStartElement();

    QVERIFY(m_doc->fixtures().size() == 0);
    QVERIFY(m_doc->functions().size() == 0);
    QVERIFY(m_doc->loadXML(xmlReader) == true);
    QVERIFY(m_doc->fixtures().size() == 3);
    QVERIFY(m_doc->functions().size() == 4);
    QVERIFY(m_doc->fixtureGroups().size() == 3);
    QVERIFY(Bus::instance()->value(0) == 1);
    QVERIFY(Bus::instance()->value(7) == 2);
    QVERIFY(Bus::instance()->value(12) == 3);
    QVERIFY(Bus::instance()->value(29) == 4);
    QVERIFY(Bus::instance()->value(31) == 500);
}
void UBMetadataDcSubsetAdaptor::persist(UBDocumentProxy* proxy)
{
    if(!QDir(proxy->persistencePath()).exists()){
        //In this case the a document is an empty document so we do not persist it
        return;
    }
    QString fileName = proxy->persistencePath() + "/" + metadataFilename;
    qWarning() << "Persisting document; path is" << fileName;
    QFile file(fileName);
    if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
    {
        qCritical() << "cannot open " << fileName << " for writing ...";
        qCritical() << "error : "  << file.errorString();
        return;
    }

    QXmlStreamWriter xmlWriter(&file);
    xmlWriter.setAutoFormatting(true);

    xmlWriter.writeStartDocument();
    xmlWriter.writeDefaultNamespace(nsRdf);
    xmlWriter.writeNamespace(nsDc, "dc");
    xmlWriter.writeNamespace(UBSettings::uniboardDocumentNamespaceUri, "ub");

    xmlWriter.writeStartElement("RDF");

    xmlWriter.writeStartElement("Description");
    xmlWriter.writeAttribute("about", proxy->metaData(UBSettings::documentIdentifer).toString());

    xmlWriter.writeTextElement(nsDc, "title", proxy->metaData(UBSettings::documentName).toString());
    xmlWriter.writeTextElement(nsDc, "type", proxy->metaData(UBSettings::documentGroupName).toString());
    xmlWriter.writeTextElement(nsDc, "date", proxy->metaData(UBSettings::documentDate).toString());
    xmlWriter.writeTextElement(nsDc, "format", "image/svg+xml");

    // introduced in UB 4.2
    xmlWriter.writeTextElement(nsDc, "identifier", proxy->metaData(UBSettings::documentIdentifer).toString());
    xmlWriter.writeTextElement(UBSettings::uniboardDocumentNamespaceUri, "version", UBSettings::currentFileVersion);
    QString width = QString::number(proxy->defaultDocumentSize().width());
    QString height = QString::number(proxy->defaultDocumentSize().height());
    xmlWriter.writeTextElement(UBSettings::uniboardDocumentNamespaceUri, "size", QString("%1x%2").arg(width).arg(height));

    // introduced in UB 4.4
    xmlWriter.writeTextElement(UBSettings::uniboardDocumentNamespaceUri, "updated-at", UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTimeUtc()));

    xmlWriter.writeEndElement(); //dc:Description
    xmlWriter.writeEndElement(); //RDF

    xmlWriter.writeEndDocument();

    file.flush();
    file.close();
}
示例#27
0
void QmitkPythonSnippets::SaveStringMap(const QString &filename, const QmitkPythonSnippets::QStringMap &) const
{
  MITK_DEBUG("QmitkPythonSnippets") << "saving to xml file " << filename.toStdString();

  if( filename.isEmpty() )
  {
    MITK_WARN("QmitkPythonSnippets") << "empty auto save file path given. quit.";
    return;
  }

  QFile file(filename);
  file.open(QIODevice::WriteOnly);
  if( !file.isOpen() )
  {
    MITK_WARN("QmitkPythonSnippets") << "could not open file " << filename.toStdString() << " for writing";
    return;
  }
  QXmlStreamWriter xmlWriter(&file);

  xmlWriter.setAutoFormatting(true);
  xmlWriter.writeStartDocument();
  xmlWriter.writeStartElement(SNIPPETS_ROOT_XML_ELEMENT_NAME);

  QStringMap::const_iterator it = d->m_Snippets.begin();
  while( it != d->m_Snippets.end() )
  {

    {
      MITK_DEBUG("QmitkPythonSnippets") << "SNIPPETS_XML_ELEMENT_NAME " << SNIPPETS_XML_ELEMENT_NAME.toStdString();
      MITK_DEBUG("QmitkPythonSnippets") << "writing item " << it.key().toStdString();
    }

    xmlWriter.writeStartElement(SNIPPETS_XML_ELEMENT_NAME);

    xmlWriter.writeAttribute( "key", it.key() );
    xmlWriter.writeAttribute( "value", it.value() );

    xmlWriter.writeEndElement();

    ++it;
  }

  xmlWriter.writeEndDocument();
  if( file.isOpen() )
    file.close();

  {
    MITK_DEBUG("QmitkPythonSnippets") << "SaveStringMap successful ";
  }

}
示例#28
0
void QLCInputProfile_Test::loadNoProfile()
{
    QXmlStreamReader doc;
    QLCInputProfile ip;
    QVERIFY(ip.loadXML(doc) == false);

    QBuffer buffer;
    buffer.open(QIODevice::ReadWrite);
    QXmlStreamWriter xmlWriter(&buffer);
    xmlWriter.writeStartElement("Whatever");

    doc.setDevice(&buffer);
    QVERIFY(ip.loadXML(doc) == false);
}
示例#29
0
void ToDoListModel::writeXML(QString fileName) {

    QFile file(fileName);
    file.open(QIODevice::WriteOnly);

    QXmlStreamWriter xmlWriter(&file);
    xmlWriter.setAutoFormatting(true);
    xmlWriter.writeStartDocument();
    xmlWriter.writeStartElement("Spice");

    ToDoItem item;
    foreach(item, m_items) {
        item.writeXML(xmlWriter);
    }
示例#30
0
void TreeModel::writeXml(const QString &fileName)
{
    QFile file(fileName);
    if (file.open(QIODevice::WriteOnly | QIODevice::Text))
    {
        QXmlStreamWriter xmlWriter(&file);
        xmlWriter.setAutoFormatting(true);
        xmlWriter.writeStartDocument();

        recursiveWrite(xmlWriter, rootItem);

        xmlWriter.writeEndDocument();
        file.close();
    }
}