summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantin Mihalache <[email protected]>2015-05-25 15:18:35 +0300
committerConstantin Mihalache <[email protected]>2015-05-25 15:18:35 +0300
commitf3aefcfb21f62c896f588f2ae40e7906afb180d6 (patch)
treed311c8ef7546560194fbc587ce448fa220ffd4d5
parent9a76d803c2ca822efc33f07b08904c16dfbf81ac (diff)
Implement missing KmlLabelStyleTagWriter.
Implement defaultColor() virtual method in KmlColorStyleTagWriter. Add unit test for placemarks.
-rw-r--r--src/lib/marble/geodata/CMakeLists.txt1
-rw-r--r--src/lib/marble/geodata/writers/kml/KmlColorStyleTagWriter.cpp9
-rw-r--r--src/lib/marble/geodata/writers/kml/KmlColorStyleTagWriter.h3
-rw-r--r--src/lib/marble/geodata/writers/kml/KmlLabelStyleTagWriter.cpp52
-rw-r--r--src/lib/marble/geodata/writers/kml/KmlLabelStyleTagWriter.h31
-rw-r--r--tests/data/PlacemarkTest.kml63
6 files changed, 157 insertions, 2 deletions
diff --git a/src/lib/marble/geodata/CMakeLists.txt b/src/lib/marble/geodata/CMakeLists.txt
index fe22e24..cb89e7f 100644
--- a/src/lib/marble/geodata/CMakeLists.txt
+++ b/src/lib/marble/geodata/CMakeLists.txt
@@ -413,6 +413,7 @@ geodata/writers/kml/KmlIconStyleTagWriter.cpp
geodata/writers/kml/KmlLatLonAltBoxWriter.cpp
geodata/writers/kml/KmlLatLonBoxWriter.cpp
geodata/writers/kml/KmlLatLonQuadWriter.cpp
+geodata/writers/kml/KmlLabelStyleTagWriter.cpp
geodata/writers/kml/KmlLinearRingTagWriter.cpp
geodata/writers/kml/KmlLineStringTagWriter.cpp
geodata/writers/kml/KmlLineStyleTagWriter.cpp
diff --git a/src/lib/marble/geodata/writers/kml/KmlColorStyleTagWriter.cpp b/src/lib/marble/geodata/writers/kml/KmlColorStyleTagWriter.cpp
index 2696750..aaa4120 100644
--- a/src/lib/marble/geodata/writers/kml/KmlColorStyleTagWriter.cpp
+++ b/src/lib/marble/geodata/writers/kml/KmlColorStyleTagWriter.cpp
@@ -31,7 +31,7 @@ bool KmlColorStyleTagWriter::write( const Marble::GeoNode *node, GeoWriter &writ
if ( colorStyle->id().isEmpty() &&
colorStyle->targetId().isEmpty() &&
- colorStyle->color() == QColor( Qt::white ) &&
+ colorStyle->color() == defaultColor() &&
colorStyle->colorMode() == GeoDataColorStyle::Normal &&
isEmpty( node ) ) {
return true;
@@ -40,7 +40,7 @@ bool KmlColorStyleTagWriter::write( const Marble::GeoNode *node, GeoWriter &writ
writer.writeStartElement( m_elementName );
KmlObjectTagWriter::writeIdentifiers( writer, colorStyle);
- writer.writeOptionalElement( kml::kmlTag_color, formatColor( colorStyle->color() ), "ffffffff" );
+ writer.writeOptionalElement( kml::kmlTag_color, formatColor( colorStyle->color() ), formatColor( defaultColor() ) );
QString const colorMode = colorStyle->colorMode() == GeoDataColorStyle::Random ? "random" : "normal";
writer.writeOptionalElement( kml::kmlTag_colorMode, colorMode, "normal" );
@@ -59,4 +59,9 @@ QString KmlColorStyleTagWriter::formatColor( const QColor &color )
.arg( color.red(), 2, 16, fill );
}
+QColor KmlColorStyleTagWriter::defaultColor() const
+{
+ return QColor( Qt::white );
+}
+
}
diff --git a/src/lib/marble/geodata/writers/kml/KmlColorStyleTagWriter.h b/src/lib/marble/geodata/writers/kml/KmlColorStyleTagWriter.h
index 62be099..3ca7320 100644
--- a/src/lib/marble/geodata/writers/kml/KmlColorStyleTagWriter.h
+++ b/src/lib/marble/geodata/writers/kml/KmlColorStyleTagWriter.h
@@ -34,6 +34,9 @@ protected:
/** Returns true iff all properties have a default value */
virtual bool isEmpty( const GeoNode *node ) const = 0;
+ /** Returns the default color **/
+ virtual QColor defaultColor() const;
+
private:
QString const m_elementName;
};
diff --git a/src/lib/marble/geodata/writers/kml/KmlLabelStyleTagWriter.cpp b/src/lib/marble/geodata/writers/kml/KmlLabelStyleTagWriter.cpp
new file mode 100644
index 0000000..5286daf
--- /dev/null
+++ b/src/lib/marble/geodata/writers/kml/KmlLabelStyleTagWriter.cpp
@@ -0,0 +1,52 @@
+//
+// This file is part of the Marble Virtual Globe.
+//
+// This program is free software licensed under the GNU LGPL. You can
+// find a copy of this license in LICENSE.txt in the top directory of
+// the source code.
+//
+// Copyright 2015 Constantin Mihalache <[email protected]>
+
+#include "KmlLabelStyleTagWriter.h"
+
+#include "GeoDataLabelStyle.h"
+#include "GeoDataTypes.h"
+#include "GeoWriter.h"
+#include "KmlElementDictionary.h"
+#include <QDebug>
+
+namespace Marble
+{
+
+static GeoTagWriterRegistrar s_writerLineStyle(
+ GeoTagWriter::QualifiedName( GeoDataTypes::GeoDataLabelStyleType,
+ kml::kmlTag_nameSpaceOgc22),
+ new KmlLabelStyleTagWriter );
+
+KmlLabelStyleTagWriter::KmlLabelStyleTagWriter() : KmlColorStyleTagWriter( kml::kmlTag_LabelStyle )
+{
+ //nothing to do here
+}
+
+bool KmlLabelStyleTagWriter::writeMid( const GeoNode *node, GeoWriter &writer ) const
+{
+ const GeoDataLabelStyle *style = static_cast<const GeoDataLabelStyle*>( node );
+
+ writer.writeElement( kml::kmlTag_scale, QString::number(style->scale()));
+
+ return true;
+}
+
+bool KmlLabelStyleTagWriter::isEmpty(const GeoNode *node) const
+{
+ const GeoDataLabelStyle *style = static_cast<const GeoDataLabelStyle*>( node );
+
+ return style->scale() == 1.0;
+}
+
+QColor KmlLabelStyleTagWriter::defaultColor() const
+{
+ return QColor( Qt::black );
+}
+
+}
diff --git a/src/lib/marble/geodata/writers/kml/KmlLabelStyleTagWriter.h b/src/lib/marble/geodata/writers/kml/KmlLabelStyleTagWriter.h
new file mode 100644
index 0000000..1be4ad4
--- /dev/null
+++ b/src/lib/marble/geodata/writers/kml/KmlLabelStyleTagWriter.h
@@ -0,0 +1,31 @@
+//
+// This file is part of the Marble Virtual Globe.
+//
+// This program is free software licensed under the GNU LGPL. You can
+// find a copy of this license in LICENSE.txt in the top directory of
+// the source code.
+//
+// Copyright 2015 Constantin Mihalache <[email protected]>
+
+#ifndef KMLLABELSTYLETAGWRITER_H
+#define KMLLABELSTYLETAGWRITER_H
+
+#include "KmlColorStyleTagWriter.h"
+#include "GeoTagWriter.h"
+
+namespace Marble
+{
+
+class KmlLabelStyleTagWriter : public KmlColorStyleTagWriter
+{
+public:
+ KmlLabelStyleTagWriter();
+
+protected:
+ virtual bool writeMid( const GeoNode *node, GeoWriter &writer ) const;
+ virtual bool isEmpty( const GeoNode *node ) const;
+ virtual QColor defaultColor() const;
+};
+
+}
+#endif // KMLLABELSTYLETAGWRITER_H
diff --git a/tests/data/PlacemarkTest.kml b/tests/data/PlacemarkTest.kml
new file mode 100644
index 0000000..30bd3a0
--- /dev/null
+++ b/tests/data/PlacemarkTest.kml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
+ <Document>
+ <name>PlacemarkTest.kml</name>
+ <Style id="sh_ylw-pushpin">
+ <IconStyle>
+ <color>feff651e</color>
+ <scale>4.727270</scale>
+ <Icon>
+ <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
+ </Icon>
+ <hotSpot x="20.000000" y="2.000000" xunits="pixels" yunits="pixels"/>
+ </IconStyle>
+ <LabelStyle>
+ <color>ff35ff38</color>
+ <scale>4.5</scale>
+ </LabelStyle>
+ </Style>
+ <Style id="sn_ylw-pushpin">
+ <IconStyle>
+ <color>feff651e</color>
+ <scale>4.000000</scale>
+ <Icon>
+ <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
+ </Icon>
+ <hotSpot x="20.000000" y="2.000000" xunits="pixels" yunits="pixels"/>
+ </IconStyle>
+ <LabelStyle>
+ <color>ff35ff38</color>
+ <scale>4.5</scale>
+ </LabelStyle>
+ </Style>
+ <StyleMap id="msn_ylw-pushpin">
+ <Pair>
+ <key>highlight</key>
+ <styleUrl>#sh_ylw-pushpin</styleUrl>
+ </Pair>
+ <Pair>
+ <key>normal</key>
+ <styleUrl>#sn_ylw-pushpin</styleUrl>
+ </Pair>
+ </StyleMap>
+ <Folder>
+ <name>Marble test</name>
+ <description>Not a very special description</description>
+ <Placemark>
+ <name>One placemark</name>
+ <description>This is, indeed, a true placemark description.</description>
+ <LookAt>
+ <longitude>-40.0000003592</longitude>
+ <latitude>24.9999947791</latitude>
+ <altitude>0.0000000000</altitude>
+ <range>25522625.9522628300</range>
+ <gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
+ </LookAt>
+ <styleUrl>#msn_ylw-pushpin</styleUrl>
+ <Point>
+ <coordinates>-40.0000003592,24.9999947791</coordinates>
+ </Point>
+ </Placemark>
+ </Folder>
+ </Document>
+</kml> \ No newline at end of file