summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Bremer <wolfgang@w-bremer.de>2015-04-08 01:06:31 +0200
committerWolfgang Bremer <wolfgang.bremer@pelagicore.com>2015-04-20 13:08:05 +0000
commit0c0354911ac2c5807ba3235427bb0a8b57adf092 (patch)
treeea44c64107d1093f0b7045b85c29cd046c2086d2
parentec4c8d4a75a811d5440a297df0d7c6ebb7d56522 (diff)
Remove duplicate code from QDeclarativeRouteMapItem
The QDeclarativeRouteMapItem was more or less a copy of the QDeclarativePolylineMapItem. Now, the RouteMapItem directly inherits from the PolylineMapItem and adds only the route interface. Change-Id: I73e0dddf09ea893b1340c7606cda50de7dc573f1 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r--src/imports/location/qdeclarativepolylinemapitem.cpp14
-rw-r--r--src/imports/location/qdeclarativepolylinemapitem_p.h3
-rw-r--r--src/imports/location/qdeclarativeroutemapitem.cpp137
-rw-r--r--src/imports/location/qdeclarativeroutemapitem_p.h21
4 files changed, 27 insertions, 148 deletions
diff --git a/src/imports/location/qdeclarativepolylinemapitem.cpp b/src/imports/location/qdeclarativepolylinemapitem.cpp
index a5653edd..dade8e22 100644
--- a/src/imports/location/qdeclarativepolylinemapitem.cpp
+++ b/src/imports/location/qdeclarativepolylinemapitem.cpp
@@ -523,10 +523,19 @@ void QDeclarativePolylineMapItem::setPath(const QJSValue &value)
pathList.append(c);
}
- if (path_ == pathList)
+ setPathFromGeoList(pathList);
+}
+
+
+/*!
+ \internal
+*/
+void QDeclarativePolylineMapItem::setPathFromGeoList(const QList<QGeoCoordinate> &path)
+{
+ if (path_ == path)
return;
- path_ = pathList;
+ path_ = path;
geometry_.markSourceDirty();
updateMapItem();
@@ -719,6 +728,7 @@ QSGNode *QDeclarativePolylineMapItem::updateMapItemPaintNode(QSGNode *oldNode, U
node->update(line_.color(), &geometry_);
geometry_.setPreserveGeometry(false);
geometry_.markClean();
+ dirtyMaterial_ = false;
}
return node;
}
diff --git a/src/imports/location/qdeclarativepolylinemapitem_p.h b/src/imports/location/qdeclarativepolylinemapitem_p.h
index e3f49fcd..8822f49d 100644
--- a/src/imports/location/qdeclarativepolylinemapitem_p.h
+++ b/src/imports/location/qdeclarativepolylinemapitem_p.h
@@ -109,7 +109,7 @@ public:
Q_INVOKABLE void removeCoordinate(const QGeoCoordinate &coordinate);
QJSValue path() const;
- void setPath(const QJSValue &value);
+ virtual void setPath(const QJSValue &value);
bool contains(const QPointF &point) const Q_DECL_OVERRIDE;
@@ -120,6 +120,7 @@ Q_SIGNALS:
protected:
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
+ void setPathFromGeoList(const QList<QGeoCoordinate> &path);
protected Q_SLOTS:
virtual void updateMapItem() Q_DECL_OVERRIDE;
diff --git a/src/imports/location/qdeclarativeroutemapitem.cpp b/src/imports/location/qdeclarativeroutemapitem.cpp
index f1d6086b..2e780d4f 100644
--- a/src/imports/location/qdeclarativeroutemapitem.cpp
+++ b/src/imports/location/qdeclarativeroutemapitem.cpp
@@ -78,14 +78,9 @@
QDeclarativeRouteMapItem::QDeclarativeRouteMapItem(QQuickItem *parent)
-: QDeclarativeGeoMapItemBase(parent), route_(0)
+: QDeclarativePolylineMapItem(parent), route_(0)
{
setFlag(ItemHasContents, true);
- line_.setWidth(3.0);
- QObject::connect(&line_, SIGNAL(colorChanged(QColor)),
- this, SLOT(updateAfterLinePropertiesChanged()));
- QObject::connect(&line_, SIGNAL(widthChanged(qreal)),
- this, SLOT(updateAfterLinePropertiesChanged()));
}
QDeclarativeRouteMapItem::~QDeclarativeRouteMapItem()
@@ -93,28 +88,6 @@ QDeclarativeRouteMapItem::~QDeclarativeRouteMapItem()
}
/*!
- \internal
-*/
-void QDeclarativeRouteMapItem::updateAfterLinePropertiesChanged()
-{
- // mark dirty just in case we're a width change
- geometry_.markSourceDirty();
- updateMapItem();
-}
-
-/*!
- \internal
-*/
-void QDeclarativeRouteMapItem::setMap(QDeclarativeGeoMap *quickMap, QGeoMap *map)
-{
- QDeclarativeGeoMapItemBase::setMap(quickMap,map);
- if (map) {
- geometry_.markSourceDirty();
- updateMapItem();
- }
-}
-
-/*!
\qmlproperty Route MapRoute::route
This property holds the route to be drawn which can be used
@@ -132,110 +105,20 @@ void QDeclarativeRouteMapItem::setRoute(QDeclarativeGeoRoute *route)
route_ = route;
- if (route_) {
- path_ = route_->routePath();
- } else {
- path_ = QList<QGeoCoordinate>();
- }
+ if (route_)
+ setPathFromGeoList(route_->routePath());
- geometry_.markSourceDirty();
- updateMapItem();
emit routeChanged(route_);
-
-}
-
-/*!
- \internal
-*/
-QSGNode *QDeclarativeRouteMapItem::updateMapItemPaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
-{
- Q_UNUSED(data);
-
- MapPolylineNode *node = static_cast<MapPolylineNode *>(oldNode);
-
- if (!node) {
- node = new MapPolylineNode();
- }
-
- //TODO: update only material
- if (geometry_.isScreenDirty() || dirtyMaterial_) {
- geometry_.setPreserveGeometry(false);
- node->update(line_.color(), &geometry_);
- geometry_.markClean();
- dirtyMaterial_ = false;
- }
- return node;
-}
-
-/*!
- \qmlpropertygroup Location::MapRoute::line
- \qmlproperty int MapRoute::line.width
- \qmlproperty color MapRoute::line.color
-
- This property is part of the line property group.
- The line property group holds the width and color used to draw the line.
-
- The width is in pixels and is independent of the zoom level of the map.
- The default values correspond to a black border with a width of 1 pixel.
-
- For no line, use a width of 0 or a transparent color.
-*/
-
-QDeclarativeMapLineProperties *QDeclarativeRouteMapItem::line()
-{
- return &line_;
}
/*!
- \internal
-*/
-void QDeclarativeRouteMapItem::updateMapItem()
-{
- if (!map() || path_.isEmpty())
- return;
-
- geometry_.updateSourcePoints(*map(), path_);
- geometry_.updateScreenPoints(*map(), line_.width());
- setWidth(geometry_.sourceBoundingBox().width());
- setHeight(geometry_.sourceBoundingBox().height());
+ \internal void QDeclarativeRouteMapItem::setPath(const QJSValue &value)
- setPositionOnMap(path_.at(0), -1 * geometry_.sourceBoundingBox().topLeft());
- update();
-}
-
-/*!
- \internal
-*/
-void QDeclarativeRouteMapItem::afterViewportChanged(const QGeoMapViewportChangeEvent &event)
-{
- // if the scene is tilted, we must regenerate our geometry every frame
- if (map()->cameraCapabilities().supportsTilting()
- && (event.cameraData.tilt() > 0.1
- || event.cameraData.tilt() < -0.1)) {
- geometry_.markSourceDirty();
- }
-
- // if the scene is rolled, we must regen too
- if (map()->cameraCapabilities().supportsRolling()
- && (event.cameraData.roll() > 0.1
- || event.cameraData.roll() < -0.1)) {
- geometry_.markSourceDirty();
- }
-
- // otherwise, only regen on rotate, resize and zoom
- if (event.bearingChanged || event.mapSizeChanged || event.zoomLevelChanged) {
- geometry_.markSourceDirty();
- }
-
- geometry_.setPreserveGeometry(true, geometry_.geoLeftBound());
- geometry_.markScreenDirty();
- updateMapItem();
-}
-
-/*!
- \internal
-*/
-bool QDeclarativeRouteMapItem::contains(const QPointF &point) const
+ Used to disable path property on the RouteMapItem
+ */
+void QDeclarativeRouteMapItem::setPath(const QJSValue &value)
{
- return geometry_.contains(point);
+ Q_UNUSED(value);
+ qWarning() << "Can not set the path on QDeclarativeRouteMapItem."
+ << "Please use the route property instead.";
}
diff --git a/src/imports/location/qdeclarativeroutemapitem_p.h b/src/imports/location/qdeclarativeroutemapitem_p.h
index c884a79f..5ba9f071 100644
--- a/src/imports/location/qdeclarativeroutemapitem_p.h
+++ b/src/imports/location/qdeclarativeroutemapitem_p.h
@@ -47,42 +47,27 @@ QT_BEGIN_NAMESPACE
class QDeclarativeGeoRoute;
-class QDeclarativeRouteMapItem : public QDeclarativeGeoMapItemBase
+class QDeclarativeRouteMapItem : public QDeclarativePolylineMapItem
{
Q_OBJECT
Q_PROPERTY(QDeclarativeGeoRoute *route READ route WRITE setRoute NOTIFY routeChanged)
- Q_PROPERTY(QDeclarativeMapLineProperties *line READ line CONSTANT)
public:
explicit QDeclarativeRouteMapItem(QQuickItem *parent = 0);
~QDeclarativeRouteMapItem();
- virtual void setMap(QDeclarativeGeoMap *quickMap, QGeoMap *map);
- //from QuickItem
- virtual QSGNode *updateMapItemPaintNode(QSGNode *, UpdatePaintNodeData *);
-
QDeclarativeGeoRoute *route() const;
void setRoute(QDeclarativeGeoRoute *route);
- QDeclarativeMapLineProperties *line();
-
- bool contains(const QPointF &point) const;
-
Q_SIGNALS:
void routeChanged(const QDeclarativeGeoRoute *route);
-protected Q_SLOTS:
- virtual void updateMapItem();
- void updateAfterLinePropertiesChanged();
- void afterViewportChanged(const QGeoMapViewportChangeEvent &event);
+protected:
+ void setPath(const QJSValue &value) Q_DECL_OVERRIDE;
private:
- QDeclarativeMapLineProperties line_;
QDeclarativeGeoRoute *route_;
- QList<QGeoCoordinate> path_;
- bool dirtyMaterial_;
- QGeoMapPolylineGeometry geometry_;
};
QT_END_NAMESPACE