bool TrackNode::toGPX(QXmlStreamWriter& stream, QProgressDialog * progress, QString element, bool forExport) { bool OK = true; if (isVirtual()) return OK; if (!tagValue("_waypoint_","").isEmpty() ||!sizeParents()) stream.writeStartElement("wpt"); else stream.writeStartElement(element); if (!forExport) stream.writeAttribute("xml:id", xmlId()); stream.writeAttribute("lon",COORD2STRING(BBox.topRight().x())); stream.writeAttribute("lat", COORD2STRING(BBox.topRight().y())); stream.writeTextElement("time", time().toString(Qt::ISODate)+"Z"); QString s = tagValue("name",""); if (!s.isEmpty()) { stream.writeTextElement("name", s); } if (elevation()) { stream.writeTextElement("ele", QString::number(elevation(),'f',6)); } if (speed()) { stream.writeTextElement("speed", QString::number(speed(),'f',6)); } s = tagValue("_comment_",""); if (!s.isEmpty()) { stream.writeTextElement("cmt", s); } s = tagValue("_description_",""); if (!s.isEmpty()) { stream.writeTextElement("desc", s); } // OpenStreetBug s = tagValue("_special_",""); if (!s.isEmpty() && id().type & IFeature::Special) { stream.writeStartElement("extensions"); QString sid = stripToOSMId(id()); stream.writeTextElement("id", sid); stream.writeEndElement(); } stream.writeEndElement(); if (progress) progress->setValue(progress->value()+1); return OK; }
bool Node::toXML(QXmlStreamWriter& stream, QProgressDialog * progress, bool strict, QString changesetid) { bool OK = true; if (isVirtual()) return OK; stream.writeStartElement("node"); Feature::toXML(stream, strict, changesetid); stream.writeAttribute("lon",COORD2STRING(BBox.topRight().x())); stream.writeAttribute("lat", COORD2STRING(BBox.topRight().y())); tagsToXML(stream, strict); stream.writeEndElement(); if (progress) progress->setValue(progress->value()+1); return OK; }
QString Node::toHtml() { QString D; int i; if ((i = findKey("_waypoint_")) != -1) D += "<p><b>"+QApplication::translate("MapFeature", "Waypoint")+"</b><br/>"; D += "<i>"+QApplication::translate("MapFeature", "coord")+": </i>" + COORD2STRING(position().y()) + " (" + Coord2Sexa(position().y()) + ") / " + COORD2STRING(position().x()) + " (" + Coord2Sexa(position().x()) + ")"; if ((i = findKey("_description_")) != -1) D += "<br/><i>"+QApplication::translate("MapFeature", "description")+": </i>" + tagValue(i); if ((i = findKey("_comment_")) != -1) D += "<br/><i>"+QApplication::translate("MapFeature", "comment")+": </i>" + tagValue(i); return Feature::toMainHtml(QApplication::translate("MapFeature", "Node"), "node").arg(D); }
void PropertiesDock::resetValues() { Highlighted.clear(); // Tables that might need column sizing CurrentTagView = NULL; CurrentMembersView = NULL; // to prevent slots to change the values also QList<Feature*> Current = Selection; Selection.clear(); if (FullSelection.size() == 1) { Main->info()->setHtml(FullSelection[0]->toHtml()); Node* Pt = dynamic_cast<Node*>(FullSelection[0]); Way* R = dynamic_cast<Way*>(FullSelection[0]); Relation* L = dynamic_cast<Relation*>(FullSelection[0]); if ((Pt) && (NowShowing == TrackPointUiShowing)) { TrackPointUi.Id->setText(QString::number(Pt->id().numId)); TrackPointUi.Latitude->setText(COORD2STRING(Pt->position().y())); TrackPointUi.Longitude->setText(COORD2STRING(Pt->position().x())); TrackPointUi.TagView->setModel(theModel); TrackPointUi.TagView->setItemDelegate(delegate); QWidget* w; for (int i=0; i<TrackPointUi.variableLayout->count(); ++i) { w = TrackPointUi.variableLayout->itemAt(i)->widget(); if (w) { w->hide(); w->deleteLater(); } } if (theTemplates) { w = theTemplates->getWidget(Pt, Main->view()); w->installEventFilter(shortcutFilter); TrackPointUi.variableLayout->addWidget(w); } CurrentTagView = TrackPointUi.TagView; #ifdef GEOIMAGE Main->geoImage()->setImage(Pt); #endif } else if ((R) && (NowShowing == RoadUiShowing)) { RoadUi.Id->setText(QString::number(R->id().numId)); //RoadUi.Name->setText(R->tagValue("name","")); RoadUi.TagView->setModel(theModel); RoadUi.TagView->setItemDelegate(delegate); QWidget* w; for (int i=0; i<RoadUi.variableLayout->count(); ++i) { w = RoadUi.variableLayout->itemAt(i)->widget(); if (w) { w->hide(); w->deleteLater(); } } if (theTemplates) { w = theTemplates->getWidget(R, Main->view()); w->installEventFilter(shortcutFilter); RoadUi.variableLayout->addWidget(w); } CurrentTagView = RoadUi.TagView; } else if ((L) && (NowShowing == RelationUiShowing)) { RelationUi.MembersView->setModel(L->referenceMemberModel(Main)); RelationUi.TagView->setModel(theModel); RelationUi.TagView->setItemDelegate(delegate); QWidget* w; for (int i=0; i<RelationUi.variableLayout->count(); ++i) { w = RelationUi.variableLayout->itemAt(i)->widget(); if (w) { w->hide(); w->deleteLater(); } } if (theTemplates) { w = theTemplates->getWidget(L, Main->view()); w->installEventFilter(shortcutFilter); RelationUi.variableLayout->addWidget(w); } CurrentTagView = RelationUi.TagView; CurrentMembersView = RelationUi.MembersView; } if (theTemplates) theTemplates->apply(FullSelection[0]); } else if ((FullSelection.size() > 1) && (NowShowing == MultiShowing)) { Main->info()->setHtml(""); #ifdef GEOIMAGE Main->geoImage()->setImage((Node *)NULL); #endif MultiUi.TagView->setModel(theModel); MultiUi.TagView->setItemDelegate(delegate); CurrentTagView = MultiUi.TagView; } theModel->setFeature(Current); Selection = Current; checkMenuStatus(); emit selectionChanged(); /* If we have standard TableViews in the current UI, set it so that the */ /* first column is the width of the default text (Edit this to add...) */ /* And the rest of the space is assigned to the second column */ if (CurrentTagView) { if (M_PREFS->getTagListFirstColumnWidth() > 20 && M_PREFS->getTagListFirstColumnWidth() < CurrentTagView->width()) CurrentTagView->setColumnWidth( 0, M_PREFS->getTagListFirstColumnWidth() ); else CurrentTagView->setColumnWidth( 0, CurrentTagView->fontMetrics().width(theModel->newKeyText())+10 ); CurrentTagView->horizontalHeader()->setStretchLastSection(true); CurrentTagView->installEventFilter(shortcutFilter); } if (CurrentMembersView) { CurrentMembersView->setColumnWidth( 0, CurrentMembersView->fontMetrics().width(theModel->newKeyText())+10 ); CurrentMembersView->horizontalHeader()->setStretchLastSection(true); CurrentMembersView->installEventFilter(shortcutFilter); } }
bool downloadOpenstreetbugs(MainWindow* Main, const CoordBox& aBox, Document* theDocument, SpecialLayer* theLayer) { QUrl osbUrl; osbUrl.setUrl(M_PREFS->getOpenStreetBugsUrl()); osbUrl.setPath(osbUrl.path() + "getGPX"); if (Main) Main->view()->setUpdatesEnabled(false); Downloader theDownloader("", ""); QList<TrackLayer*> theTracklayers; SpecialLayer* trackLayer = theLayer; if (!trackLayer) { SpecialLayer* trackLayer = new SpecialLayer(QApplication::translate("Downloader","OpenStreetBugs"),Layer::OsmBugsLayer); trackLayer->setUploadable(false); theDocument->add(trackLayer); } theTracklayers << trackLayer; IProgressWindow* aProgressWindow = dynamic_cast<IProgressWindow*>(Main); if (!aProgressWindow) return false; QProgressDialog* dlg = aProgressWindow->getProgressDialog(); dlg->setWindowTitle(QApplication::translate("Downloader","Parsing...")); QProgressBar* Bar = aProgressWindow->getProgressBar(); Bar->setTextVisible(false); Bar->setMaximum(11); QLabel* Lbl = aProgressWindow->getProgressLabel(); Lbl->setText(QApplication::translate("Downloader","Parsing XML")); if (dlg) dlg->show(); theDownloader.setAnimator(dlg,Lbl,Bar,true); Lbl->setText(QApplication::translate("Downloader","Downloading points")); #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) QUrlQuery theQuery(osbUrl); #define theQuery theQuery #else #define theQuery osbUrl #endif theQuery.addQueryItem("t", COORD2STRING(aBox.topRight().y())); theQuery.addQueryItem("l", COORD2STRING(aBox.bottomLeft().x())); theQuery.addQueryItem("b", COORD2STRING(aBox.bottomLeft().y())); theQuery.addQueryItem("r", COORD2STRING(aBox.topRight().x())); theQuery.addQueryItem("open", "yes"); #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) osbUrl.setQuery(theQuery); #endif #undef theQuery if (!theDownloader.go(osbUrl)) return false; if (theDownloader.resultCode() != 200) return false; QByteArray Ar(theDownloader.content()); bool OK = importGPX(Main, Ar, theDocument, theTracklayers, true); if (Main) Main->view()->setUpdatesEnabled(true); if (OK) { if (Main) Main->invalidateView(); } return OK; }
bool downloadMapdust(MainWindow* Main, const CoordBox& aBox, Document* theDocument, SpecialLayer* theLayer) { QUrl url; url.setUrl(M_PREFS->getMapdustUrl()); if (Main) Main->view()->setUpdatesEnabled(false); Downloader theDownloader("", ""); SpecialLayer* trackLayer = theLayer; if (!trackLayer) { trackLayer = new SpecialLayer(QApplication::translate("Downloader","MapDust"), Layer::MapDustLayer); trackLayer->setUploadable(false); theDocument->add(trackLayer); } IProgressWindow* aProgressWindow = dynamic_cast<IProgressWindow*>(Main); if (!aProgressWindow) return false; QProgressDialog* dlg = aProgressWindow->getProgressDialog(); dlg->setWindowTitle(QApplication::translate("Downloader","Parsing...")); QProgressBar* Bar = aProgressWindow->getProgressBar(); Bar->setTextVisible(false); Bar->setMaximum(11); QLabel* Lbl = aProgressWindow->getProgressLabel(); Lbl->setText(QApplication::translate("Downloader","Parsing XML")); if (dlg) dlg->show(); theDownloader.setAnimator(dlg,Lbl,Bar,true); Lbl->setText(QApplication::translate("Downloader","Downloading points")); #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) QUrlQuery theQuery(url); #define theQuery theQuery #else #define theQuery url #endif theQuery.addQueryItem("t", COORD2STRING(aBox.topRight().y())); theQuery.addQueryItem("l", COORD2STRING(aBox.bottomLeft().x())); theQuery.addQueryItem("b", COORD2STRING(aBox.bottomLeft().y())); theQuery.addQueryItem("r", COORD2STRING(aBox.topRight().x())); #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) url.setQuery(theQuery); #endif #undef theQuery if (!theDownloader.go(url)) return false; if (theDownloader.resultCode() != 200) return false; QByteArray Ar(theDownloader.content()); ImportExportGdal gdal(theDocument); bool OK = gdal.import(trackLayer, Ar, false); if (Main) Main->view()->setUpdatesEnabled(true); if (OK) { if (Main) Main->invalidateView(); } return OK; }
// export bool ImportExportKML::export_(const QList<Feature *>& featList) { QList<Node*> waypoints; QList<TrackSegment*> segments; QDomElement k; QDomText v; if(! IImportExport::export_(featList) ) return false; bool OK = true; QDomDocument theXmlDoc; theXmlDoc.appendChild(theXmlDoc.createProcessingInstruction("xml", "version=\"1.0\"")); QDomElement kml = theXmlDoc.createElement("kml"); theXmlDoc.appendChild(kml); kml.setAttribute("xmlns", "http://earth.google.com/kml/2.2"); QDomElement d = theXmlDoc.createElement("Document"); kml.appendChild(d); //QDomElement g = theXmlDoc.createElement("MultiGeometry"); //p.appendChild(g); for (int i=0; i<theFeatures.size(); ++i) { if (Way* R = dynamic_cast<Way*>(theFeatures[i])) { QDomElement p = theXmlDoc.createElement("Placemark"); d.appendChild(p); k = theXmlDoc.createElement("name"); p.appendChild(k); v = theXmlDoc.createTextNode(R->description()); k.appendChild(v); k = theXmlDoc.createElement("description"); p.appendChild(k); QString desc; for (int j=0; j<R->tagSize(); ++j) { desc += R->tagKey(j); desc += "="; desc += R->tagValue(j); desc += "<br/>"; } v = theXmlDoc.createTextNode(desc); k.appendChild(v); k = theXmlDoc.createElement("Style"); p.appendChild(k); QDomElement ls = theXmlDoc.createElement("LineStyle"); k.appendChild(ls); const FeaturePainter* fp = R->getCurrentPainter(); if (fp) { QDomElement color = theXmlDoc.createElement("color"); ls.appendChild(color); QRgb kcolor = fp->ForegroundColor.rgba(); v = theXmlDoc.createTextNode(QString::number(qRgba(qBlue(kcolor), qGreen(kcolor), qRed(kcolor), /*qAlpha(kcolor)*/ 192), 16)); color.appendChild(v); } QDomElement width = theXmlDoc.createElement("width"); ls.appendChild(width); v = theXmlDoc.createTextNode(QString::number(R->widthOf())); width.appendChild(v); QDomElement l = theXmlDoc.createElement("LineString"); p.appendChild(l); QDomElement c = theXmlDoc.createElement("coordinates"); l.appendChild(c); QString s; for (int j=0; j<R->size(); ++j) { Node* N = dynamic_cast<Node*>(R->get(j)); s += QString(" %1,%2").arg(COORD2STRING(N->position().x())).arg(COORD2STRING(N->position().y())); } QDomText v = theXmlDoc.createTextNode(s); c.appendChild(v); } else if (Node* N = dynamic_cast<Node*>(theFeatures[i])) { if (N->sizeParents()) continue; QDomElement p = theXmlDoc.createElement("Placemark"); d.appendChild(p); k = theXmlDoc.createElement("name"); p.appendChild(k); v = theXmlDoc.createTextNode(N->description()); k.appendChild(v); k = theXmlDoc.createElement("description"); p.appendChild(k); QString desc; for (int j=0; j<N->tagSize(); ++j) { desc += N->tagKey(j); desc += "="; desc += N->tagValue(j); desc += "<br/>"; } v = theXmlDoc.createTextNode(desc); k.appendChild(v); //k = theXmlDoc.createElement("Style"); //p.appendChild(k); //QDomElement ls = theXmlDoc.createElement("LineStyle"); //k.appendChild(ls); //FeaturePainter* fp = R->getCurrentEditPainter(); //if (fp) { // QDomElement color = theXmlDoc.createElement("color"); // ls.appendChild(color); // QRgb kcolor = fp->ForegroundColor.rgba(); // v = theXmlDoc.createTextNode(QString::number(qRgba(qBlue(kcolor), qGreen(kcolor), qRed(kcolor), /*qAlpha(kcolor)*/ 164), 16)); // color.appendChild(v); //} //QDomElement width = theXmlDoc.createElement("width"); //ls.appendChild(width); //v = theXmlDoc.createTextNode(QString::number(widthOf(R))); //width.appendChild(v); QDomElement l = theXmlDoc.createElement("Point"); p.appendChild(l); QDomElement c = theXmlDoc.createElement("coordinates"); l.appendChild(c); QString s; s += QString(" %1,%2").arg(COORD2STRING(N->position().x())).arg(COORD2STRING(N->position().y())); QDomText v = theXmlDoc.createTextNode(s); c.appendChild(v); } } Device->write(theXmlDoc.toString().toUtf8()); return OK; }