summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <[email protected]>2016-07-02 20:48:13 +0200
committerDennis Nienhüser <[email protected]>2016-07-02 20:49:06 +0200
commite39e03cb34ed58e6c2934e5afbc717fa12f7b4ea (patch)
tree5107250fac7102b29669c1e1036692ef2235961a
parenta47525a30aeb4519b9ae4edc99a5c221125f170d (diff)
Handle placemark selection in the map: Show info, allow routing.
-rw-r--r--src/apps/marble-maps/MainScreen.qml13
-rw-r--r--src/lib/marble/declarative/MarbleQuickItem.cpp84
-rw-r--r--src/lib/marble/declarative/MarbleQuickItem.h7
3 files changed, 103 insertions, 1 deletions
diff --git a/src/apps/marble-maps/MainScreen.qml b/src/apps/marble-maps/MainScreen.qml
index 21bff38..5e670b5 100644
--- a/src/apps/marble-maps/MainScreen.qml
+++ b/src/apps/marble-maps/MainScreen.qml
@@ -95,6 +95,18 @@ ApplicationWindow {
positionProvider: suspended ? "" : currentPositionProvider
showPositionMarker: false
+ placemarkDelegate: Image {
+ property int xPos: 0
+ property int yPos: 0
+ property var placemark: null
+ x: xPos - 0.5 * width
+ y: yPos - 0.5 * height
+ width: 20
+ height: 20
+ source: "qrc:///ic_place.png"
+ onPlacemarkChanged: placemarkDialog.placemark = placemark
+ }
+
onPositionAvailableChanged: {
updateIndicator();
}
@@ -138,6 +150,7 @@ ApplicationWindow {
onPressed: {
search.focus = true;
mouse.accepted = false;
+ marbleMaps.selectPlacemarkAt(mouse.x, mouse.y)
}
}
diff --git a/src/lib/marble/declarative/MarbleQuickItem.cpp b/src/lib/marble/declarative/MarbleQuickItem.cpp
index cca1ef2..66fc007 100644
--- a/src/lib/marble/declarative/MarbleQuickItem.cpp
+++ b/src/lib/marble/declarative/MarbleQuickItem.cpp
@@ -13,6 +13,7 @@
#include <QPainter>
#include <QPaintDevice>
#include <QtMath>
+#include <QQmlContext>
#include <MarbleModel.h>
#include <MarbleMap.h>
@@ -30,6 +31,7 @@
#include <RenderPlugin.h>
#include <MarbleMath.h>
#include <GeoDataCoordinates.h>
+#include <GeoDataTypes.h>
namespace Marble
{
@@ -68,6 +70,11 @@ namespace Marble
(void)handlePinch(center, scale, state);
}
+ void handleMouseButtonPressAndHold(const QPoint &position)
+ {
+ /** @TODO: Implement */
+ }
+
private Q_SLOTS:
void showLmbMenu(int, int) {}
void showRmbMenu(int, int) {}
@@ -140,7 +147,10 @@ namespace Marble
m_map(&m_model),
m_presenter(&m_map),
m_positionVisible(false),
- m_inputHandler(&m_presenter, marble)
+ m_inputHandler(&m_presenter, marble),
+ m_placemarkDelegate(nullptr),
+ m_placemarkItem(nullptr),
+ m_placemark(nullptr)
{
m_currentPosition.setName(QObject::tr("Current Location"));
}
@@ -155,6 +165,9 @@ namespace Marble
Placemark m_currentPosition;
MarbleQuickInputHandler m_inputHandler;
+ QQmlComponent* m_placemarkDelegate;
+ QQuickItem* m_placemarkItem;
+ Placemark* m_placemark;
};
MarbleQuickItem::MarbleQuickItem(QQuickItem *parent) : QQuickPaintedItem(parent)
@@ -210,6 +223,7 @@ namespace Marble
void MarbleQuickItem::updatePositionVisibility()
{
+ updatePlacemarks();
bool isVisible = false;
if ( positionAvailable() ) {
if ( d->m_map.viewport()->viewLatLonAltBox().contains(d->m_model.positionTracking()->currentLocation()) ) {
@@ -229,6 +243,35 @@ namespace Marble
emit currentPositionChanged(&d->m_currentPosition);
}
+ void MarbleQuickItem::updatePlacemarks()
+ {
+ if (!d->m_placemarkDelegate || !d->m_placemark) {
+ return;
+ }
+
+ if (!d->m_placemarkItem) {
+ QQmlContext * context = new QQmlContext(qmlContext(d->m_placemarkDelegate));
+ QObject * component = d->m_placemarkDelegate->create(context);
+ d->m_placemarkItem = qobject_cast<QQuickItem*>( component );
+ if (d->m_placemarkItem) {
+ d->m_placemarkItem->setParentItem( this );
+ d->m_placemarkItem->setProperty("placemark", QVariant::fromValue(d->m_placemark));
+ } else {
+ delete component;
+ return;
+ }
+ }
+
+ qreal x = 0;
+ qreal y = 0;
+ const bool visible = d->m_map.viewport()->screenCoordinates(d->m_placemark->coordinate()->coordinates(), x, y);
+ d->m_placemarkItem->setVisible(visible);
+ if (visible) {
+ d->m_placemarkItem->setProperty("xPos", QVariant::fromValue(x));
+ d->m_placemarkItem->setProperty("yPos", QVariant::fromValue(y));
+ }
+ }
+
void MarbleQuickItem::paint(QPainter *painter)
{ //TODO - much to be done here still, i.e paint !enabled version
QPaintDevice *paintDevice = painter->device();
@@ -365,6 +408,11 @@ namespace Marble
return d->m_inputHandler.inertialEarthRotationEnabled();
}
+ QQmlComponent *MarbleQuickItem::placemarkDelegate() const
+ {
+ return d->m_placemarkDelegate;
+ }
+
qreal MarbleQuickItem::speed() const
{
return d->m_model.positionTracking()->speed();
@@ -474,6 +522,28 @@ namespace Marble
}
}
+ void MarbleQuickItem::selectPlacemarkAt(int x, int y)
+ {
+ auto const features = d->m_map.whichFeatureAt(QPoint(x, y));
+ foreach(auto feature, features) {
+ if (feature->nodeType() == GeoDataTypes::GeoDataPlacemarkType) {
+ GeoDataPlacemark const * placemark = static_cast<const GeoDataPlacemark*>(feature);
+ if (d->m_placemark && placemark->coordinate() == d->m_placemark->coordinate()->coordinates()) {
+ delete d->m_placemark;
+ d->m_placemark = nullptr;
+ } else {
+ delete d->m_placemark;
+ d->m_placemark = new Placemark;
+ d->m_placemark->setGeoDataPlacemark(*placemark);
+ }
+ delete d->m_placemarkItem;
+ d->m_placemarkItem = nullptr;
+ updatePlacemarks();
+ return;
+ }
+ }
+ }
+
void MarbleQuickItem::goHome()
{
d->m_presenter.goHome();
@@ -748,6 +818,18 @@ namespace Marble
update();
}
+ void MarbleQuickItem::setPlacemarkDelegate(QQmlComponent *placemarkDelegate)
+ {
+ if (d->m_placemarkDelegate == placemarkDelegate) {
+ return;
+ }
+
+ delete d->m_placemarkItem;
+ d->m_placemarkItem = nullptr;
+ d->m_placemarkDelegate = placemarkDelegate;
+ emit placemarkDelegateChanged(placemarkDelegate);
+ }
+
QObject *MarbleQuickItem::getEventFilter() const
{ //We would want to install the same event filter for abstract layer QuickItems such as PinchArea
return &d->m_inputHandler;
diff --git a/src/lib/marble/declarative/MarbleQuickItem.h b/src/lib/marble/declarative/MarbleQuickItem.h
index 959ecf5..43682b0 100644
--- a/src/lib/marble/declarative/MarbleQuickItem.h
+++ b/src/lib/marble/declarative/MarbleQuickItem.h
@@ -57,6 +57,7 @@ namespace Marble
Q_PROPERTY(qreal speed READ speed NOTIFY speedChanged)
Q_PROPERTY(qreal angle READ angle NOTIFY angleChanged)
Q_PROPERTY(bool inertialGlobeRotation READ inertialGlobeRotation WRITE setInertialGlobeRotation NOTIFY inertialGlobeRotationChanged)
+ Q_PROPERTY(QQmlComponent* placemarkDelegate READ placemarkDelegate WRITE setPlacemarkDelegate NOTIFY placemarkDelegateChanged)
public:
explicit MarbleQuickItem(QQuickItem *parent = 0);
@@ -86,6 +87,7 @@ namespace Marble
void centerOn(qreal longitude, qreal latitude);
Q_INVOKABLE void centerOnCoordinates(qreal longitude, qreal latitude);
Q_INVOKABLE void centerOnCurrentPosition();
+ Q_INVOKABLE void selectPlacemarkAt(int x, int y);
void zoomIn(FlyToMode mode = Automatic);
void zoomOut(FlyToMode mode = Automatic);
@@ -121,6 +123,8 @@ namespace Marble
Q_INVOKABLE void setShowRuntimeTrace(bool showRuntimeTrace);
Q_INVOKABLE void setShowDebugPolygons(bool showDebugPolygons);
+ void setPlacemarkDelegate(QQmlComponent* placemarkDelegate);
+
public:
void paint(QPainter *painter);
@@ -164,6 +168,7 @@ namespace Marble
const MarbleMap* map() const;
bool inertialGlobeRotation() const;
+ QQmlComponent* placemarkDelegate() const;
Q_SIGNALS:
void mapWidthChanged(int mapWidth);
@@ -191,6 +196,7 @@ namespace Marble
void speedChanged();
void zoomChanged();
void inertialGlobeRotationChanged(bool inertialGlobeRotation);
+ void placemarkDelegateChanged(QQmlComponent* placemarkDelegate);
protected:
QObject *getEventFilter() const;
@@ -202,6 +208,7 @@ namespace Marble
void positionChanged(const GeoDataCoordinates &, GeoDataAccuracy);
void updatePositionVisibility();
void updateCurrentPosition(const GeoDataCoordinates & coordinates);
+ void updatePlacemarks();
private:
typedef QSharedPointer<MarbleQuickItemPrivate> MarbleQuickItemPrivatePtr;