Commit e39e03cb authored by Dennis Nienhüser's avatar Dennis Nienhüser

Handle placemark selection in the map: Show info, allow routing.

parent a47525a3
......@@ -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)
}
}
......
......@@ -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;
......
......@@ -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;
......
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