void CameraManager::save(QXmlStreamWriter& writer) { writer.writeStartElement("Camera"); // root element start writer.writeStartElement("input size"); // element1 start QXmlStreamAttributes inputSizes; inputSizes.append("width", QtUtil::toQString(_size.width)); inputSizes.append("height", QtUtil::toQString(_size.width)); writer.writeAttributes(inputSizes); writer.writeEndElement(); // element1 end writer.writeEndElement(); // root end }
void SessionWriter::addTabData(const TabData& td){ m_writer.writeStartElement("Tab"); QXmlStreamAttributes attrs; attrs.push_back(QXmlStreamAttribute("filePath", td.filePath)); attrs.push_back(QXmlStreamAttribute("cacheFilePath", td.cacheFilePath)); attrs.push_back(QXmlStreamAttribute("scrollX", QString::number(td.scrollX))); attrs.push_back(QXmlStreamAttribute("scrollY", QString::number(td.scrollY))); // A few attributes aren't often used, so we'll only write them into the file if they're // set to a non-default value as to not clutter up the xml file. if (!td.language.isEmpty()) attrs.push_back(QXmlStreamAttribute("language", td.language)); if (td.lastModified != 0) attrs.push_back(QXmlStreamAttribute("lastModified", QString::number(td.lastModified))); if (td.active) attrs.push_back(QXmlStreamAttribute("active", "1")); m_writer.writeAttributes(attrs); m_writer.writeEndElement(); }
void LapTimerThread::writeXml() { QXmlStreamReader xmlReader; coordTmpFile.open(QIODevice::ReadOnly | QIODevice::Text); xmlReader.setDevice(&coordTmpFile); xmlReader.readNext(); int lapNum=0; //Reading from the file xmlReader.readNext(); while (!xmlReader.isEndDocument()) { if (xmlReader.isStartElement()) { QString name = xmlReader.name().toString(); if (name == "lap") { lapNum++; } } else if (xmlReader.isEndElement()) { } xmlReader.readNext(); } coordTmpFile.close(); for (int i=0;i<lapNum-1;i++)// loop to generate kml file for each lap { QFile xmlKmlFile; QXmlStreamWriter bufferKml; xmlKmlFile.setFileName("data/"+dirName+"/"+dirName+"-"+QString::number(i+1)+".kml"); xmlKmlFile.open(QIODevice::WriteOnly | QIODevice::Text); bufferKml.setDevice(&xmlKmlFile); bufferKml.setAutoFormatting(true); bufferKml.writeStartDocument(); bufferKml.writeStartElement("kml"); QXmlStreamAttributes atrr; atrr.append("xmlns","http://www.opengis.net/kml/2.2"); atrr.append("xmlns:gx","http://www.google.com/kml/ext/2.2"); atrr.append("xmlns:atom","http://www.w3.org/2005/Atom"); bufferKml.writeAttributes(atrr); bufferKml.writeStartElement("Document"); bufferKml.writeTextElement("open","1"); bufferKml.writeTextElement("visibility","1"); bufferKml.writeStartElement("name"); bufferKml.writeCDATA("GPS Lap Timer - KML Log - "+QDate::currentDate().toString("yyyyMMdd")+QTime::currentTime().toString("hhmmss")); bufferKml.writeEndElement(); //style - track bufferKml.writeStartElement("Style"); bufferKml.writeAttribute(QXmlStreamAttribute("id","track")); bufferKml.writeStartElement("LineStyle"); bufferKml.writeTextElement("color","7f0000ff"); bufferKml.writeTextElement("width","4"); bufferKml.writeEndElement(); bufferKml.writeStartElement("IconStyle"); bufferKml.writeTextElement("scale","1.3"); bufferKml.writeStartElement("Icon"); bufferKml.writeTextElement("href","http://earth.google.com/images/kml-icons/track-directional/track-0.png"); bufferKml.writeEndElement(); bufferKml.writeEndElement(); bufferKml.writeEndElement(); //style - start bufferKml.writeStartElement("Style"); bufferKml.writeAttribute(QXmlStreamAttribute("id","start")); bufferKml.writeStartElement("IconStyle"); bufferKml.writeTextElement("scale","1.3"); bufferKml.writeStartElement("Icon"); bufferKml.writeTextElement("href","http://maps.google.com/mapfiles/kml/paddle/grn-circle.png"); bufferKml.writeEndElement(); bufferKml.writeEmptyElement("hotSpot"); atrr.clear(); atrr.append("x","32"); atrr.append("y","1"); atrr.append("xunits","pixels"); atrr.append("yunits","pixels"); bufferKml.writeAttributes(atrr); bufferKml.writeEndElement(); bufferKml.writeEndElement(); // style - end bufferKml.writeStartElement("Style"); bufferKml.writeAttribute(QXmlStreamAttribute("id","end")); bufferKml.writeStartElement("IconStyle"); bufferKml.writeTextElement("scale","1.3"); bufferKml.writeStartElement("Icon"); bufferKml.writeTextElement("href","http://maps.google.com/mapfiles/kml/paddle/red-circle.png"); bufferKml.writeEndElement(); bufferKml.writeEmptyElement("hotSpot"); bufferKml.writeAttributes(atrr); bufferKml.writeEndElement(); bufferKml.writeEndElement(); // style - statistics bufferKml.writeStartElement("Style"); bufferKml.writeAttribute(QXmlStreamAttribute("id","statistics")); bufferKml.writeStartElement("IconStyle"); bufferKml.writeTextElement("scale","1.3"); bufferKml.writeStartElement("Icon"); bufferKml.writeTextElement("href","http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png"); bufferKml.writeEndElement(); bufferKml.writeEmptyElement("hotSpot"); atrr.clear(); atrr.append("x","20"); atrr.append("y","2"); atrr.append("xunits","pixels"); atrr.append("yunits","pixels"); bufferKml.writeAttributes(atrr); bufferKml.writeEndElement(); bufferKml.writeEndElement(); // style - waypoint bufferKml.writeStartElement("Style"); bufferKml.writeAttribute(QXmlStreamAttribute("id","waypoint")); bufferKml.writeStartElement("IconStyle"); bufferKml.writeTextElement("scale","1.3"); bufferKml.writeStartElement("Icon"); bufferKml.writeTextElement("href","http://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png"); bufferKml.writeEndElement(); bufferKml.writeEmptyElement("hotSpot"); bufferKml.writeAttributes(atrr); bufferKml.writeEndElement(); bufferKml.writeEndElement(); QStringList xmlTmpTextBuffer; int lapTmpNum=0; bool lapNumFlag=false; bufferKml.writeStartElement("Folder"); bufferKml.writeStartElement("name"); bufferKml.writeCDATA("Lap #"+QString::number(i+1)); bufferKml.writeEndElement(); bufferKml.writeTextElement("open","1"); //waypoints - load xmlReader.clear(); wayptTmpFile.open(QIODevice::ReadOnly | QIODevice::Text); xmlReader.setDevice(&wayptTmpFile); xmlReader.readNext(); xmlTmpTextBuffer.clear(); xmlTextBuffer.clear(); lapTmpNum=0; lapNumFlag=false; QStringList bestBuffer,devBuffer,timeBuffer; while (!xmlReader.isEndDocument()) { if (xmlReader.isStartElement()) { QString name = xmlReader.name().toString(); if (name == "when" && lapNumFlag)//read time of each element { xmlTextBuffer.append(xmlReader.readElementText()); } else if (name == "waypt" && lapNumFlag) { xmlTmpTextBuffer.append(xmlReader.readElementText()); } else if (name == "best" && lapNumFlag) { bestBuffer.append(xmlReader.readElementText()); } else if (name == "time" && lapNumFlag) { timeBuffer.append(xmlReader.readElementText()); } else if (name == "dev" && lapNumFlag) { devBuffer.append(xmlReader.readElementText()); } else if (name == "lap") { lapNumFlag=(lapTmpNum==i)?true:false; lapTmpNum++; } } else if (xmlReader.isEndElement()) { } xmlReader.readNext(); } wayptTmpFile.close(); //waypoint - write for (int j=0;j<xmlTextBuffer.length();j++) { bufferKml.writeStartElement("Placemark"); bufferKml.writeStartElement("name"); if ((j+1)==xmlTextBuffer.length()) bufferKml.writeCDATA("Finish"); else bufferKml.writeCDATA("Waypoint"+QString::number(j+1)); bufferKml.writeEndElement(); bufferKml.writeStartElement("description"); bufferKml.writeCDATA("Time: "+timeBuffer.at(j)+"; To best: "+devBuffer.at(j)+"; Best: "+bestBuffer.at(j)); bufferKml.writeEndElement(); bufferKml.writeStartElement("TimeStamp"); bufferKml.writeTextElement("when",xmlTextBuffer.at(j)); bufferKml.writeEndElement(); if (j==xmlTextBuffer.length()-1) bufferKml.writeTextElement("styleUrl","#end"); else bufferKml.writeTextElement("styleUrl","#waypoint"); bufferKml.writeStartElement("Point"); bufferKml.writeTextElement("coordinates",xmlTmpTextBuffer.at(j)); bufferKml.writeEndElement(); bufferKml.writeEndElement(); } //track - load xmlReader.clear(); coordTmpFile.open(QIODevice::ReadOnly | QIODevice::Text); xmlReader.setDevice(&coordTmpFile); xmlReader.readNext(); xmlTmpTextBuffer.clear(); xmlTextBuffer.clear(); lapTmpNum=0; lapNumFlag=false; while (!xmlReader.isEndDocument()) { if (xmlReader.isStartElement()) { QString name = xmlReader.name().toString(); if (name == "when" && lapNumFlag)//read time of each element { xmlTextBuffer.append(xmlReader.readElementText()); } else if (name == "coord" && lapNumFlag) { xmlTmpTextBuffer.append(xmlReader.readElementText()); } else if (name == "lap") { lapNumFlag=(lapTmpNum==i)?true:false; lapTmpNum++; } } else if (xmlReader.isEndElement()) { } xmlReader.readNext(); } coordTmpFile.close(); //track - write bufferKml.writeStartElement("Placemark"); bufferKml.writeAttribute(QXmlStreamAttribute("id","tour")); bufferKml.writeStartElement("name"); bufferKml.writeCDATA("track"); bufferKml.writeEndElement(); bufferKml.writeStartElement("description"); bufferKml.writeCDATA(""); bufferKml.writeEndElement(); bufferKml.writeTextElement("styleUrl","#track"); bufferKml.writeStartElement("gx:MultiTrack"); bufferKml.writeTextElement("altitudeMode","absolute"); bufferKml.writeTextElement("gx:interpolate","1"); bufferKml.writeStartElement("gx:Track"); for (int j=0;j<xmlTextBuffer.length();j++) { bufferKml.writeTextElement("when",xmlTextBuffer.at(j)); bufferKml.writeTextElement("gx:coord",xmlTmpTextBuffer.at(j)); } //data - alt - write bufferKml.writeStartElement("ExtendedData"); bufferKml.writeEmptyElement("SchemaData"); bufferKml.writeAttribute(QXmlStreamAttribute("schemaUrl","#schema")); bufferKml.writeStartElement("gx:SimpleArrayData"); bufferKml.writeAttribute(QXmlStreamAttribute("name","elevation")); for (int j=0;j<xmlTextBuffer.length();j++) { bufferKml.writeTextElement("gx:value",QString(xmlTmpTextBuffer.at(j)).section(" ",2,2)); } bufferKml.writeEndElement(); //data - speed - load xmlReader.clear(); speedTmpFile.open(QIODevice::ReadOnly | QIODevice::Text); xmlReader.setDevice(&speedTmpFile); xmlReader.readNext(); xmlTmpTextBuffer.clear(); xmlTextBuffer.clear(); lapTmpNum=0; lapNumFlag=false; while (!xmlReader.isEndDocument()) { if (xmlReader.isStartElement()) { QString name = xmlReader.name().toString(); if (name == "speed" && lapNumFlag)//read time of each element { xmlTextBuffer.append(xmlReader.readElementText()); } else if (name == "lap") { lapNumFlag=(lapTmpNum==i)?true:false; lapTmpNum++; } } else if (xmlReader.isEndElement()) { } xmlReader.readNext(); } speedTmpFile.close(); //data - speed - write bufferKml.writeStartElement("gx:SimpleArrayData"); bufferKml.writeAttribute(QXmlStreamAttribute("name","speed")); for (int j=0;j<xmlTextBuffer.length();j++) { bufferKml.writeTextElement("gx:value",xmlTextBuffer.at(j)); } bufferKml.writeEndElement(); // close all opened element bufferKml.writeEndElement(); bufferKml.writeEndElement(); bufferKml.writeEndElement(); bufferKml.writeEndElement(); bufferKml.writeEndElement(); bufferKml.writeEndElement(); bufferKml.writeEndElement(); bufferKml.writeEndDocument(); xmlKmlFile.close(); } }
QString FirefoxProfileSelectPage::GetImportOpmlFile () { QString rssSql ("SELECT ann.id, ann.item_id, ann.anno_attribute_id, ann.content," "bm.title FROM moz_items_annos ann,moz_bookmarks bm WHERE ann.item_id" " IN (SELECT item_id FROM moz_items_annos WHERE anno_attribute_id = (SELECT" " id FROM moz_anno_attributes WHERE name = 'livemark/feedURI')) AND (" "ann.anno_attribute_id = 4 OR ann.anno_attribute_id = 5) AND " "bm.id = ann.item_id"); QSqlQuery rssQuery = GetQuery (rssSql); if (rssQuery.isValid ()) { QSqlQuery query (*DB_); query.exec ("SELECT id FROM moz_anno_attributes WHERE name='livemark/siteURI'"); query.next (); int site = query.value (0).toInt (); query.exec ("SELECT id FROM moz_anno_attributes WHERE name='livemark/feedURI'"); query.next (); int feed = query.value (0).toInt (); QList<QVariant> opmlData; int prevItemId = -1; QMap<QString, QVariant> omplLine; do { if (rssQuery.value (2).toInt () == site) omplLine ["SiteUrl"] = rssQuery.value (3).toString (); if (rssQuery.value (2).toInt () == feed) omplLine ["FeedUrl"] = rssQuery.value (3).toString (); if (prevItemId == rssQuery.value (1).toInt ()) opmlData.push_back (omplLine); else { prevItemId = rssQuery.value (1).toInt (); omplLine ["Title"] = rssQuery.value (4).toString (); } } while (rssQuery.next ()); QFile file ("firefox.opml"); if (file.open (QIODevice::WriteOnly)) { QXmlStreamWriter streamWriter (&file); streamWriter.setAutoFormatting (true); streamWriter.writeStartDocument (); streamWriter.writeStartElement ("opml"); streamWriter.writeAttribute ("version", "1.0"); streamWriter.writeStartElement ("head"); streamWriter.writeStartElement ("text"); streamWriter.writeEndElement (); streamWriter.writeEndElement (); streamWriter.writeStartElement ("body"); streamWriter.writeStartElement ("outline"); streamWriter.writeAttribute ("text", "Live Bookmarks"); Q_FOREACH (const QVariant& hRowVar, opmlData) { streamWriter.writeStartElement ("outline"); QMap<QString, QVariant> hRow = hRowVar.toMap (); QXmlStreamAttributes attr; attr.append ("title", hRow ["Title"].toString ()); attr.append ("htmlUrl", hRow ["SiteUrl"].toString ()); attr.append ("xmlUrl", hRow ["FeedUrl"].toString ()); attr.append ("text", hRow ["Title"].toString ()); streamWriter.writeAttributes (attr); streamWriter.writeEndElement (); }