Commit 9e0ebe51 authored by Dennis Nienhüser's avatar Dennis Nienhüser

Create a placemark with reverse geocoding result on press and hold

parent 9f492e17
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <MarbleMath.h> #include <MarbleMath.h>
#include <GeoDataCoordinates.h> #include <GeoDataCoordinates.h>
#include <GeoDataTypes.h> #include <GeoDataTypes.h>
#include <ReverseGeocodingRunnerManager.h>
namespace Marble namespace Marble
{ {
...@@ -72,7 +73,7 @@ namespace Marble ...@@ -72,7 +73,7 @@ namespace Marble
void handleMouseButtonPressAndHold(const QPoint &position) void handleMouseButtonPressAndHold(const QPoint &position)
{ {
/** @TODO: Implement */ m_marbleQuick->reverseGeocoding(position);
} }
private Q_SLOTS: private Q_SLOTS:
...@@ -150,7 +151,8 @@ namespace Marble ...@@ -150,7 +151,8 @@ namespace Marble
m_inputHandler(&m_presenter, marble), m_inputHandler(&m_presenter, marble),
m_placemarkDelegate(nullptr), m_placemarkDelegate(nullptr),
m_placemarkItem(nullptr), m_placemarkItem(nullptr),
m_placemark(nullptr) m_placemark(nullptr),
m_reverseGeocoding(&m_model)
{ {
m_currentPosition.setName(QObject::tr("Current Location")); m_currentPosition.setName(QObject::tr("Current Location"));
} }
...@@ -168,6 +170,7 @@ namespace Marble ...@@ -168,6 +170,7 @@ namespace Marble
QQmlComponent* m_placemarkDelegate; QQmlComponent* m_placemarkDelegate;
QQuickItem* m_placemarkItem; QQuickItem* m_placemarkItem;
Placemark* m_placemark; Placemark* m_placemark;
ReverseGeocodingRunnerManager m_reverseGeocoding;
}; };
MarbleQuickItem::MarbleQuickItem(QQuickItem *parent) : QQuickPaintedItem(parent) MarbleQuickItem::MarbleQuickItem(QQuickItem *parent) : QQuickPaintedItem(parent)
...@@ -189,6 +192,8 @@ namespace Marble ...@@ -189,6 +192,8 @@ namespace Marble
connect(&d->m_map, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)), this, SLOT(updatePositionVisibility())); connect(&d->m_map, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)), this, SLOT(updatePositionVisibility()));
connect(&d->m_map, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)), this, SIGNAL(visibleLatLonAltBoxChanged())); connect(&d->m_map, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)), this, SIGNAL(visibleLatLonAltBoxChanged()));
connect(&d->m_map, SIGNAL(radiusChanged(int)), this, SIGNAL(zoomChanged())); connect(&d->m_map, SIGNAL(radiusChanged(int)), this, SIGNAL(zoomChanged()));
connect(&d->m_reverseGeocoding, SIGNAL(reverseGeocodingFinished(GeoDataCoordinates,GeoDataPlacemark)),
this, SLOT(handleReverseGeocoding(GeoDataCoordinates,GeoDataPlacemark)));
setAcceptedMouseButtons(Qt::AllButtons); setAcceptedMouseButtons(Qt::AllButtons);
installEventFilter(&d->m_inputHandler); installEventFilter(&d->m_inputHandler);
...@@ -272,6 +277,14 @@ namespace Marble ...@@ -272,6 +277,14 @@ namespace Marble
} }
} }
void MarbleQuickItem::handleReverseGeocoding(const GeoDataCoordinates &coordinates, const GeoDataPlacemark &placemark)
{
if (d->m_placemark && d->m_placemark->coordinate()->coordinates() == coordinates) {
d->m_placemark->setGeoDataPlacemark(placemark);
updatePlacemarks();
}
}
void MarbleQuickItem::paint(QPainter *painter) void MarbleQuickItem::paint(QPainter *painter)
{ //TODO - much to be done here still, i.e paint !enabled version { //TODO - much to be done here still, i.e paint !enabled version
QPaintDevice *paintDevice = painter->device(); QPaintDevice *paintDevice = painter->device();
...@@ -413,6 +426,19 @@ namespace Marble ...@@ -413,6 +426,19 @@ namespace Marble
return d->m_placemarkDelegate; return d->m_placemarkDelegate;
} }
void MarbleQuickItem::reverseGeocoding(const QPoint &point)
{
qreal lon, lat;
d->m_map.viewport()->geoCoordinates(point.x(), point.y(), lon, lat);
auto const coordinates = GeoDataCoordinates(lon, lat, 0.0, GeoDataCoordinates::Degree);
delete d->m_placemarkItem;
d->m_placemarkItem = nullptr;
delete d->m_placemark;
d->m_placemark = new Placemark;
d->m_placemark->coordinate()->setCoordinates(coordinates);
d->m_reverseGeocoding.reverseGeocoding(coordinates);
}
qreal MarbleQuickItem::speed() const qreal MarbleQuickItem::speed() const
{ {
return d->m_model.positionTracking()->speed(); return d->m_model.positionTracking()->speed();
......
...@@ -169,6 +169,7 @@ namespace Marble ...@@ -169,6 +169,7 @@ namespace Marble
bool inertialGlobeRotation() const; bool inertialGlobeRotation() const;
QQmlComponent* placemarkDelegate() const; QQmlComponent* placemarkDelegate() const;
void reverseGeocoding(const QPoint &point);
Q_SIGNALS: Q_SIGNALS:
void mapWidthChanged(int mapWidth); void mapWidthChanged(int mapWidth);
...@@ -209,6 +210,7 @@ namespace Marble ...@@ -209,6 +210,7 @@ namespace Marble
void updatePositionVisibility(); void updatePositionVisibility();
void updateCurrentPosition(const GeoDataCoordinates & coordinates); void updateCurrentPosition(const GeoDataCoordinates & coordinates);
void updatePlacemarks(); void updatePlacemarks();
void handleReverseGeocoding(const GeoDataCoordinates &coordinates, const GeoDataPlacemark &placemark);
private: private:
typedef QSharedPointer<MarbleQuickItemPrivate> MarbleQuickItemPrivatePtr; typedef QSharedPointer<MarbleQuickItemPrivate> MarbleQuickItemPrivatePtr;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment