summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Beschow <bbeschow@cs.tu-berlin.de>2016-08-14 10:52:39 (GMT)
committerBernhard Beschow <bbeschow@cs.tu-berlin.de>2016-08-14 11:14:06 (GMT)
commit815379faeb5fd788ea41f60e605d08c48cf3b4a4 (patch)
tree889774bcdfd59a9f290b723303ca352f0c34066f
parent2c8f7e90ef215b85fdd70f868419a69cc5c14cc7 (diff)
use OsmTag rather than plain QString (which needed to be in a certain format)
-rw-r--r--src/lib/marble/EditPlacemarkDialog.cpp4
-rw-r--r--src/lib/marble/StyleBuilder.cpp4
-rw-r--r--src/lib/marble/osm/OsmPresetLibrary.cpp18
-rw-r--r--src/lib/marble/osm/OsmPresetLibrary.h2
-rw-r--r--src/lib/marble/osm/OsmTagEditorWidget.cpp17
-rw-r--r--src/lib/marble/osm/OsmTagEditorWidget.h6
-rw-r--r--src/plugins/render/annotate/EditPolygonDialog.cpp4
-rw-r--r--src/plugins/render/annotate/EditPolylineDialog.cpp4
-rw-r--r--src/plugins/runner/json/JsonParser.cpp3
-rw-r--r--src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.cpp3
10 files changed, 33 insertions, 32 deletions
diff --git a/src/lib/marble/EditPlacemarkDialog.cpp b/src/lib/marble/EditPlacemarkDialog.cpp
index b641836..b9c0478 100644
--- a/src/lib/marble/EditPlacemarkDialog.cpp
+++ b/src/lib/marble/EditPlacemarkDialog.cpp
@@ -340,8 +340,8 @@ void EditPlacemarkDialog::updateTextAnnotation()
d->m_placemark->setStyle( newStyle );
}
else {
- QString suitableTag = d->m_osmTagEditorWidget->suitableTag();
- if ( !suitableTag.isEmpty() ) {
+ const OsmTagEditorWidget::OsmTag suitableTag = d->m_osmTagEditorWidget->suitableTag();
+ if (suitableTag != OsmTagEditorWidget::OsmTag()) {
GeoDataFeature::GeoDataVisualCategory category = OsmPresetLibrary::osmVisualCategory( suitableTag );
d->m_placemark->setVisualCategory( category );
d->m_placemark->setStyle(GeoDataStyle::Ptr());
diff --git a/src/lib/marble/StyleBuilder.cpp b/src/lib/marble/StyleBuilder.cpp
index adf12c5..99dfac4 100644
--- a/src/lib/marble/StyleBuilder.cpp
+++ b/src/lib/marble/StyleBuilder.cpp
@@ -962,8 +962,8 @@ GeoDataStyle::ConstPtr StyleBuilder::createStyle(const StyleParameters &paramete
if (style->iconStyle().iconPath().isEmpty()) {
for (auto iter = osmData.tagsBegin(), end = osmData.tagsEnd(); iter != end; ++iter) {
- const QString keyValue = QString("%1=%2").arg(iter.key()).arg(iter.value());
- const GeoDataFeature::GeoDataVisualCategory category = OsmPresetLibrary::osmVisualCategory(keyValue);
+ const auto tag = OsmPresetLibrary::OsmTag(iter.key(), iter.value());
+ const GeoDataFeature::GeoDataVisualCategory category = OsmPresetLibrary::osmVisualCategory(tag);
const GeoDataStyle::ConstPtr categoryStyle = presetStyle(category);
if (category != GeoDataFeature::None && !categoryStyle->iconStyle().icon().isNull()) {
GeoDataStyle::Ptr newStyle(new GeoDataStyle(*style));
diff --git a/src/lib/marble/osm/OsmPresetLibrary.cpp b/src/lib/marble/osm/OsmPresetLibrary.cpp
index eb4858b..7856268 100644
--- a/src/lib/marble/osm/OsmPresetLibrary.cpp
+++ b/src/lib/marble/osm/OsmPresetLibrary.cpp
@@ -479,7 +479,7 @@ GeoDataStyle::ConstPtr OsmPresetLibrary::presetStyle( const OsmTag &tag )
{
static const StyleBuilder styleBuilder;
- const GeoDataFeature::GeoDataVisualCategory category = osmVisualCategory(tag.first + '=' + tag.second);
+ const GeoDataFeature::GeoDataVisualCategory category = osmVisualCategory(tag);
return styleBuilder.presetStyle(category);
}
@@ -490,19 +490,11 @@ bool OsmPresetLibrary::hasVisualCategory ( const OsmTag &tag )
return s_visualCategories.contains( tag );
}
-GeoDataFeature::GeoDataVisualCategory OsmPresetLibrary::osmVisualCategory( const QString &keyValue )
+GeoDataFeature::GeoDataVisualCategory OsmPresetLibrary::osmVisualCategory(const OsmTag &tag)
{
initializeOsmVisualCategories();
- QStringList tokens = keyValue.split( '=' );
- if ( tokens.size() != 2 ) {
- return GeoDataFeature::None;
- }
-
- QString key = tokens.at( 0 );
- QString value = tokens.at( 1 );
-
- return s_visualCategories.value( OsmTag( key, value ) );
+ return s_visualCategories.value(tag, GeoDataFeature::None);
}
QMap<OsmPresetLibrary::OsmTag, GeoDataFeature::GeoDataVisualCategory>::const_iterator OsmPresetLibrary::begin()
@@ -581,8 +573,8 @@ GeoDataFeature::GeoDataVisualCategory OsmPresetLibrary::determineVisualCategory(
}
for (auto iter = osmData.tagsBegin(), end=osmData.tagsEnd(); iter != end; ++iter) {
- QString const keyValue = QString("%1=%2").arg(iter.key()).arg(iter.value());
- GeoDataFeature::GeoDataVisualCategory category = osmVisualCategory(keyValue);
+ const auto tag = OsmPresetLibrary::OsmTag(iter.key(), iter.value());
+ GeoDataFeature::GeoDataVisualCategory category = osmVisualCategory(tag);
if (category != GeoDataFeature::None) {
return category;
}
diff --git a/src/lib/marble/osm/OsmPresetLibrary.h b/src/lib/marble/osm/OsmPresetLibrary.h
index 881d9eb..48c0fc4 100644
--- a/src/lib/marble/osm/OsmPresetLibrary.h
+++ b/src/lib/marble/osm/OsmPresetLibrary.h
@@ -40,7 +40,7 @@ public:
/**
* @brief Convenience categorization of placemarks for Osm key=value pairs
*/
- static GeoDataFeature::GeoDataVisualCategory osmVisualCategory(const QString &keyValue );
+ static GeoDataFeature::GeoDataVisualCategory osmVisualCategory(const OsmTag &tag);
/**
* @brief hasVisualCategory returns true if there is a visual category associated with
diff --git a/src/lib/marble/osm/OsmTagEditorWidget.cpp b/src/lib/marble/osm/OsmTagEditorWidget.cpp
index 8c319fe..a4af9d4 100644
--- a/src/lib/marble/osm/OsmTagEditorWidget.cpp
+++ b/src/lib/marble/osm/OsmTagEditorWidget.cpp
@@ -63,28 +63,31 @@ OsmTagEditorWidget::~OsmTagEditorWidget()
void OsmTagEditorWidget::update()
-{ d->m_currentTagsList->clear();
+{
+ d->m_currentTagsList->clear();
d->m_recommendedTagsList->clear();
d->populatePresetTagsList();
d->populateCurrentTagsList();
+
emit placemarkChanged( d->m_placemark );
}
-QString OsmTagEditorWidget::suitableTag()
+OsmTagEditorWidget::OsmTag OsmTagEditorWidget::suitableTag() const
{
- /* The most suitable tag is the first tag in the list for which the OsmPresetLibrary
+ /*
+ * The most suitable tag is the first tag in the list for which the OsmPresetLibrary
* has an assigned visual category ( a QMap entry )
* Maybe there's a better option.
*/
- for ( int index = 0; index < d->m_currentTagsList->topLevelItemCount(); ++index ) {
+ for (int index = 0; index < d->m_currentTagsList->topLevelItemCount(); ++index) {
const QTreeWidgetItem *item = d->m_currentTagsList->topLevelItem( index );
- OsmTagEditorWidgetPrivate::OsmTag tag( item->text( 0 ), item->text( 1 ) );
+ const auto tag = OsmTag(item->text(0), item->text(1));
if ( OsmPresetLibrary::hasVisualCategory( tag ) ) {
- return tag.first + '=' + tag.second;
+ return tag;
}
}
- return QString();
+ return OsmTag();
}
void OsmTagEditorWidget::addSelectedTag()
diff --git a/src/lib/marble/osm/OsmTagEditorWidget.h b/src/lib/marble/osm/OsmTagEditorWidget.h
index d8d27b7..5136600 100644
--- a/src/lib/marble/osm/OsmTagEditorWidget.h
+++ b/src/lib/marble/osm/OsmTagEditorWidget.h
@@ -16,6 +16,8 @@
#include "MarbleGlobal.h"
#include "marble_export.h"
+#include <QPair>
+
class QTreeWidgetItem;
namespace Marble
@@ -30,6 +32,8 @@ class MARBLE_EXPORT OsmTagEditorWidget : public QWidget
Q_OBJECT
public:
+ typedef QPair<QString, QString> OsmTag;
+
explicit OsmTagEditorWidget( GeoDataPlacemark *placemark, QWidget *parent = 0 );
~OsmTagEditorWidget();
@@ -44,7 +48,7 @@ public Q_SLOTS:
* @brief suitableTag returns the tag that fits best to represent the Visual Category
* of the placemark ( chosen from the current list of tags )
*/
- QString suitableTag();
+ OsmTag suitableTag() const;
Q_SIGNALS:
void placemarkChanged( GeoDataFeature *);
diff --git a/src/plugins/render/annotate/EditPolygonDialog.cpp b/src/plugins/render/annotate/EditPolygonDialog.cpp
index 6c0a4e6..b7adc5d 100644
--- a/src/plugins/render/annotate/EditPolygonDialog.cpp
+++ b/src/plugins/render/annotate/EditPolygonDialog.cpp
@@ -255,8 +255,8 @@ void EditPolygonDialog::updatePolygon()
// If there is not custom style initialized( default #polyline url is used ) and there is a osmTag-based style
// available, set it
- QString suitableTag = d->m_osmTagEditorWidget->suitableTag();
- if ( d->m_placemark->styleUrl() == "#polygon" && !suitableTag.isEmpty() ) {
+ const OsmTagEditorWidget::OsmTag suitableTag = d->m_osmTagEditorWidget->suitableTag();
+ if (d->m_placemark->styleUrl() == "#polygon" && suitableTag != OsmTagEditorWidget::OsmTag()) {
GeoDataFeature::GeoDataVisualCategory category = OsmPresetLibrary::osmVisualCategory( suitableTag );
d->m_placemark->setStyle( GeoDataStyle::Ptr() ); // first clear style so style gets set by setVisualCategory()
d->m_placemark->setVisualCategory( category );
diff --git a/src/plugins/render/annotate/EditPolylineDialog.cpp b/src/plugins/render/annotate/EditPolylineDialog.cpp
index efaaf9f..d38f484 100644
--- a/src/plugins/render/annotate/EditPolylineDialog.cpp
+++ b/src/plugins/render/annotate/EditPolylineDialog.cpp
@@ -219,8 +219,8 @@ void EditPolylineDialog::updatePolyline()
// If there is no custom style initialized( default #polyline url is used ) and there is a osmTag-based style
// available, set it
- QString suitableTag = d->m_osmTagEditorWidget->suitableTag();
- if ( d->m_placemark->styleUrl() == "#polyline" && !suitableTag.isEmpty() ) {
+ const OsmTagEditorWidget::OsmTag suitableTag = d->m_osmTagEditorWidget->suitableTag();
+ if (d->m_placemark->styleUrl() == "#polyline" && suitableTag != OsmTagEditorWidget::OsmTag()) {
GeoDataFeature::GeoDataVisualCategory category = OsmPresetLibrary::osmVisualCategory( suitableTag );
d->m_placemark->setStyle( GeoDataStyle::Ptr() ); // first clear style so style gets set by setVisualCategory()
d->m_placemark->setVisualCategory( category );
diff --git a/src/plugins/runner/json/JsonParser.cpp b/src/plugins/runner/json/JsonParser.cpp
index d0d50fa..54a6ccf 100644
--- a/src/plugins/runner/json/JsonParser.cpp
+++ b/src/plugins/runner/json/JsonParser.cpp
@@ -265,7 +265,8 @@ bool JsonParser::read( QIODevice* device )
// Else if the geometry still doesn't have a category, try if this
// key-value properties match any OSM visual category
else if ( category == GeoDataFeature::None ) {
- category = OsmPresetLibrary::osmVisualCategory( propertyIterator.name().toLower() + '=' + propertyIterator.value().toString().toLower() );
+ const auto tag = OsmPresetLibrary::OsmTag(propertyIterator.name().toLower(), propertyIterator.value().toString().toLower());
+ category = OsmPresetLibrary::osmVisualCategory(tag);
if ( category != GeoDataFeature::None ) {
// Add the visual category to all the placemarks
diff --git a/src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.cpp b/src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.cpp
index f2260a4..91eebcf 100644
--- a/src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.cpp
+++ b/src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.cpp
@@ -203,7 +203,8 @@ void OsmNominatimRunner::handleResult( QNetworkReply* reply )
placemark->setDescription(description);
placemark->setAddress(desc);
placemark->setCoordinate( lon.toDouble(), lat.toDouble(), 0, GeoDataCoordinates::Degree );
- GeoDataFeature::GeoDataVisualCategory category = OsmPresetLibrary::osmVisualCategory( key + '=' + value );
+ const auto tag = OsmPresetLibrary::OsmTag(key, value);
+ const GeoDataFeature::GeoDataVisualCategory category = OsmPresetLibrary::osmVisualCategory(tag);
placemark->setVisualCategory( category );
placemark->setExtendedData(placemarkData);
placemark->setOsmData(data);