summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/imports/location/qdeclarativecirclemapitem.cpp117
-rw-r--r--src/imports/location/qdeclarativecirclemapitem_p.h29
-rw-r--r--src/imports/location/qdeclarativegeomapitembase.cpp11
-rw-r--r--src/imports/location/qdeclarativegeomapitembase_p.h9
-rw-r--r--src/imports/location/qdeclarativegeomapmousearea.cpp52
-rw-r--r--src/imports/location/qdeclarativegeomapmousearea_p.h6
-rw-r--r--src/imports/location/qdeclarativegeomapquickitem.cpp50
-rw-r--r--src/imports/location/qdeclarativegeomapquickitem_p.h7
-rw-r--r--src/imports/location/qdeclarativepolylinemapitem.cpp99
-rw-r--r--src/imports/location/qdeclarativepolylinemapitem_p.h20
-rw-r--r--src/imports/location/qdeclarativerectanglemapitem.cpp111
-rw-r--r--src/imports/location/qdeclarativerectanglemapitem_p.h19
-rw-r--r--tests/applications/declarative_map/map3d.qml341
13 files changed, 673 insertions, 198 deletions
diff --git a/src/imports/location/qdeclarativecirclemapitem.cpp b/src/imports/location/qdeclarativecirclemapitem.cpp
index 8cf4a3f1..794b02f4 100644
--- a/src/imports/location/qdeclarativecirclemapitem.cpp
+++ b/src/imports/location/qdeclarativecirclemapitem.cpp
@@ -46,6 +46,8 @@
#include <QPen>
#include <QPainter>
+QT_BEGIN_NAMESPACE
+
//TODO: make export ??
#ifndef M_PI
@@ -103,10 +105,13 @@ static QPolygonF createPolygon(const Map& map, const QList<QGeoCoordinate> &path
QDeclarativeCircleMapItem::QDeclarativeCircleMapItem(QQuickItem *parent):
QDeclarativeGeoMapItemBase(parent),
- center_(0),
- quickItem_(new QDeclarativeGeoMapQuickItem(this)),
- circleMapPaintedItem_(new CircleMapPaintedItem(quickItem_))
+ center_(0),
+ circleItem_(new CircleMapPaintedItem(this)),
+ inUpdate_(false),
+ zoomLevel_(0.0),
+ dragActive_(false)
{
+ circleItem_->setParentItem(this);
}
QDeclarativeCircleMapItem::~QDeclarativeCircleMapItem()
@@ -117,17 +122,13 @@ void QDeclarativeCircleMapItem::setCenter(QDeclarativeCoordinate *center)
{
if (center_ == center)
return;
-
if (center_)
center_->disconnect(this);
-
center_ = center;
-
if (!center_) {
- circleMapPaintedItem_->setCenter(QGeoCoordinate());
+ circleItem_->setCenter(QGeoCoordinate());
} else {
- circleMapPaintedItem_->setCenter(center_->coordinate());
-
+ circleItem_->setCenter(center_->coordinate());
connect(center_, SIGNAL(latitudeChanged(double)), this,
SLOT(handleCenterCoordinateChanged()));
connect(center_, SIGNAL(longitudeChanged(double)), this,
@@ -135,7 +136,6 @@ void QDeclarativeCircleMapItem::setCenter(QDeclarativeCoordinate *center)
connect(center_, SIGNAL(altitudeChanged(double)), this,
SLOT(handleCenterCoordinateChanged()));
}
-
emit centerChanged(center_);
}
@@ -146,12 +146,12 @@ QDeclarativeCoordinate* QDeclarativeCircleMapItem::center()
void QDeclarativeCircleMapItem::handleCenterCoordinateChanged()
{
- circleMapPaintedItem_->setCenter(center_->coordinate());
+ circleItem_->setCenter(center_->coordinate());
}
void QDeclarativeCircleMapItem::handleCameraDataChanged(const CameraData& cameraData)
{
- circleMapPaintedItem_->setZoomLevel(cameraData.zoomFactor());
+ circleItem_->setZoomLevel(cameraData.zoomFactor());
update();
}
@@ -161,7 +161,7 @@ void QDeclarativeCircleMapItem::setColor(const QColor &color)
return;
color_ = color;
QBrush m_brush(color);
- circleMapPaintedItem_->setBrush(m_brush);
+ circleItem_->setBrush(m_brush);
emit colorChanged(color_);
}
@@ -172,31 +172,70 @@ QColor QDeclarativeCircleMapItem::color() const
void QDeclarativeCircleMapItem::setRadius(qreal radius)
{
- if (circleMapPaintedItem_->radius() == radius)
+ if (circleItem_->radius() == radius)
return;
- circleMapPaintedItem_->setRadius(radius);
+ circleItem_->setRadius(radius);
emit radiusChanged(radius);
}
qreal QDeclarativeCircleMapItem::radius() const
{
- return circleMapPaintedItem_->radius();
+ return circleItem_->radius();
}
void QDeclarativeCircleMapItem::update()
{
- if (!map())
+ if (inUpdate_ || !map())
return;
- quickItem_->setCoordinate(new QDeclarativeCoordinate(circleMapPaintedItem_->quickItemCoordinate()));
- quickItem_->setAnchorPoint(circleMapPaintedItem_->quickItemAnchorPoint());
-
- if (quickItem_->sourceItem() == 0) {
+ inUpdate_ = true;
+ QPointF topLeft = map()->coordinateToScreenPosition(center()->coordinate(), false) - QPointF(width(),height()) / 2;
+ if ((topLeft.x() > quickMap()->width())
+ || (topLeft.x() + width() < 0)
+ || (topLeft.y() + height() < 0)
+ || (topLeft.y() > quickMap()->height())) {
+ setPos(map()->coordinateToScreenPosition(QGeoCoordinate()));
+ } else {
+ setWidth(circleItem_->width());
+ setHeight(circleItem_->height());
+ setPos(topLeft);
+ }
+ // optimize this check/calls, need to be done only when map changes:
+ if (!circleItem_->map()) {
+ circleItem_->setMap(map());
connect(map(), SIGNAL(cameraDataChanged(CameraData)), this, SLOT(handleCameraDataChanged(CameraData)));
- circleMapPaintedItem_->setMap(map());
- quickItem_->setMap(quickMap(), map());
- quickItem_->setSourceItem(circleMapPaintedItem_);
}
+ inUpdate_ = false;
+}
+
+void QDeclarativeCircleMapItem::dragEnded()
+{
+ if (!dragActive_)
+ return;
+ dragActive_ = false;
+ QPointF newPoint = QPointF(x(),y()) + QPointF(width(), height()) / 2;
+ QGeoCoordinate newCoordinate = map()->screenPositionToCoordinate(newPoint, false);
+ if (newCoordinate.isValid()) {
+ internalCoordinate_.setCoordinate(newCoordinate);
+ setCenter(&internalCoordinate_);
+ }
+}
+
+void QDeclarativeCircleMapItem::dragStarted()
+{
+ dragActive_ = true;
+}
+
+bool QDeclarativeCircleMapItem::contains(QPointF point)
+{
+ return circleItem_->contains(point);
+}
+
+void QDeclarativeCircleMapItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ // TODO - if X and Y of the wrapper item are changed, currently
+ // the item moves, but returns to old position when map camera changes
+ QQuickItem::geometryChanged(newGeometry, oldGeometry);
}
//////////////////////////////////////////////////////////////////////
@@ -216,9 +255,16 @@ CircleMapPaintedItem::~CircleMapPaintedItem() {}
void CircleMapPaintedItem::setMap(Map* map)
{
+ if (map_ == map)
+ return;
map_ = map;
}
+Map* CircleMapPaintedItem::map()
+{
+ return map_;
+}
+
void CircleMapPaintedItem::setZoomLevel(qreal zoomLevel)
{
if (zoomLevel_ == zoomLevel)
@@ -235,20 +281,17 @@ qreal CircleMapPaintedItem::zoomLevel() const
void CircleMapPaintedItem::paint(QPainter *painter)
{
-
if (!initialized_)
return;
painter->setPen(pen_);
painter->setBrush(brush_);
painter->drawConvexPolygon(polygon_);
-
}
void CircleMapPaintedItem::updateGeometry()
{
initialized_ = false;
-
if (!map_)
return;
@@ -258,7 +301,6 @@ void CircleMapPaintedItem::updateGeometry()
if (zoomLevel_ == -1)
return;
-
QPointF center = map_->coordinateToScreenPosition(centerCoord_, false);
qreal w = 0;
@@ -273,10 +315,7 @@ void CircleMapPaintedItem::updateGeometry()
setHeight(h);
setContentsSize(QSize(w, h));
- quickItemCoordinate_ = centerCoord_;
- quickItemAnchorPoint_ = QPointF(w, h) / 2;
initialized_ = true;
-
update();
}
@@ -357,7 +396,6 @@ void CircleMapPaintedItem::setCenter(const QGeoCoordinate &center)
{
if (centerCoord_ == center)
return;
-
centerCoord_ = center;
updateGeometry();
}
@@ -367,6 +405,11 @@ const QGeoCoordinate& CircleMapPaintedItem::center() const
return centerCoord_;
}
+bool CircleMapPaintedItem::contains(QPointF point)
+{
+ return polygon_.containsPoint(point, Qt::OddEvenFill);
+}
+
void CircleMapPaintedItem::setRadius(qreal radius)
{
if (radius_ == radius)
@@ -381,12 +424,4 @@ qreal CircleMapPaintedItem::radius() const
return radius_;
}
-QGeoCoordinate CircleMapPaintedItem::quickItemCoordinate() const
-{
- return quickItemCoordinate_;
-}
-
-QPointF CircleMapPaintedItem::quickItemAnchorPoint() const
-{
- return quickItemAnchorPoint_;
-}
+QT_END_NAMESPACE
diff --git a/src/imports/location/qdeclarativecirclemapitem_p.h b/src/imports/location/qdeclarativecirclemapitem_p.h
index ff290749..3557f616 100644
--- a/src/imports/location/qdeclarativecirclemapitem_p.h
+++ b/src/imports/location/qdeclarativecirclemapitem_p.h
@@ -39,16 +39,14 @@
**
****************************************************************************/
-#ifndef QDECLARATIVECRICLEMAPITEM_H_
-#define QDECLARATIVECRICLEMAPITEM_H_
+#ifndef QDECLARATIVECIRCLEMAPITEM_H
+#define QDECLARATIVECIRCLEMAPITEM_H
#include "qdeclarativegeomapitembase_p.h"
#include <QPen>
#include <QBrush>
QT_BEGIN_NAMESPACE
-class QDeclarativeGeoMapQuickItem;
-QT_END_NAMESPACE
class CircleMapPaintedItem;
@@ -72,6 +70,10 @@ public:
QColor color() const;
void setColor(const QColor &color);
+ void dragStarted();
+ void dragEnded();
+ bool contains(QPointF point);
+
Q_SIGNALS:
void centerChanged(const QDeclarativeCoordinate *center);
void radiusChanged(qreal radius);
@@ -79,17 +81,21 @@ Q_SIGNALS:
protected Q_SLOTS:
void update();
+ // from qquickitem
+ void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
private Q_SLOTS:
void handleCameraDataChanged(const CameraData& cameraData);
void handleCenterCoordinateChanged();
-
private:
+ QDeclarativeCoordinate internalCoordinate_;
QDeclarativeCoordinate *center_;
- QDeclarativeGeoMapQuickItem *quickItem_;
- CircleMapPaintedItem *circleMapPaintedItem_;
+ CircleMapPaintedItem *circleItem_;
QColor color_;
+ bool inUpdate_;
+ bool zoomLevel_;
+ bool dragActive_;
};
//////////////////////////////////////////////////////////////////////
@@ -102,6 +108,7 @@ public:
~CircleMapPaintedItem();
void setMap(Map* map);
+ Map* map();
void setZoomLevel(qreal zoomLevel);
qreal zoomLevel() const;
@@ -119,8 +126,7 @@ public:
QBrush brush() const;
void setBrush(const QBrush &brush);
- QGeoCoordinate quickItemCoordinate() const;
- QPointF quickItemAnchorPoint() const;
+ bool contains(QPointF point);
private:
void updateGeometry();
@@ -130,8 +136,6 @@ private:
qreal zoomLevel_;
QGeoCoordinate centerCoord_;
qreal radius_;
- QGeoCoordinate quickItemCoordinate_;
- QPointF quickItemAnchorPoint_;
QPen pen_;
QBrush brush_;
QPolygonF polygon_;
@@ -139,5 +143,6 @@ private:
bool initialized_;
};
+QT_END_NAMESPACE
-#endif /* QDECLARATIVECRICLEMAPITEM_H_ */
+#endif /* QDECLARATIVECIRCLEMAPITEM_H */
diff --git a/src/imports/location/qdeclarativegeomapitembase.cpp b/src/imports/location/qdeclarativegeomapitembase.cpp
index 33e01625..bdec43a1 100644
--- a/src/imports/location/qdeclarativegeomapitembase.cpp
+++ b/src/imports/location/qdeclarativegeomapitembase.cpp
@@ -62,11 +62,20 @@ void QDeclarativeGeoMapItemBase::componentComplete()
componentComplete_ = true;
}
-bool QDeclarativeGeoMapItemBase::contains(QPoint point)
+bool QDeclarativeGeoMapItemBase::contains(QPointF point)
{
+ Q_UNUSED(point);
return true;
}
+void QDeclarativeGeoMapItemBase::dragStarted()
+{
+}
+
+void QDeclarativeGeoMapItemBase::dragEnded()
+{
+}
+
void QDeclarativeGeoMapItemBase::setMap(QDeclarativeGeoMap* quickMap, Map *map)
{
QLOC_TRACE2(quickMap, quickMap_);
diff --git a/src/imports/location/qdeclarativegeomapitembase_p.h b/src/imports/location/qdeclarativegeomapitembase_p.h
index 785fab09..17f24f53 100644
--- a/src/imports/location/qdeclarativegeomapitembase_p.h
+++ b/src/imports/location/qdeclarativegeomapitembase_p.h
@@ -45,6 +45,7 @@
#include <QtDeclarative/qquickitem.h>
#include "qdeclarativegeomap_p.h"
+#include "qdeclarativecoordinate_p.h"
QT_BEGIN_NAMESPACE
@@ -53,12 +54,14 @@ class QDeclarativeGeoMapItemBase : public QQuickItem
Q_OBJECT
public:
QDeclarativeGeoMapItemBase(QQuickItem *parent = 0);
- ~QDeclarativeGeoMapItemBase();
+ virtual ~QDeclarativeGeoMapItemBase();
void setMap(QDeclarativeGeoMap* quickMap, Map *map);
virtual void classBegin() {}
virtual void componentComplete();
- virtual bool contains(QPoint point);
+ virtual bool contains(QPointF point);
+ virtual void dragStarted();
+ virtual void dragEnded();
QDeclarativeGeoMap* quickMap();
protected Q_SLOTS:
@@ -66,6 +69,7 @@ protected Q_SLOTS:
protected:
Map* map();
+ bool inUpdate_;
private:
QDeclarativeGeoMap* quickMap_;
@@ -73,7 +77,6 @@ private:
Map* map_;
};
-
QT_END_NAMESPACE
#endif
diff --git a/src/imports/location/qdeclarativegeomapmousearea.cpp b/src/imports/location/qdeclarativegeomapmousearea.cpp
index 0cf1200c..c29d749e 100644
--- a/src/imports/location/qdeclarativegeomapmousearea.cpp
+++ b/src/imports/location/qdeclarativegeomapmousearea.cpp
@@ -108,12 +108,11 @@ QDeclarativeGeoMapMouseArea::~QDeclarativeGeoMapMouseArea()
QDeclarativeCoordinate* QDeclarativeGeoMapMouseArea::mouseToCoordinate(QQuickMouseEvent* event)
{
// figure out the map association for this mouse area and use it to resolve geocoordinate.
- // we may need to dive higher in the parent tree if associating
- // element (map item or map element) is further up the tree. TODO
- if (parentItem()) {
- QDeclarativeGeoMap* map = qobject_cast<QDeclarativeGeoMap*>(parentItem());
+ QQuickItem* pmi = parentMapItem();
+ if (pmi) {
+ QDeclarativeGeoMap* map = qobject_cast<QDeclarativeGeoMap*>(pmi);
if (!map) {
- QDeclarativeGeoMapItemBase* item = qobject_cast<QDeclarativeGeoMapItemBase*>(parentItem());
+ QDeclarativeGeoMapItemBase* item = qobject_cast<QDeclarativeGeoMapItemBase*>(pmi);
if (item)
map = item->quickMap();
}
@@ -123,21 +122,34 @@ QDeclarativeCoordinate* QDeclarativeGeoMapMouseArea::mouseToCoordinate(QQuickMou
return new QDeclarativeCoordinate; // return invalid coordinate
}
+void QDeclarativeGeoMapMouseArea::dragActiveChanged()
+{
+ QQuickItem* pmi = parentMapItem();
+ if (pmi && qobject_cast<QDeclarativeGeoMapItemBase*>(pmi)) {
+ if (drag() && drag()->property("active").toBool())
+ qobject_cast<QDeclarativeGeoMapItemBase*>(pmi)->dragStarted();
+ else
+ qobject_cast<QDeclarativeGeoMapItemBase*>(pmi)->dragEnded();
+ }
+}
+
void QDeclarativeGeoMapMouseArea::componentComplete()
{
componentCompleted_ = true;
+ connect(drag(), SIGNAL(activeChanged()), this, SLOT(dragActiveChanged()));
QQuickMouseArea::componentComplete();
}
void QDeclarativeGeoMapMouseArea::mousePressEvent(QMouseEvent *event)
{
// map element's flickable may use the event
- if (parentItem() && qobject_cast<QDeclarativeGeoMap*>(parentItem()))
- qobject_cast<QDeclarativeGeoMap*>(parentItem())->mouseEvent(event);
+ QQuickItem* pmi = parentMapItem();
+ if (pmi && qobject_cast<QDeclarativeGeoMap*>(pmi))
+ qobject_cast<QDeclarativeGeoMap*>(pmi)->mouseEvent(event);
// ignore event if it misses non-rectangular geometry (e.g. circle, route)
bool contains = true;
- if (parentItem() && qobject_cast<QDeclarativeGeoMapItemBase*>(parentItem()))
- contains = qobject_cast<QDeclarativeGeoMapItemBase*>(parentItem())->contains(event->pos());
+ if (pmi && qobject_cast<QDeclarativeGeoMapItemBase*>(pmi))
+ contains = qobject_cast<QDeclarativeGeoMapItemBase*>(pmi)->contains(event->pos());
if (!contains)
event->ignore();
else
@@ -147,8 +159,9 @@ void QDeclarativeGeoMapMouseArea::mousePressEvent(QMouseEvent *event)
void QDeclarativeGeoMapMouseArea::mouseReleaseEvent(QMouseEvent *event)
{
// map element's flickable may use the event
- if (parentItem() && qobject_cast<QDeclarativeGeoMap*>(parentItem()))
- qobject_cast<QDeclarativeGeoMap*>(parentItem())->mouseEvent(event);
+ QQuickItem* pmi = parentMapItem();
+ if (pmi && qobject_cast<QDeclarativeGeoMap*>(pmi))
+ qobject_cast<QDeclarativeGeoMap*>(pmi)->mouseEvent(event);
QQuickMouseArea::mouseReleaseEvent(event);
}
@@ -160,11 +173,24 @@ void QDeclarativeGeoMapMouseArea::mouseDoubleClickEvent(QMouseEvent *event)
void QDeclarativeGeoMapMouseArea::mouseMoveEvent(QMouseEvent *event)
{
// map element's flickable may use the event
- if (parentItem() && qobject_cast<QDeclarativeGeoMap*>(parentItem()))
- qobject_cast<QDeclarativeGeoMap*>(parentItem())->mouseEvent(event);
+ QQuickItem* pmi = parentMapItem();
+ if (pmi && qobject_cast<QDeclarativeGeoMap*>(pmi))
+ qobject_cast<QDeclarativeGeoMap*>(pmi)->mouseEvent(event);
QQuickMouseArea::mouseMoveEvent(event);
}
+QQuickItem* QDeclarativeGeoMapMouseArea::parentMapItem()
+{
+ QQuickItem* item = this;
+ while (item->parentItem()) {
+ item = item->parentItem();
+ if (qobject_cast<QDeclarativeGeoMap*>(item) ||
+ qobject_cast<QDeclarativeGeoMapItemBase*>(item))
+ return item;
+ }
+ return 0;
+}
+
/*!
\qmlproperty real QtLocation5::MapMouseArea::mouseX
\qmlproperty real QtLocation5::MapMouseArea::mouseY
diff --git a/src/imports/location/qdeclarativegeomapmousearea_p.h b/src/imports/location/qdeclarativegeomapmousearea_p.h
index 8c1657da..a12e2a61 100644
--- a/src/imports/location/qdeclarativegeomapmousearea_p.h
+++ b/src/imports/location/qdeclarativegeomapmousearea_p.h
@@ -71,6 +71,12 @@ protected:
void mouseDoubleClickEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
+private Q_SLOTS:
+ void dragActiveChanged();
+
+private:
+ QQuickItem* parentMapItem();
+
private:
QDeclarativeGeoMap* map_;
bool componentCompleted_;
diff --git a/src/imports/location/qdeclarativegeomapquickitem.cpp b/src/imports/location/qdeclarativegeomapquickitem.cpp
index 12ad4ad5..8a9aa4b2 100644
--- a/src/imports/location/qdeclarativegeomapquickitem.cpp
+++ b/src/imports/location/qdeclarativegeomapquickitem.cpp
@@ -60,7 +60,8 @@ QDeclarativeGeoMapQuickItem::QDeclarativeGeoMapQuickItem(QQuickItem *parent)
sourceItem_(0),
zoomLevel_(0.0),
inUpdate_(false),
- mapAndSourceItemSet_(false) {}
+ mapAndSourceItemSet_(false),
+ dragActive_(true) {}
QDeclarativeGeoMapQuickItem::~QDeclarativeGeoMapQuickItem() {}
@@ -89,6 +90,43 @@ void QDeclarativeGeoMapQuickItem::setCoordinate(QDeclarativeCoordinate *coordina
emit coordinateChanged();
}
+void QDeclarativeGeoMapQuickItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ if (!dragActive_ && quickMap() && sourceItem() && newGeometry.isValid() && newGeometry != oldGeometry) {
+ QPointF point(newGeometry.x(), newGeometry.y());
+ // screenPositionToCoordinate seems to return nan values when
+ // it goes beyond viewport, hence sanity check (fixme todo):
+ QGeoCoordinate newCoordinate = map()->screenPositionToCoordinate(point, false);
+ if (newCoordinate.isValid()) {
+ internalCoordinate_.setCoordinate(newCoordinate);
+ setCoordinate(&internalCoordinate_);
+ }
+ }
+ QQuickItem::geometryChanged(newGeometry, oldGeometry);
+}
+
+void QDeclarativeGeoMapQuickItem::dragStarted()
+{
+ dragActive_ = true;
+}
+
+void QDeclarativeGeoMapQuickItem::dragEnded()
+{
+ if (!dragActive_)
+ return;
+ dragActive_ = false;
+ if (quickMap() && sourceItem()) {
+ QPointF point(x(), y());
+ // screenPositionToCoordinate seems to return nan values when
+ // it goes beyond viewport, hence sanity check (fixme todo):
+ QGeoCoordinate newCoordinate = map()->screenPositionToCoordinate(point, false);
+ if (newCoordinate.isValid()) {
+ internalCoordinate_.setCoordinate(newCoordinate);
+ setCoordinate(&internalCoordinate_);
+ }
+ }
+}
+
void QDeclarativeGeoMapQuickItem::coordinateCoordinateChanged(double)
{
update();
@@ -161,7 +199,6 @@ void QDeclarativeGeoMapQuickItem::update()
if (!mapAndSourceItemSet_ && quickMap() && map() && sourceItem_) {
mapAndSourceItemSet_ = true;
-
sourceItem_->setParentItem(this);
sourceItem_->setTransformOrigin(QQuickItem::TopLeft);
connect(quickMap(), SIGNAL(heightChanged()), this, SLOT(update()));
@@ -185,12 +222,17 @@ void QDeclarativeGeoMapQuickItem::update()
|| (topLeft.x() + s * sourceItem_->width() < 0)
|| (topLeft.y() + s * sourceItem_->height() < 0)
|| (topLeft.y() > quickMap()->height())) {
+ // TODO FIXME generates QTransform::translate with NaN called - warnings:
sourceItem_->setPos(invalid);
+ setPos(invalid);
} else {
- sourceItem_->setPos(topLeft);
+ // source item is positioned at 0,0 of the wrapper item
+ setPos(topLeft);
+ sourceItem_->setPos(QPointF(0,0));
sourceItem_->setScale(s);
+ setWidth(sourceItem_->width());
+ setHeight(sourceItem_->height());
}
-
inUpdate_ = false;
}
diff --git a/src/imports/location/qdeclarativegeomapquickitem_p.h b/src/imports/location/qdeclarativegeomapquickitem_p.h
index c51f46c8..919a932a 100644
--- a/src/imports/location/qdeclarativegeomapquickitem_p.h
+++ b/src/imports/location/qdeclarativegeomapquickitem_p.h
@@ -74,6 +74,9 @@ public:
void setZoomLevel(qreal zoomLevel);
qreal zoomLevel() const;
+ void dragStarted();
+ void dragEnded();
+
Q_SIGNALS:
void coordinateChanged();
void sourceItemChanged();
@@ -83,17 +86,21 @@ Q_SIGNALS:
protected Q_SLOTS:
void update();
+ // from qquickitem
+ void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
private Q_SLOTS:
void coordinateCoordinateChanged(double);
private:
QDeclarativeCoordinate* coordinate_;
+ QDeclarativeCoordinate internalCoordinate_;
QQuickItem* sourceItem_;
QPointF anchorPoint_;
qreal zoomLevel_;
bool inUpdate_;
bool mapAndSourceItemSet_;
+ bool dragActive_;
};
QT_END_NAMESPACE
diff --git a/src/imports/location/qdeclarativepolylinemapitem.cpp b/src/imports/location/qdeclarativepolylinemapitem.cpp
index a2523d6a..3fc2934b 100644
--- a/src/imports/location/qdeclarativepolylinemapitem.cpp
+++ b/src/imports/location/qdeclarativepolylinemapitem.cpp
@@ -40,10 +40,11 @@
****************************************************************************/
#include "qdeclarativepolylinemapitem_p.h"
-#include "qdeclarativegeomapquickitem_p.h"
#include <QDeclarativeInfo>
#include <QPainter>
+QT_BEGIN_NAMESPACE
+
static QPainterPath createPath(const Map& map, const QList<QGeoCoordinate> &path, qreal& w,
qreal& h)
{
@@ -53,14 +54,12 @@ static QPainterPath createPath(const Map& map, const QList<QGeoCoordinate> &path
//TODO: dateline handling
for (int i = 0; i < path.size(); ++i) {
-
const QGeoCoordinate &coord = path.at(i);
if (!coord.isValid())
continue;
QPointF point = map.coordinateToScreenPosition(coord, false);
-
if (i == 0) {
minX = point.x();
maxX = point.x();
@@ -86,9 +85,13 @@ static QPainterPath createPath(const Map& map, const QList<QGeoCoordinate> &path
}
QDeclarativePolylineMapItem::QDeclarativePolylineMapItem(QQuickItem *parent) :
- QDeclarativeGeoMapItemBase(parent), quickItem_(new QDeclarativeGeoMapQuickItem(this)), polylineMapPaintedItem_(
- new PolylineMapPaintedItem(quickItem_)), initialized_(false)
+ QDeclarativeGeoMapItemBase(parent),
+ polylineItem_(new PolylineMapPaintedItem(this)),
+ initialized_(false),
+ inUpdate_(false),
+ zoomLevel_(0.0)
{
+ polylineItem_->setParentItem(this);
}
QDeclarativePolylineMapItem::~QDeclarativePolylineMapItem()
@@ -97,7 +100,7 @@ QDeclarativePolylineMapItem::~QDeclarativePolylineMapItem()
void QDeclarativePolylineMapItem::componentComplete()
{
- initialized_ = true;
+ //initialized_ = true;
}
QDeclarativeListProperty<QDeclarativeCoordinate> QDeclarativePolylineMapItem::declarativePath()
@@ -112,9 +115,9 @@ void QDeclarativePolylineMapItem::path_append(
QDeclarativePolylineMapItem* item = qobject_cast<QDeclarativePolylineMapItem*>(
property->object);
item->path_.append(coordinate);
- QList<QGeoCoordinate> p = item->polylineMapPaintedItem_->path();
+ QList<QGeoCoordinate> p = item->polylineItem_->path();
p.append(coordinate->coordinate());
- item->polylineMapPaintedItem_->setPath(p);
+ item->polylineItem_->setPath(p);
if (item->initialized_)
emit item->pathChanged();
}
@@ -138,7 +141,7 @@ void QDeclarativePolylineMapItem::path_clear(
property->object);
qDeleteAll(item->path_);
item->path_.clear();
- item->polylineMapPaintedItem_->setPath(QList<QGeoCoordinate>());
+ item->polylineItem_->setPath(QList<QGeoCoordinate>());
if (item->initialized_)
emit item->pathChanged();
}
@@ -146,9 +149,9 @@ void QDeclarativePolylineMapItem::path_clear(
void QDeclarativePolylineMapItem::addCoordinate(QDeclarativeCoordinate* coordinate)
{
path_.append(coordinate);
- QList<QGeoCoordinate> path = polylineMapPaintedItem_->path();
+ QList<QGeoCoordinate> path = polylineItem_->path();
path.append(coordinate->coordinate());
- polylineMapPaintedItem_->setPath(path);
+ polylineItem_->setPath(path);
emit pathChanged();
}
@@ -161,39 +164,66 @@ void QDeclarativePolylineMapItem::removeCoordinate(QDeclarativeCoordinate* coord
return;
}
- QList<QGeoCoordinate> path = polylineMapPaintedItem_->path();
+ QList<QGeoCoordinate> path = polylineItem_->path();
if (path.count() < index + 1) {
qmlInfo(this) << tr("Coordinate does not belong to PolylineMapItem.");
return;
}
path.removeAt(index);
- polylineMapPaintedItem_->setPath(path);
+ polylineItem_->setPath(path);
path_.removeAt(index);
emit pathChanged();
}
void QDeclarativePolylineMapItem::update()
{
- if (!map())
+ if (inUpdate_ || !map())
return;
- quickItem_->setCoordinate(
- new QDeclarativeCoordinate(polylineMapPaintedItem_->quickItemCoordinate()));
- quickItem_->setAnchorPoint(polylineMapPaintedItem_->quickItemAnchorPoint());
-
- if (quickItem_->sourceItem() == 0) {
- QObject::connect(map(), SIGNAL(cameraDataChanged(CameraData)), this,
- SLOT(handleCameraDataChanged(CameraData)));
- polylineMapPaintedItem_->setMap(map());
- quickItem_->setMap(quickMap(), map());
- quickItem_->setSourceItem(polylineMapPaintedItem_);
+ inUpdate_ = true;
+ QPointF topLeft = map()->coordinateToScreenPosition(
+ polylineItem_->quickItemCoordinate(), false) - polylineItem_->quickItemAnchorPoint();
+ if ((topLeft.x() > quickMap()->width())
+ || (topLeft.x() + width() < 0)
+ || (topLeft.y() + height() < 0)
+ || (topLeft.y() > quickMap()->height())) {
+ setPos(map()->coordinateToScreenPosition(QGeoCoordinate()));
+ } else {
+ setWidth(polylineItem_->width());
+ setHeight(polylineItem_->height());
+ setPos(topLeft);
+ }
+ // optimize this check/calls, need to be done only when map changes:
+ if (!polylineItem_->map()) {
+ polylineItem_->setMap(map());
+ connect(map(), SIGNAL(cameraDataChanged(CameraData)), this, SLOT(handleCameraDataChanged(CameraData)));
}
+ inUpdate_ = false;
+}
+
+void QDeclarativePolylineMapItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ // TODO - if X and Y of the wrapper item are changed, currently
+ // the item moves, but returns to old position when map camera changes
+ QQuickItem::geometryChanged(newGeometry, oldGeometry);
+}
+
+void QDeclarativePolylineMapItem::dragStarted()
+{
+ qmlInfo(this) << "warning: mouse dragging is not currently supported with polylines/routes.";
+}
+
+bool QDeclarativePolylineMapItem::contains(QPointF point)
+{
+ // todo this currently returns all points _inside_ of the implicitly closed
+ // painterpath whereas we are only interested in the outlines of it
+ return polylineItem_->contains(point);
}
void QDeclarativePolylineMapItem::handleCameraDataChanged(const CameraData& cameraData)
{
- polylineMapPaintedItem_->setZoomLevel(cameraData.zoomFactor());
+ polylineItem_->setZoomLevel(cameraData.zoomFactor());
update();
}
@@ -208,7 +238,7 @@ void QDeclarativePolylineMapItem::setColor(const QColor &color)
return;
color_ = color;
- polylineMapPaintedItem_->setPen(color);
+ polylineItem_->setPen(color);
emit colorChanged(color_);
}
@@ -231,6 +261,11 @@ void PolylineMapPaintedItem::setMap(Map* map)
map_ = map;
}
+Map* PolylineMapPaintedItem::map()
+{
+ return map_;
+}
+
void PolylineMapPaintedItem::setZoomLevel(qreal zoomLevel)
{
if (zoomLevel_ == zoomLevel)
@@ -245,6 +280,11 @@ qreal PolylineMapPaintedItem::zoomLevel() const
return zoomLevel_;
}
+bool PolylineMapPaintedItem::contains(QPointF point)
+{
+ return path_.contains(point);
+}
+
void PolylineMapPaintedItem::setPath(const QList<QGeoCoordinate>& path)
{
coordPath_ = path;
@@ -299,7 +339,7 @@ void PolylineMapPaintedItem::updateGeometry()
{
initialized_ = false;
- if (!map_)
+ if (!map())
return;
if (coordPath_.size() == 0)
@@ -308,8 +348,6 @@ void PolylineMapPaintedItem::updateGeometry()
if (zoomLevel_ == -1)
return;
- QPointF point = map_->coordinateToScreenPosition(coordPath_.at(0), false);
-
qreal w = 0;
qreal h = 0;
@@ -325,4 +363,7 @@ void PolylineMapPaintedItem::updateGeometry()
initialized_ = true;
update();
+
}
+
+QT_END_NAMESPACE
diff --git a/src/imports/location/qdeclarativepolylinemapitem_p.h b/src/imports/location/qdeclarativepolylinemapitem_p.h
index d10d49f8..94a9cc32 100644
--- a/src/imports/location/qdeclarativepolylinemapitem_p.h
+++ b/src/imports/location/qdeclarativepolylinemapitem_p.h
@@ -51,7 +51,6 @@
QT_BEGIN_NAMESPACE
class PolylineMapPaintedItem;
-class QDeclarativeGeoMapQuickItem;
class QDeclarativePolylineMapItem : public QDeclarativeGeoMapItemBase
{
@@ -74,13 +73,17 @@ public:
QColor color() const;
void setColor(const QColor &color);
+ void dragStarted();
+ bool contains(QPointF point);
+
Q_SIGNALS:
void pathChanged();
void colorChanged(const QColor &color);
-
protected Q_SLOTS:
void update();
+ // from qquickitem
+ void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
private Q_SLOTS:
// map size changed
@@ -94,11 +97,12 @@ private:
void pathPropertyChanged();
private:
- QDeclarativeGeoMapQuickItem *quickItem_;
- PolylineMapPaintedItem *polylineMapPaintedItem_;
+ PolylineMapPaintedItem *polylineItem_;
QList<QDeclarativeCoordinate*> path_;
QColor color_;
bool initialized_;
+ bool inUpdate_;
+ bool zoomLevel_;
};
//////////////////////////////////////////////////////////////////////
@@ -112,6 +116,7 @@ public:
~PolylineMapPaintedItem();
void setMap(Map* map);
+ Map* map();
void setZoomLevel(qreal zoomLevel);
qreal zoomLevel() const;
@@ -127,18 +132,19 @@ public:
QBrush brush() const;
void setBrush(const QBrush &brush);
+ bool contains(QPointF point);
+
QGeoCoordinate quickItemCoordinate() const;
QPointF quickItemAnchorPoint() const;
private:
void updateGeometry();
-
Map *map_;
qreal zoomLevel_;
- QGeoCoordinate quickItemCoordinate_;
- QPointF quickItemAnchorPoint_;
QPen pen_;
QBrush brush_;
+ QGeoCoordinate quickItemCoordinate_;
+ QPointF quickItemAnchorPoint_;
QList<QGeoCoordinate> coordPath_;
QPainterPath path_;
bool initialized_;
diff --git a/src/imports/location/qdeclarativerectanglemapitem.cpp b/src/imports/location/qdeclarativerectanglemapitem.cpp
index 36fa9d70..ac01adeb 100644
--- a/src/imports/location/qdeclarativerectanglemapitem.cpp
+++ b/src/imports/location/qdeclarativerectanglemapitem.cpp
@@ -40,14 +40,20 @@
****************************************************************************/
#include "qdeclarativerectanglemapitem_p.h"
-#include "qdeclarativegeomapquickitem_p.h"
#include <QPainter>
+QT_BEGIN_NAMESPACE
+
QDeclarativeRectangleMapItem::QDeclarativeRectangleMapItem(QQuickItem *parent)
-: QDeclarativeGeoMapItemBase(parent), quickItem_(new QDeclarativeGeoMapQuickItem(this)),
- rectangleMapPaintedItem_(new RectangleMapPaintedItem(quickItem_)), topLeft_(0),
- bottomRight_(0)
+: QDeclarativeGeoMapItemBase(parent),
+ rectangleItem_(new RectangleMapPaintedItem(this)),
+ topLeft_(0),
+ bottomRight_(0),
+ zoomLevel_(0.0),
+ inUpdate_(false),
+ dragActive_(false)
{
+ rectangleItem_->setParentItem(this);
}
QDeclarativeRectangleMapItem::~QDeclarativeRectangleMapItem()
@@ -62,9 +68,9 @@ void QDeclarativeRectangleMapItem::setTopLeft(QDeclarativeCoordinate *topLeft)
topLeft_->disconnect(this);
topLeft_ = topLeft;
if (!topLeft_) {
- rectangleMapPaintedItem_->setTopLeft(QGeoCoordinate());
+ rectangleItem_->setTopLeft(QGeoCoordinate());
} else {
- rectangleMapPaintedItem_->setTopLeft(topLeft_->coordinate());
+ rectangleItem_->setTopLeft(topLeft_->coordinate());
connect(topLeft_, SIGNAL(latitudeChanged(double)), this,
SLOT(handleTopLeftCoordinateChanged()));
connect(topLeft_, SIGNAL(longitudeChanged(double)), this,
@@ -88,9 +94,9 @@ void QDeclarativeRectangleMapItem::setBottomRight(QDeclarativeCoordinate *bottom
bottomRight_->disconnect(this);
bottomRight_ = bottomRight;
if (!bottomRight_) {
- rectangleMapPaintedItem_->setBottomRight(QGeoCoordinate());
+ rectangleItem_->setBottomRight(QGeoCoordinate());
} else {
- rectangleMapPaintedItem_->setBottomRight(bottomRight_->coordinate());
+ rectangleItem_->setBottomRight(bottomRight_->coordinate());
connect(bottomRight_, SIGNAL(latitudeChanged(double)), this,
SLOT(handleBottomRightCoordinateChanged()));
connect(bottomRight_, SIGNAL(longitudeChanged(double)), this,
@@ -108,37 +114,80 @@ QDeclarativeCoordinate* QDeclarativeRectangleMapItem::bottomRight()
void QDeclarativeRectangleMapItem::update()
{
- if (!map())
+ if (inUpdate_ || !map())
return;
- quickItem_->setCoordinate(
- new QDeclarativeCoordinate(rectangleMapPaintedItem_->quickItemCoordinate()));
- quickItem_->setAnchorPoint(rectangleMapPaintedItem_->quickItemAnchorPoint());
+ inUpdate_ = true;
+
+ QPointF topLeft = map()->coordinateToScreenPosition(rectangleItem_->topLeft(), false);
+ if ((topLeft.x() > quickMap()->width())
+ || (topLeft.x() + width() < 0)
+ || (topLeft.y() + height() < 0)
+ || (topLeft.y() > quickMap()->height())) {
+ setPos(map()->coordinateToScreenPosition(QGeoCoordinate()));
+ } else {
+ setWidth(rectangleItem_->width());
+ setHeight(rectangleItem_->height());
+ setPos(topLeft);
+ }
+ // optimize this check/calls, need to be done only when map changes:
+ if (!rectangleItem_->map()) {
+ rectangleItem_->setMap(map());
+ connect(map(), SIGNAL(cameraDataChanged(CameraData)), this, SLOT(handleCameraDataChanged(CameraData)));
+ }
+ inUpdate_ = false;
+}
- if (quickItem_->sourceItem() == 0) {
- QObject::connect(map(), SIGNAL(cameraDataChanged(CameraData)), this,
- SLOT(handleCameraDataChanged(CameraData)));
- rectangleMapPaintedItem_->setMap(map());
- quickItem_->setMap(quickMap(), map());
- quickItem_->setSourceItem(rectangleMapPaintedItem_);
+void QDeclarativeRectangleMapItem::dragEnded()
+{
+ if (!dragActive_)
+ return;
+ dragActive_ = false;
+ QPointF newTopLeftPoint = QPointF(x(),y());
+ // does not preserve exact projection geometry but that should be acceptable
+ QGeoCoordinate newTopLeft = map()->screenPositionToCoordinate(newTopLeftPoint, false);
+ QPointF newBottomRightPoint = QPointF(x() + width(), y() + height());
+ QGeoCoordinate newBottomRight = map()->screenPositionToCoordinate(newBottomRightPoint, false);
+ if (newTopLeft.isValid() && newBottomRight.isValid()) {
+ internalTopLeft_.setCoordinate(newTopLeft);
+ internalBottomRight_.setCoordinate(newBottomRight);
+ setTopLeft(&internalTopLeft_);
+ setBottomRight(&internalBottomRight_);
}
}
+void QDeclarativeRectangleMapItem::dragStarted()
+{
+ dragActive_ = true;
+}
+
void QDeclarativeRectangleMapItem::handleCameraDataChanged(const CameraData& cameraData)
{
- rectangleMapPaintedItem_->setZoomLevel(cameraData.zoomFactor());
+ rectangleItem_->setZoomLevel(cameraData.zoomFactor());
update();
}
+bool QDeclarativeRectangleMapItem::contains(QPointF point)
+{
+ return rectangleItem_->contains(point);
+}
+
+void QDeclarativeRectangleMapItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ // TODO - if X and Y of the wrapper item are changed, currently
+ // the item moves, but returns to old position when map camera changes
+ QQuickItem::geometryChanged(newGeometry, oldGeometry);
+}
+
void QDeclarativeRectangleMapItem::handleTopLeftCoordinateChanged()
{
- rectangleMapPaintedItem_->setTopLeft(topLeft_->coordinate());
+ rectangleItem_->setTopLeft(topLeft_->coordinate());
emit topLeftChanged(topLeft_);
}
void QDeclarativeRectangleMapItem::handleBottomRightCoordinateChanged()
{
- rectangleMapPaintedItem_->setBottomRight(bottomRight_->coordinate());
+ rectangleItem_->setBottomRight(bottomRight_->coordinate());
emit bottomRightChanged(bottomRight_);
}
@@ -154,7 +203,7 @@ void QDeclarativeRectangleMapItem::setColor(const QColor &color)
color_ = color;
QBrush m_brush(color);
- rectangleMapPaintedItem_->setBrush(m_brush);
+ rectangleItem_->setBrush(m_brush);
emit colorChanged(color_);
}
@@ -177,6 +226,11 @@ void RectangleMapPaintedItem::setMap(Map* map)
map_ = map;
}
+Map* RectangleMapPaintedItem::map()
+{
+ return map_;
+}
+
void RectangleMapPaintedItem::setZoomLevel(qreal zoomLevel)
{
if (zoomLevel_ == zoomLevel)
@@ -259,21 +313,14 @@ void RectangleMapPaintedItem::updateGeometry()
rect_.setTopLeft(QPointF(0, 0));
rect_.setBottomRight(QPointF(w, h));
- quickItemCoordinate_ = topLeftCoord_;
- quickItemAnchorPoint_ = rect_.topLeft();
initialized_ = true;
-
update();
}
-QGeoCoordinate RectangleMapPaintedItem::quickItemCoordinate() const
-{
- return quickItemCoordinate_;
-}
-QPointF RectangleMapPaintedItem::quickItemAnchorPoint() const
+bool RectangleMapPaintedItem::contains(QPointF point)
{
- return quickItemAnchorPoint_;
+ return rect_.contains(point);
}
void RectangleMapPaintedItem::setBrush(const QBrush &brush)
@@ -295,3 +342,5 @@ QPen RectangleMapPaintedItem::pen() const
{
return pen_;
}
+
+QT_END_NAMESPACE
diff --git a/src/imports/location/qdeclarativerectanglemapitem_p.h b/src/imports/location/qdeclarativerectanglemapitem_p.h
index 0b69f927..7aece21d 100644
--- a/src/imports/location/qdeclarativerectanglemapitem_p.h
+++ b/src/imports/location/qdeclarativerectanglemapitem_p.h
@@ -51,7 +51,6 @@
QT_BEGIN_NAMESPACE
class RectangleMapPaintedItem;
-class QDeclarativeGeoMapQuickItem;
class QDeclarativeRectangleMapItem: public QDeclarativeGeoMapItemBase
{
@@ -74,6 +73,10 @@ public:
QColor color() const;
void setColor(const QColor &color);
+ void dragStarted();
+ void dragEnded();
+ bool contains(QPointF point);
+
Q_SIGNALS:
void topLeftChanged(const QDeclarativeCoordinate *topLeft);
void bottomRightChanged(const QDeclarativeCoordinate *bottomRight);
@@ -81,6 +84,8 @@ Q_SIGNALS:
protected Q_SLOTS:
void update();
+ // from qquickitem
+ void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
private Q_SLOTS:
// map size changed
@@ -89,11 +94,15 @@ private Q_SLOTS:
void handleBottomRightCoordinateChanged();
private:
- QDeclarativeGeoMapQuickItem *quickItem_;
- RectangleMapPaintedItem *rectangleMapPaintedItem_;
+ RectangleMapPaintedItem *rectangleItem_;
QDeclarativeCoordinate* topLeft_;
QDeclarativeCoordinate* bottomRight_;
+ QDeclarativeCoordinate internalTopLeft_;
+ QDeclarativeCoordinate internalBottomRight_;
QColor color_;
+ qreal zoomLevel_;
+ bool inUpdate_;
+ bool dragActive_;
};
//////////////////////////////////////////////////////////////////////
@@ -107,6 +116,7 @@ public:
~RectangleMapPaintedItem();
void setMap(Map* map);
+ Map* map();
void setZoomLevel(qreal zoomLevel);
qreal zoomLevel() const;
@@ -125,8 +135,7 @@ public:
QBrush brush() const;
void setBrush(const QBrush &brush);
- QGeoCoordinate quickItemCoordinate() const;
- QPointF quickItemAnchorPoint() const;
+ bool contains(QPointF point);
private:
void updateGeometry();
diff --git a/tests/applications/declarative_map/map3d.qml b/tests/applications/declarative_map/map3d.qml
index cd075a33..2b238045 100644
--- a/tests/applications/declarative_map/map3d.qml
+++ b/tests/applications/declarative_map/map3d.qml
@@ -43,12 +43,14 @@ import QtLocation 5.0
import QtLocation.test 5.0
import "common" as Common
-Item {
+import Qt3D 1.0
+import Qt.multimediakit 4.0
+
+Rectangle {
objectName: "The page."
- width: 1140 //360
- height: 1085 // 640
- //width: 360
- //height: 640
+ color: 'yellow'
+ width: 1140
+ height: 1085
id: page
// From location.test plugin
@@ -214,16 +216,15 @@ Item {
Map {
id: map
property bool disableFlickOnStarted: false
- x: 0
- y: 0
+ x: 10
+ y: 10
MapMouseArea {
id: mapMouseArea
- onDoubleClicked: console.log('mapmousearea got doubleclicked')
anchors.fill: parent
- onClicked: console.log('coordinate lat: ' + mapMouseArea.mouseToCoordinate(mouse).latitude +
- 'coordinate lon: ' + mapMouseArea.mouseToCoordinate(mouse).longitude +
- ' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x +
- ' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
+ onClicked: console.log('.....[Map]..... mouse area of maps clicked, coordinate lat: ' + mapMouseArea.mouseToCoordinate(mouse).latitude +
+ 'coordinate lon: ' + mapMouseArea.mouseToCoordinate(mouse).longitude);
+ //' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x +
+ //' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
}
/*
MapItem {
@@ -244,12 +245,100 @@ Item {
}
}
*/
+
+
MapCircle {
+ id: mapCircle
+ z: 5
center: londonCoordinate
- radius: 1000
+ radius: 10000
color: 'red'
+
+ MapMouseArea {
+ id: mouseAreaOfMapCircle
+ anchors.fill: parent
+ drag.target: parent
+ onClicked: console.log('....[Circle].... map mouse area of circle clicked')
+ }
+ Column {
+ spacing: 2
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black';
+ text: ' MapCircle '}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black';
+ text: ' x: ' + mapCircle.x}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black';
+ text: ' y: ' + mapCircle.y}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black'; elide: Text.ElideRight; width: mapCircle.width + 30;
+ text: ' c lat: ' + mapCircle.center.latitude}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black'; elide: Text.ElideRight; width: mapCircle.width + 30;
+ text: ' c lon: ' + mapCircle.center.longitude}
+ }
+ }
+
+ Coordinate { id: southEastLondonCoordinate; latitude: 51.2; longitude: 0.3 }
+
+ MapPolyline {
+ id: mapPolyline
+ z: 15
+ color: 'red'
+ path: [
+ Coordinate { id: pathCoord1; latitude: 51; longitude: 0.1},
+ Coordinate { id: pathCoord2; latitude: 51.1; longitude: 0.4},
+ Coordinate { id: pathCoord3; latitude: 51.2; longitude: 0.2}
+ ]
+ MapMouseArea {
+ id: mouseAreaOfMapPolyline
+ anchors.fill: parent
+ drag.target: parent
+ onClicked: console.log('....[Polyline].... map mouse area of polyline clicked')
+ }
+ Column {
+ spacing: 2
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black';
+ text: ' MapPolyline '}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black';
+ text: ' x: ' + mapPolyline.x}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black';
+ text: ' y: ' + mapPolyline.y}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black'; elide: Text.ElideRight; width: mapPolyline.width + 30;
+ text: ' at(0) lat: ' + mapPolyline.path[0].latitude}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black'; elide: Text.ElideRight; width: mapPolyline.width + 30;
+ text: ' at(0) lon: ' + mapPolyline.path[0].longitude}
+ }
+ }
+
+ MapRectangle {
+ id: mapRectangle
+ z: 5
+ topLeft: londonCoordinate
+ bottomRight: southEastLondonCoordinate
+ color: 'green'
+ MapMouseArea {
+ id: mouseAreaOfMapRectangle
+ anchors.fill: parent
+ drag.target: parent
+ onClicked: console.log('....[Rectangle].... map mouse area of rectangle clicked')
+ }
+ Column {
+ spacing: 2
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black';
+ text: ' MapRectangle '}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black';
+ text: ' x: ' + mapRectangle.x}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black';
+ text: ' y: ' + mapRectangle.y}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black'; elide: Text.ElideRight; width: mapRectangle.width - 10;
+ text: ' tl lat: ' + mapRectangle.topLeft.latitude}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black'; elide: Text.ElideRight; width: mapRectangle.width - 10;
+ text: ' tl lon: ' + mapRectangle.topLeft.longitude}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black'; elide: Text.ElideRight; width: mapRectangle.width - 10;
+ text: ' br lat: ' + mapRectangle.bottomRight.latitude}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black'; elide: Text.ElideRight; width: mapRectangle.width - 10;
+ text: ' br lon: ' + mapRectangle.bottomRight.longitude}
+ }
}
+ /*
MapQuickItem {
objectName: "blinky quick item 1"
coordinate: Coordinate { latitude: -19; longitude : 146 }
@@ -260,70 +349,144 @@ Item {
source: "blinky.gif"
}
}
+ */
Coordinate {id: londonCoordinate; latitude: 51.5; longitude: -0.11}
+
+ /*
+ MapQuickItem {
+ objectName: "mousetestrectanglelower yellow"
+ coordinate: londonCoordinate
+ MapMouseArea {
+ anchors.fill: parent
+ onClicked: console.log('....... yellow map mouse clicked at x: ' + mouse.x + ' y: ' + mouse.y)
+ }
+ sourceItem: Rectangle {
+ width: 160
+ height: 160
+ color: 'yellow'
+ }
+ }
+ */
+
MapQuickItem {
+ objectName: "mousetestrectangleupper purple"
+ id: purpleRectMapItem
+ coordinate: londonCoordinate
+
MapMouseArea {
id: mapMouseAreaUpperPurple
- z: 100
objectName: 'mapMouseAreaUpperPurple'
- width: rectangleSourceItem.width
- height: rectangleSourceItem.height
- x: rectangleSourceItem.x
- y: rectangleSourceItem.y
+ anchors.fill: parent
+ //z: 100
+ drag.target: parent
onClicked: {
- console.log('..... map mouse clicked() area upper coordinate: ' + mapMouseAreaUpperPurple.mouseToCoordinate(mouse).latitude + ' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x + ' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
- rectangleSourceItem.width -= 5
- rectangleSourceItem.height -= 5
+ console.log('....[purple]..... purple map mouse clicked() area upper coordinate: ' + mapMouseAreaUpperPurple.mouseToCoordinate(mouse).latitude + ' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x + ' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
}
onPressed: {
- console.log('..... map mouse pressed() area upper coordinate: ' + mapMouseAreaUpperPurple.mouseToCoordinate(mouse).latitude + ' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x + ' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
+ console.log('....[purple]..... map mouse pressed() area purple coordinate: ' + mapMouseAreaUpperPurple.mouseToCoordinate(mouse).latitude + ' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x + ' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
}
onReleased: {
- console.log('..... map mouse released() area upper coordinate: ' + mapMouseAreaUpperPurple.mouseToCoordinate(mouse).latitude + ' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x + ' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
+ console.log('....[purple]..... map mouse released() area purple coordinate: ' + mapMouseAreaUpperPurple.mouseToCoordinate(mouse).latitude + ' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x + ' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
}
onDoubleClicked: {
- console.log('..... map mouse doubleClicked() area upper coordinate: ' + mapMouseAreaUpperPurple.mouseToCoordinate(mouse).latitude + ' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x + ' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
- }
- onPositionChanged: {
- console.log('..... map mouse positionChanged() area upper coordinate: ' + mapMouseAreaUpperPurple.mouseToCoordinate(mouse).latitude + ' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x + ' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
+ console.log('....[purple]..... map mouse doubleClicked() area purple coordinate: ' + mapMouseAreaUpperPurple.mouseToCoordinate(mouse).latitude + ' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x + ' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
}
+ //onPositionChanged: {
+ // console.log('....[purple]..... map mouse positionChanged() area purple coordinate: ' + mapMouseAreaUpperPurple.mouseToCoordinate(mouse).latitude + ' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x + ' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
+ //}
onPressAndHold: {
- console.log('..... map mouse pressAndHold() area upper coordinate: ' + mapMouseAreaUpperPurple.mouseToCoordinate(mouse).latitude + ' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x + ' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
+ console.log('....[purple]..... map mouse pressAndHold() area purple coordinate: ' + mapMouseAreaUpperPurple.mouseToCoordinate(mouse).latitude + ' to screen pos: ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).x + ' ' + map.toScreenPosition(mapMouseAreaUpperPurple.mouseToCoordinate(mouse)).y)
}
onEntered: {
- console.log('..... map mouse entered()')
+ console.log('....[purple]..... map mouse area purple entered()')
}
onExited: {
- console.log('..... map mouse exited()')
+ console.log('....[purple]..... map mouse area purple exited()')
}
}
- z: 2
- objectName: "mousetestrectangleupper"
- coordinate: londonCoordinate
sourceItem: Rectangle {
id: rectangleSourceItem
- width: 80
- height: 80
+ width: 200
+ height: 200
color: 'purple'
+ Column {
+ spacing: 2
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black';
+ text: ' MapQuickItem '}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black';
+ text: ' x: ' + purpleRectMapItem.x}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black';
+ text: ' y: ' + purpleRectMapItem.y}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black'; elide: Text.ElideRight; width: purpleRectMapItem.width - 30;
+ text: ' c lat: ' + purpleRectMapItem.coordinate.latitude}
+ Text { color: 'yellow'; font.bold: true; style: Text.Outline; styleColor: 'black'; elide: Text.ElideRight; width: purpleRectMapItem.width - 30;
+ text: ' c lon: ' + purpleRectMapItem.coordinate.longitude}
+ }
}
}
+
+ /*
MapQuickItem {
- z: 1
- objectName: "mousetestrectanglelower"
+ z: 10
+ objectName: "video item"
coordinate: londonCoordinate
sourceItem: Rectangle {
- width: 160
- height: 160
- color: 'yellow'
+ color: "green"
+ width: 200;
+ height: 200;
+ MediaPlayer {
+ id: player
+ source: "file:///home/juvuolle/Downloads/Big_Buck_Bunny_Trailer_400p.ogg.ogv"
+ playing: true
+ }
+ VideoOutput {
+ id: videoItem
+ source: player
+ anchors.fill: parent
+ }
}
}
+ */
-
-
-
+/*
+ MapQuickItem {
+ z: 11
+ objectName: "3d item"
+ coordinate: londonCoordinate
+ sourceItem: Item {//Rectangle {
+ width: 200
+ height: 200
+ //color: Qt.rgba(0, 0, 1, 0)
+ Viewport {
+ width: 200
+ height: 200
+ Item3D {
+ mesh: Mesh { source: "file:///home/juvuolle/qt/qt5/qtlocation/tests/applications/declarative_map/basket.bez" }
+ effect: Effect { texture: "file:///home/juvuolle/qt/qt5/qtlocation/tests/applications/declarative_map/basket.jpg" }
+ //! [2]
+ //! [3]
+
+ transform: [
+ Scale3D { scale: 1.5 },
+ Rotation3D {
+ axis: Qt.vector3d(0, 1, 0)
+ NumberAnimation on angle {
+ running: true
+ loops: Animation.Infinite
+ from: 0
+ to: 360
+ duration: 2000
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+*/
/*
MapQuickItem {
objectName: "blinky quick item 2"
@@ -359,6 +522,7 @@ Item {
}
*/
+ /*
MapItemView {
id: theObjectView
model: testModel
@@ -395,6 +559,7 @@ Item {
}
}
}
+ */
// From location.test plugin
PinchGenerator {
@@ -429,16 +594,87 @@ Item {
anchors.top: infoText.bottom
columns: 3
spacing: 2
- Rectangle { id: navRect; width: 50; height: 50; color: 'peru'; Text {text: "\u2196";} MouseArea {anchors.fill: parent; onClicked: { map.pan(-1,1)}}}
- Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2191";} MouseArea {anchors.fill: parent; onClicked: {map.pan(0,1)}}}
- Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2197";} MouseArea {anchors.fill: parent; onClicked: {map.pan(1,1)}}}
- Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2190";} MouseArea {anchors.fill: parent; onClicked: {map.pan(-1,0)}}}
- Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "Tickle";} MouseArea {anchors.fill: parent; onClicked: {console.log('ticle tickle hehehe')}}}
- Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2192";} MouseArea {anchors.fill: parent; onClicked: {map.pan(1,0)}}}
- Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2199";} MouseArea {anchors.fill: parent; onClicked: {map.pan(-1,-1)}}}
- Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2193";} MouseArea {anchors.fill: parent; onClicked: {map.pan(0,-1)}}}
- Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2198";} MouseArea {anchors.fill: parent; onClicked: {map.pan(1,-1)}}}
+ Rectangle { id: navRect; width: 50; height: 50; color: 'peru'; Text {text: "\u2196";} MouseArea {anchors.fill: parent; onClicked: { map.pan(-5,5)}}}
+ Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2191";} MouseArea {anchors.fill: parent; onClicked: {map.pan(0,5)}}}
+ Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2197";} MouseArea {anchors.fill: parent; onClicked: {map.pan(5,5)}}}
+ Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2190";} MouseArea {anchors.fill: parent; onClicked: {map.pan(-5,0)}}}
+ Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "Pan\nMap";} MouseArea {anchors.fill: parent; onClicked: {console.log('ticle tickle hehehe')}}}
+ Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2192";} MouseArea {anchors.fill: parent; onClicked: {map.pan(5,0)}}}
+ Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2199";} MouseArea {anchors.fill: parent; onClicked: {map.pan(-5,-5)}}}
+ Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2193";} MouseArea {anchors.fill: parent; onClicked: {map.pan(0,-5)}}}
+ Rectangle { width: navRect.width; height: navRect.height; color: navRect.color; Text {text: "\u2198";} MouseArea {anchors.fill: parent; onClicked: {map.pan(5,-5)}}}
+ }
+
+ Grid {
+ id: itemMover
+ z: 10
+ anchors.top: panNav.bottom
+ columns: 3
+ spacing: 2
+ property variant target: mapCircle
+
+ Rectangle { id: itemMoverRect; width: 50; height: 50; color: 'peru'; Text {text: "\u2196";} MouseArea {anchors.fill: parent; onClicked: { itemMover.target.y -= 5; itemMover.target.x -= 5 }}}
+ Rectangle { width: itemMoverRect.width; height: itemMoverRect.height; color: itemMoverRect.color; Text {text: "\u2191";} MouseArea {anchors.fill: parent; onClicked: {itemMover.target.y -= 5}}}
+ Rectangle { width: itemMoverRect.width; height: itemMoverRect.height; color: itemMoverRect.color; Text {text: "\u2197";} MouseArea {anchors.fill: parent; onClicked: {itemMover.target.y -= 5; itemMover.target.x += 5}}}
+ Rectangle { width: itemMoverRect.width; height: itemMoverRect.height; color: itemMoverRect.color; Text {text: "\u2190";} MouseArea {anchors.fill: parent; onClicked: {itemMover.target.x -= 5}}}
+ Rectangle { width: itemMoverRect.width; height: itemMoverRect.height; color: itemMoverRect.color; Text {text: "Move\nCircle";} MouseArea {anchors.fill: parent; onClicked: {console.log('ticle tickle hehehe')}}}
+ Rectangle { width: itemMoverRect.width; height: itemMoverRect.height; color: itemMoverRect.color; Text {text: "\u2192";} MouseArea {anchors.fill: parent; onClicked: {itemMover.target.x += 5}}}
+ Rectangle { width: itemMoverRect.width; height: itemMoverRect.height; color: itemMoverRect.color; Text {text: "\u2199";} MouseArea {anchors.fill: parent; onClicked: {itemMover.target.x -= 5; itemMover.target.y += 5}}}
+ Rectangle { width: itemMoverRect.width; height: itemMoverRect.height; color: itemMoverRect.color; Text {text: "\u2193";} MouseArea {anchors.fill: parent; onClicked: {itemMover.target.y += 5}}}
+ Rectangle { width: itemMoverRect.width; height: itemMoverRect.height; color: itemMoverRect.color; Text {text: "\u2198";} MouseArea {anchors.fill: parent; onClicked: {itemMover.target.y += 5; itemMover.target.x += 5}}}
+ }
+
+ Rectangle {
+ id: itemDataBackground
+ opacity: 0.8
+ anchors.top: itemMover.bottom
+ anchors.bottom: rectangleData.bottom
+ width: itemMover.width
+ }
+ Column {
+ id: circleData;
+ anchors.top: itemMover.bottom
+ spacing: 1
+ Text { text: ' MapCircle '; font.bold: true; font.pixelSize: 10; }
+ Text { text: ' x: ' + mapCircle.x; font.pixelSize: 10; }
+ Text { text: ' y: ' + mapCircle.y; font.pixelSize: 10; }
+ Text { text: ' c lat: ' + mapCircle.center.latitude; font.pixelSize: 10; }
+ Text { text: ' c lon: ' + mapCircle.center.longitude; font.pixelSize: 10; }
+ }
+ Column {
+ id: polylineData;
+ anchors.top: circleData.bottom
+ spacing: 1
+ Text { text: ' MapPolyline '; font.bold: true;font.pixelSize: 10; }
+ Text { text: ' x: ' + mapPolyline.x; font.pixelSize: 10; }
+ Text {text: ' y: ' + mapPolyline.y; font.pixelSize: 10; }
+ Text {text: ' at(0) lat: ' + mapPolyline.path[0].latitude; font.pixelSize: 10; }
+ Text {text: ' at(0) lon: ' + mapPolyline.path[0].longitude; font.pixelSize: 10; }
+ }
+ Column {
+ id: quickItemData
+ spacing: 1
+ anchors.top: polylineData.bottom
+ Text {text: ' MapQuickItem ';font.bold: true; font.pixelSize: 10; }
+ Text {text: ' x: ' + purpleRectMapItem.x; font.pixelSize: 10; }
+ Text {text: ' y: ' + purpleRectMapItem.y; font.pixelSize: 10; }
+ Text {text: ' tl lat: ' + purpleRectMapItem.coordinate.latitude; font.pixelSize: 10; }
+ Text {text: ' tl lon: ' + purpleRectMapItem.coordinate.longitude; font.pixelSize: 10; }
}
+ Column {
+ id: rectangleData
+ spacing: 1
+ anchors.top: quickItemData.bottom
+ Text {text: ' MapRectangle '; font.bold: true; font.pixelSize: 10; }
+ Text {text: ' x: ' + mapRectangle.x; font.pixelSize: 10; }
+ Text {text: ' y: ' + mapRectangle.y; font.pixelSize: 10; }
+ Text {text: ' tl lat: ' + mapRectangle.topLeft.latitude; font.pixelSize: 10; }
+ Text {text: ' tl lon: ' + mapRectangle.topLeft.longitude; font.pixelSize: 10; }
+ Text {text: ' br lat: ' + mapRectangle.bottomRight.latitude; font.pixelSize: 10; }
+ Text {text: ' br lon: ' + mapRectangle.bottomRight.longitude; font.pixelSize: 10; }
+ }
+
+
/*
Keys.onPressed: {
@@ -485,6 +721,7 @@ Item {
// Flicking
flick.enabled: true
+ // flick.deceleration: 500
//flick.onFlickStarted: {console.log ('flick started signal F Start ++++++++++++++++++ ') }
//flick.onFlickEnded: {console.log ('flick ended signal F Stop ------------------ ') }
//flick.onMovementStarted: {console.log('movement started signal M Start ++++++++++++++++++ ') }