void CRouteContainer::dumpGPX( QXmlStreamWriter & _rqXmlStreamWriter, bool bOnlySelected ) const { // GPX format reference: see http://www.topografix.com/GPX/1/1/ // Data _rqXmlStreamWriter.writeStartElement( "rte" ); // ... name if( !qsName.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "name" ); _rqXmlStreamWriter.writeCharacters( qsName ); _rqXmlStreamWriter.writeEndElement(); // name } // ... type if( !qsType.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "type" ); _rqXmlStreamWriter.writeCharacters( qsType ); _rqXmlStreamWriter.writeEndElement(); // type } // ... description if( !qsDescription.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "desc" ); _rqXmlStreamWriter.writeCDATA( qsDescription ); _rqXmlStreamWriter.writeEndElement(); // desc } // ... comment if( !qsComment.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "cmt" ); _rqXmlStreamWriter.writeCDATA( qsComment ); _rqXmlStreamWriter.writeEndElement(); // cmt } // ... url if( !qsUrl.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "link" ); _rqXmlStreamWriter.writeAttribute( "href", qsUrl ); _rqXmlStreamWriter.writeEndElement(); // link } // ... points int __iCount = QTreeWidgetItem::childCount(); for( int __i = 0; __i < __iCount; __i++ ) { CRoutePoint* __poRoutePoint = (CRoutePoint*)QTreeWidgetItem::child( __i ); if( bOnlySelected && !__poRoutePoint->isMultiSelected() ) continue; __poRoutePoint->dumpGPX( _rqXmlStreamWriter ); } // ... [end] _rqXmlStreamWriter.writeEndElement(); // rte }
void CVesselContainer::dumpQVCT( QXmlStreamWriter & _rqXmlStreamWriter, bool bOnlySelected ) const { // Data _rqXmlStreamWriter.writeStartElement( "Flotilla" ); // ... name if( !qsName.isEmpty() ) _rqXmlStreamWriter.writeAttribute( "name", qsName ); // ... visibility _rqXmlStreamWriter.writeAttribute( "visibility", QString::number( COverlayVisibility::getVisibility() ) ); // ... type if( !qsType.isEmpty() ) _rqXmlStreamWriter.writeAttribute( "type", qsType ); // ... url if( !qsUrl.isEmpty() ) _rqXmlStreamWriter.writeAttribute( "url", qsUrl ); // ... description if( !qsDescription.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "Description" ); _rqXmlStreamWriter.writeCDATA( qsDescription ); _rqXmlStreamWriter.writeEndElement(); // Description } // ... comment if( !qsComment.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "Comment" ); _rqXmlStreamWriter.writeCDATA( qsComment ); _rqXmlStreamWriter.writeEndElement(); // Comment } // ... points if( !bDynamic ) { int __iCount = QTreeWidgetItem::childCount(); for( int __i = 0; __i < __iCount; __i++ ) { CVesselPoint* __poVesselPoint = (CVesselPoint*)QTreeWidgetItem::child( __i ); if( bOnlySelected && !__poVesselPoint->isMultiSelected() ) continue; __poVesselPoint->dumpQVCT( _rqXmlStreamWriter ); } } else { CVesselContainerDevice* __poVesselContainerDevice = (CVesselContainerDevice*)QTreeWidgetItem::child( 0 ); __poVesselContainerDevice->dumpQVCT( _rqXmlStreamWriter ); } // ... [end] _rqXmlStreamWriter.writeEndElement(); // Flotilla }
void CLandmarkPoint::dumpQVCT( QXmlStreamWriter & _rqXmlStreamWriter ) const { // Data _rqXmlStreamWriter.writeStartElement( "Point" ); // ... name if( !qsName.isEmpty() ) _rqXmlStreamWriter.writeAttribute( "name", qsName ); // ... visibility _rqXmlStreamWriter.writeAttribute( "visibility", QString::number( COverlayVisibility::getVisibility() ) ); // ... position _rqXmlStreamWriter.writeAttribute( "longitude", QString::number( CDataPosition::getLongitude() ) ); _rqXmlStreamWriter.writeAttribute( "latitude", QString::number( CDataPosition::getLatitude() ) ); // ... elevation if( CDataPosition::getElevation() != CDataPosition::UNDEFINED_ELEVATION ) _rqXmlStreamWriter.writeAttribute( "elevation", QString::number( CDataPosition::getElevation() ) ); // ... type if( !qsType.isEmpty() ) _rqXmlStreamWriter.writeAttribute( "type", qsType ); // ... symbol if( !qsSymbol.isEmpty() ) _rqXmlStreamWriter.writeAttribute( "symbol", qsSymbol ); // ... url if( !qsUrl.isEmpty() ) _rqXmlStreamWriter.writeAttribute( "url", qsUrl ); // ... description if( !qsDescription.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "Description" ); _rqXmlStreamWriter.writeCDATA( qsDescription ); _rqXmlStreamWriter.writeEndElement(); // Description } // ... comment if( !qsComment.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "Comment" ); _rqXmlStreamWriter.writeCDATA( qsComment ); _rqXmlStreamWriter.writeEndElement(); // Comment } // ... [end] _rqXmlStreamWriter.writeEndElement(); // Point }
bool Deck::exportToXml(QString fileName) { QXmlStreamWriter xml; QFile file(fileName); file.open(QIODevice::WriteOnly | QIODevice::Text); if(!file.isOpen()) return false; xml.setAutoFormatting(true); xml.setCodec("UTF-8"); xml.setDevice(&file); xml.writeStartDocument(); /// --<dana> xml.writeStartElement(XML_TAG_ROOT); xml.writeStartElement(XML_TAG_VERSION); xml.writeCharacters(appVersionToString()); xml.writeEndElement(); /// --<deck> xml.writeStartElement(XML_TAG_DECK); xml.writeStartElement(XML_TAG_NAME); xml.writeCharacters(name); xml.writeEndElement(); xml.writeStartElement(XML_TAG_DESC); xml.writeCharacters(desc); xml.writeEndElement(); xml.writeStartElement(XML_TAG_ICON); xml.writeCharacters("icon.png"); xml.writeEndElement(); xml.writeStartElement(XML_TAG_GUID); xml.writeCharacters(guid.toString()); xml.writeEndElement(); xml.writeStartElement(XML_TAG_CREATED); xml.writeCharacters(createdTime.toString()); xml.writeEndElement(); xml.writeStartElement(XML_TAG_UPDATED); xml.writeCharacters(updatedTime.toString()); xml.writeEndElement(); xml.writeStartElement(XML_TAG_AUTHOR); xml.writeCharacters(author); xml.writeEndElement(); xml.writeStartElement(XML_TAG_TAGS); xml.writeCharacters(tags); xml.writeEndElement(); xml.writeStartElement(XML_TAG_FLAGS); xml.writeCharacters(QString::number(flags)); xml.writeEndElement(); xml.writeStartElement(XML_TAG_INHAND); xml.writeCharacters(QString::number(inhand)); xml.writeEndElement(); xml.writeDTD(format.toString()); xml.writeEndElement(); /// --</deck> /// --<cards> xml.writeStartElement(XML_TAG_CARDS); Card *card = 0; int count = cards.count(); for(int index = 0; index < count; index++) { card = cards.at(index); xml.writeStartElement(XML_TAG_CARD); // --------------------------------- xml.writeStartElement(XML_TAG_FRONT); xml.writeCDATA(card->getFront()); xml.writeEndElement(); xml.writeStartElement(XML_TAG_BACK); xml.writeCDATA(card->getBack()); xml.writeEndElement(); xml.writeStartElement(XML_TAG_FLAGS); xml.writeCDATA(QString::number(card->getFlags())); xml.writeEndElement(); /* xml.writeStartElement("level"); xml.writeDTD(QString::number(card->getLevel())); xml.writeEndElement(); */ // --------------------------------- xml.writeEndElement(); } xml.writeEndElement(); /// --</cards> xml.writeEndDocument(); /// --</dana> file.close(); return true; }
void CLandmarkPoint::dumpGPX( QXmlStreamWriter & _rqXmlStreamWriter ) const { // GPX format reference: see http://www.topografix.com/GPX/1/1/ // Data _rqXmlStreamWriter.writeStartElement( "wpt" ); // ... position _rqXmlStreamWriter.writeAttribute( "lon", QString::number( CDataPosition::getLongitude() ) ); _rqXmlStreamWriter.writeAttribute( "lat", QString::number( CDataPosition::getLatitude() ) ); // ... name if( !qsName.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "name" ); _rqXmlStreamWriter.writeCharacters( qsName ); _rqXmlStreamWriter.writeEndElement(); // name } // ... elevation if( CDataPosition::getElevation() != CDataPosition::UNDEFINED_ELEVATION ) { _rqXmlStreamWriter.writeStartElement( "ele" ); _rqXmlStreamWriter.writeCharacters( QString::number( CDataPosition::getElevation() ) ); _rqXmlStreamWriter.writeEndElement(); // ele } // ... type if( !qsType.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "type" ); _rqXmlStreamWriter.writeCharacters( qsType ); _rqXmlStreamWriter.writeEndElement(); // type } // ... description if( !qsDescription.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "desc" ); _rqXmlStreamWriter.writeCDATA( qsDescription ); _rqXmlStreamWriter.writeEndElement(); // desc } // ... comment if( !qsComment.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "cmt" ); _rqXmlStreamWriter.writeCDATA( qsComment ); _rqXmlStreamWriter.writeEndElement(); // cmt } // ... symbol if( !qsSymbol.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "sym" ); _rqXmlStreamWriter.writeCharacters( qsSymbol ); _rqXmlStreamWriter.writeEndElement(); // sym } // ... url if( !qsUrl.isEmpty() ) { _rqXmlStreamWriter.writeStartElement( "link" ); _rqXmlStreamWriter.writeAttribute( "href", qsUrl ); _rqXmlStreamWriter.writeEndElement(); // link } // ... [end] _rqXmlStreamWriter.writeEndElement(); // wpt }
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(); } }