summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjuhvu <qt-info@nokia.com>2011-08-15 15:54:41 +1000
committerDavid Laing <david.laing@nokia.com>2011-08-16 06:22:05 +0200
commit87c89ac76f735e4a81004bd6a47cee3886276f1c (patch)
treec16c94414e24bd0cb4e9d22fa8c3d5b6a12aa779
parentb3de5479efeeca93af88057f2f9946c6abcd8bfd (diff)
downloadqtlocation-87c89ac76f735e4a81004bd6a47cee3886276f1c.tar.gz
Map object list and ability to clear map objects.
Change-Id: I826c3b4bf6feff9824f1e60adfad3bf4a49078f3 Reviewed-on: http://codereview.qt.nokia.com/2930 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: David Laing <david.laing@nokia.com>
-rw-r--r--examples/declarative/mapviewer/MapComponent.qml3
-rw-r--r--src/imports/location/qdeclarativegeomapcircleobject.cpp9
-rw-r--r--src/imports/location/qdeclarativegeomapcircleobject_p.h2
-rw-r--r--src/imports/location/qdeclarativegeomapgroupobject.cpp4
-rw-r--r--src/imports/location/qdeclarativegeomapgroupobject_p.h2
-rw-r--r--src/imports/location/qdeclarativegeomapobject.cpp1
-rw-r--r--src/imports/location/qdeclarativegeomapobject_p.h7
-rw-r--r--src/imports/location/qdeclarativegeomapobjectborder.cpp2
-rw-r--r--src/imports/location/qdeclarativegeomappixmapobject.cpp9
-rw-r--r--src/imports/location/qdeclarativegeomappixmapobject_p.h2
-rw-r--r--src/imports/location/qdeclarativegeomappolygonobject.cpp10
-rw-r--r--src/imports/location/qdeclarativegeomappolygonobject_p.h4
-rw-r--r--src/imports/location/qdeclarativegeomappolylineobject.cpp9
-rw-r--r--src/imports/location/qdeclarativegeomappolylineobject_p.h4
-rw-r--r--src/imports/location/qdeclarativegeomaprectangleobject.cpp9
-rw-r--r--src/imports/location/qdeclarativegeomaprectangleobject_p.h2
-rw-r--r--src/imports/location/qdeclarativegeomaprouteobject.cpp47
-rw-r--r--src/imports/location/qdeclarativegeomaprouteobject_p.h11
-rw-r--r--src/imports/location/qdeclarativegeomaptextobject.cpp9
-rw-r--r--src/imports/location/qdeclarativegeomaptextobject_p.h2
-rw-r--r--src/imports/location/qdeclarativegeoroutemodel.cpp8
-rw-r--r--src/imports/location/qdeclarativegraphicsgeomap.cpp86
-rw-r--r--src/imports/location/qdeclarativegraphicsgeomap_p.h13
-rw-r--r--tests/auto/declarative/tst_map.qml56
-rw-r--r--tests/auto/declarative/tst_map_objectview.qml151
-rw-r--r--tests/auto/declarative/tst_map_routing.qml38
-rw-r--r--tests/auto/declarative/tst_plugin.qml8
-rw-r--r--tests/auto/geotestplugin/qgeocodingmanagerengine_test.h2
-rw-r--r--tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h10
-rw-r--r--tests/auto/qgeocodingmanagerplugins/qgeocodingmanagerengine_test.h2
-rw-r--r--tests/declarativetestplugin/qdeclarativelocationtestmodel.cpp10
-rw-r--r--tests/declarativetestplugin/qdeclarativelocationtestmodel_p.h2
32 files changed, 459 insertions, 75 deletions
diff --git a/examples/declarative/mapviewer/MapComponent.qml b/examples/declarative/mapviewer/MapComponent.qml
index 98f2e4c9..0ce92e83 100644
--- a/examples/declarative/mapviewer/MapComponent.qml
+++ b/examples/declarative/mapviewer/MapComponent.qml
@@ -103,7 +103,8 @@ Map {
id: routeDelegate
MapRoute {
route: path
- color: routeMouseArea.containsMouse ? "lime" :"red"
+ border.color: routeMouseArea.containsMouse ? "lime" :"red"
+ border.width: 5
MapMouseArea {
id: routeMouseArea
hoverEnabled: true
diff --git a/src/imports/location/qdeclarativegeomapcircleobject.cpp b/src/imports/location/qdeclarativegeomapcircleobject.cpp
index 65c02bb0..f5e8e1a5 100644
--- a/src/imports/location/qdeclarativegeomapcircleobject.cpp
+++ b/src/imports/location/qdeclarativegeomapcircleobject.cpp
@@ -40,6 +40,8 @@
****************************************************************************/
#include "qdeclarativegeomapcircleobject_p.h"
+#include "qdeclarativegraphicsgeomap_p.h"
+#include "qgeomapdata.h"
#include <QColor>
#include <QBrush>
@@ -90,6 +92,13 @@ QDeclarativeGeoMapCircleObject::QDeclarativeGeoMapCircleObject(QSGItem *parent)
QDeclarativeGeoMapCircleObject::~QDeclarativeGeoMapCircleObject()
{
+ // Memory management is bit tricky because we do not know
+ // which will be deleted first, the Map or some/all of the
+ // MapObjects. Hence we need to make sure that the internal
+ // c++ map objects are removed from QGeoMapData in either place
+ // (but not both).
+ if (map_ )
+ map_->removeMapObject(this);
delete circle_;
}
diff --git a/src/imports/location/qdeclarativegeomapcircleobject_p.h b/src/imports/location/qdeclarativegeomapcircleobject_p.h
index 102f57dc..0ba96c67 100644
--- a/src/imports/location/qdeclarativegeomapcircleobject_p.h
+++ b/src/imports/location/qdeclarativegeomapcircleobject_p.h
@@ -100,7 +100,7 @@ private Q_SLOTS:
void centerAltitudeChanged(double altitude);
private:
- QGeoMapCircleObject* circle_;
+ QPointer<QGeoMapCircleObject> circle_;
QDeclarativeCoordinate *center_;
QColor color_;
QDeclarativeGeoMapObjectBorder border_;
diff --git a/src/imports/location/qdeclarativegeomapgroupobject.cpp b/src/imports/location/qdeclarativegeomapgroupobject.cpp
index b728c311..9f984b41 100644
--- a/src/imports/location/qdeclarativegeomapgroupobject.cpp
+++ b/src/imports/location/qdeclarativegeomapgroupobject.cpp
@@ -40,6 +40,8 @@
****************************************************************************/
#include "qdeclarativegeomapgroupobject_p.h"
+#include "qdeclarativegraphicsgeomap_p.h"
+#include "qgeomapdata.h"
QT_BEGIN_NAMESPACE
@@ -75,6 +77,8 @@ QDeclarativeGeoMapGroupObject::~QDeclarativeGeoMapGroupObject()
// Remove all objects from the group before deleting it.
// These objects are owned by their declarative counterparts
// and they'll delete them.
+ if (map_)
+ map_->removeMapObject(this);
QList<QGeoMapObject*> objects = group_->childObjects();
for (int i = 0; i < objects.size(); ++i) {
group_->removeChildObject(objects.at(i));
diff --git a/src/imports/location/qdeclarativegeomapgroupobject_p.h b/src/imports/location/qdeclarativegeomapgroupobject_p.h
index f26470ac..9a85fa4d 100644
--- a/src/imports/location/qdeclarativegeomapgroupobject_p.h
+++ b/src/imports/location/qdeclarativegeomapgroupobject_p.h
@@ -92,7 +92,7 @@ private:
static QDeclarativeGeoMapObject* child_at(QDeclarativeListProperty<QDeclarativeGeoMapObject> *prop, int index);
static void child_clear(QDeclarativeListProperty<QDeclarativeGeoMapObject> *prop);
- QGeoMapGroupObject* group_;
+ QPointer<QGeoMapGroupObject> group_;
QList<QDeclarativeGeoMapObject*> objects_;
};
diff --git a/src/imports/location/qdeclarativegeomapobject.cpp b/src/imports/location/qdeclarativegeomapobject.cpp
index 1d255e7d..be3cc5d7 100644
--- a/src/imports/location/qdeclarativegeomapobject.cpp
+++ b/src/imports/location/qdeclarativegeomapobject.cpp
@@ -53,6 +53,7 @@ QT_BEGIN_NAMESPACE
QDeclarativeGeoMapObject::QDeclarativeGeoMapObject(QSGItem *parent)
: QSGItem(parent),
+ map_(0),
object_(0),
visible_(true)
{
diff --git a/src/imports/location/qdeclarativegeomapobject_p.h b/src/imports/location/qdeclarativegeomapobject_p.h
index 12294dc8..143c4167 100644
--- a/src/imports/location/qdeclarativegeomapobject_p.h
+++ b/src/imports/location/qdeclarativegeomapobject_p.h
@@ -48,6 +48,7 @@
#include "QModelIndex"
#include <QtDeclarative/QSGItem>
+#include <QtCore/QPointer>
class QAbstractItemModel;
@@ -98,13 +99,15 @@ public:
Q_SIGNALS:
void visibleChanged(bool visible);
+protected:
+ QPointer<QDeclarativeGraphicsGeoMap> map_;
+
private Q_SLOTS:
void parentZChanged();
private:
- QGeoMapObject *object_;
+ QPointer<QGeoMapObject> object_;
bool visible_;
- QDeclarativeGraphicsGeoMap* map_;
QList<QDeclarativeGeoMapMouseArea*> mouseAreas_;
};
diff --git a/src/imports/location/qdeclarativegeomapobjectborder.cpp b/src/imports/location/qdeclarativegeomapobjectborder.cpp
index 11cd109d..d0364410 100644
--- a/src/imports/location/qdeclarativegeomapobjectborder.cpp
+++ b/src/imports/location/qdeclarativegeomapobjectborder.cpp
@@ -68,7 +68,7 @@ QColor QDeclarativeGeoMapObjectBorder::color() const
void QDeclarativeGeoMapObjectBorder::setWidth(int width)
{
- if (m_width == width)
+ if (m_width == width || width <= 0)
return;
m_width = width;
diff --git a/src/imports/location/qdeclarativegeomappixmapobject.cpp b/src/imports/location/qdeclarativegeomappixmapobject.cpp
index bdd78aeb..121dc96a 100644
--- a/src/imports/location/qdeclarativegeomappixmapobject.cpp
+++ b/src/imports/location/qdeclarativegeomappixmapobject.cpp
@@ -40,6 +40,8 @@
****************************************************************************/
#include "qdeclarativegeomappixmapobject_p.h"
+#include "qdeclarativegraphicsgeomap_p.h"
+#include "qgeomapdata.h"
#include <QBrush>
#include <QUrl>
@@ -94,6 +96,13 @@ QDeclarativeGeoMapPixmapObject::QDeclarativeGeoMapPixmapObject(QSGItem *parent)
QDeclarativeGeoMapPixmapObject::~QDeclarativeGeoMapPixmapObject()
{
+ // Memory management is bit tricky because we do not know
+ // which will be deleted first, the Map or some/all of the
+ // MapObjects. Hence we need to make sure that the internal
+ // c++ map objects are removed from QGeoMapData in either place
+ // (but not both).
+ if (map_)
+ map_->removeMapObject(this);
delete pixmap_;
}
diff --git a/src/imports/location/qdeclarativegeomappixmapobject_p.h b/src/imports/location/qdeclarativegeomappixmapobject_p.h
index e8723961..82f9a7e4 100644
--- a/src/imports/location/qdeclarativegeomappixmapobject_p.h
+++ b/src/imports/location/qdeclarativegeomappixmapobject_p.h
@@ -101,7 +101,7 @@ private:
void setStatus(const QDeclarativeGeoMapPixmapObject::Status status);
void load();
- QGeoMapPixmapObject* pixmap_;
+ QPointer<QGeoMapPixmapObject> pixmap_;
QDeclarativeCoordinate *coordinate_;
QUrl source_;
QNetworkReply *reply_;
diff --git a/src/imports/location/qdeclarativegeomappolygonobject.cpp b/src/imports/location/qdeclarativegeomappolygonobject.cpp
index dda7aa1e..d0789c01 100644
--- a/src/imports/location/qdeclarativegeomappolygonobject.cpp
+++ b/src/imports/location/qdeclarativegeomappolygonobject.cpp
@@ -41,6 +41,8 @@
****************************************************************************/
#include "qdeclarativegeomappolygonobject_p.h"
+#include "qdeclarativegraphicsgeomap_p.h"
+#include "qgeomapdata.h"
#include <QColor>
#include <QBrush>
@@ -89,6 +91,14 @@ QDeclarativeGeoMapPolygonObject::~QDeclarativeGeoMapPolygonObject()
{
// QML engine deletes coordinates, no need to delete them here.
path_.clear();
+
+ // Memory management is bit tricky because we do not know
+ // which will be deleted first, the Map or some/all of the
+ // MapObjects. Hence we need to make sure that the internal
+ // c++ map objects are removed from QGeoMapData in either place
+ // (but not both).
+ if (map_)
+ map_->removeMapObject(this);
delete polygon_;
}
diff --git a/src/imports/location/qdeclarativegeomappolygonobject_p.h b/src/imports/location/qdeclarativegeomappolygonobject_p.h
index 1f5a7166..d7e26206 100644
--- a/src/imports/location/qdeclarativegeomappolygonobject_p.h
+++ b/src/imports/location/qdeclarativegeomappolygonobject_p.h
@@ -60,7 +60,7 @@ class QDeclarativeGeoMapPolygonObject : public QDeclarativeGeoMapObject
Q_PROPERTY(QDeclarativeListProperty<QDeclarativeCoordinate> path READ declarativePath NOTIFY pathChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
- Q_PROPERTY(QDeclarativeGeoMapObjectBorder* border READ border)
+ Q_PROPERTY(QDeclarativeGeoMapObjectBorder* border READ border CONSTANT)
public:
QDeclarativeGeoMapPolygonObject(QSGItem *parent = 0);
@@ -96,7 +96,7 @@ private:
static void path_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop);
void pathPropertyChanged();
- QGeoMapPolygonObject* polygon_;
+ QPointer<QGeoMapPolygonObject> polygon_;
QList<QDeclarativeCoordinate*> path_;
QColor color_;
QDeclarativeGeoMapObjectBorder border_;
diff --git a/src/imports/location/qdeclarativegeomappolylineobject.cpp b/src/imports/location/qdeclarativegeomappolylineobject.cpp
index 18e5f805..c9b5a75e 100644
--- a/src/imports/location/qdeclarativegeomappolylineobject.cpp
+++ b/src/imports/location/qdeclarativegeomappolylineobject.cpp
@@ -41,6 +41,8 @@
****************************************************************************/
#include "qdeclarativegeomappolylineobject_p.h"
+#include "qdeclarativegraphicsgeomap_p.h"
+#include "qgeomapdata.h"
#include <QColor>
#include <QBrush>
@@ -89,6 +91,13 @@ QDeclarativeGeoMapPolylineObject::~QDeclarativeGeoMapPolylineObject()
{
// QML engine will delete the actual declarative coordinates.
path_.clear();
+ // Memory management is bit tricky because we do not know
+ // which will be deleted first, the Map or some/all of the
+ // MapObjects. Hence we need to make sure that the internal
+ // c++ map objects are removed from QGeoMapData in either place
+ // (but not both).
+ if (map_)
+ map_->removeMapObject(this);
delete polyline_;
}
diff --git a/src/imports/location/qdeclarativegeomappolylineobject_p.h b/src/imports/location/qdeclarativegeomappolylineobject_p.h
index 9990cd7d..7ab22c35 100644
--- a/src/imports/location/qdeclarativegeomappolylineobject_p.h
+++ b/src/imports/location/qdeclarativegeomappolylineobject_p.h
@@ -59,7 +59,7 @@ class QDeclarativeGeoMapPolylineObject : public QDeclarativeGeoMapObject
Q_OBJECT
Q_PROPERTY(QDeclarativeListProperty<QDeclarativeCoordinate> path READ declarativePath NOTIFY pathChanged)
- Q_PROPERTY(QDeclarativeGeoMapObjectBorder* border READ border)
+ Q_PROPERTY(QDeclarativeGeoMapObjectBorder* border READ border CONSTANT)
public:
QDeclarativeGeoMapPolylineObject(QSGItem *parent = 0);
@@ -90,7 +90,7 @@ private:
static void path_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop);
void pathPropertyChanged();
- QGeoMapPolylineObject* polyline_;
+ QPointer<QGeoMapPolylineObject> polyline_;
QList<QDeclarativeCoordinate*> path_;
QDeclarativeGeoMapObjectBorder border_;
bool componentCompleted_;
diff --git a/src/imports/location/qdeclarativegeomaprectangleobject.cpp b/src/imports/location/qdeclarativegeomaprectangleobject.cpp
index 82dd460a..fbcf486c 100644
--- a/src/imports/location/qdeclarativegeomaprectangleobject.cpp
+++ b/src/imports/location/qdeclarativegeomaprectangleobject.cpp
@@ -43,6 +43,8 @@
****************************************************************************/
#include "qdeclarativegeomaprectangleobject_p.h"
+#include "qdeclarativegraphicsgeomap_p.h"
+#include "qgeomapdata.h"
#include <QColor>
#include <QBrush>
@@ -87,6 +89,13 @@ QDeclarativeGeoMapRectangleObject::QDeclarativeGeoMapRectangleObject(QSGItem *pa
QDeclarativeGeoMapRectangleObject::~QDeclarativeGeoMapRectangleObject()
{
+ // Memory management is bit tricky because we do not know
+ // which will be deleted first, the Map or some/all of the
+ // MapObjects. Hence we need to make sure that the internal
+ // c++ map objects are removed from QGeoMapData in either place
+ // (but not both).
+ if (map_)
+ map_->removeMapObject(this);
delete rectangle_;
}
diff --git a/src/imports/location/qdeclarativegeomaprectangleobject_p.h b/src/imports/location/qdeclarativegeomaprectangleobject_p.h
index 6d5b6d63..66117a24 100644
--- a/src/imports/location/qdeclarativegeomaprectangleobject_p.h
+++ b/src/imports/location/qdeclarativegeomaprectangleobject_p.h
@@ -94,7 +94,7 @@ private Q_SLOTS:
void borderWidthChanged(int width);
private:
- QGeoMapRectangleObject* rectangle_;
+ QPointer<QGeoMapRectangleObject> rectangle_;
QDeclarativeCoordinate *topLeft_;
QDeclarativeCoordinate *bottomRight_;
QColor color_;
diff --git a/src/imports/location/qdeclarativegeomaprouteobject.cpp b/src/imports/location/qdeclarativegeomaprouteobject.cpp
index b8e1689b..d1f3e4f7 100644
--- a/src/imports/location/qdeclarativegeomaprouteobject.cpp
+++ b/src/imports/location/qdeclarativegeomaprouteobject.cpp
@@ -49,6 +49,15 @@ QDeclarativeGeoMapRouteObject::QDeclarativeGeoMapRouteObject(QSGItem *parent)
{
route_ = new QGeoMapRouteObject(); // graphical object
setMapObject(route_);
+
+ connect(&border_,
+ SIGNAL(colorChanged(QColor)),
+ this,
+ SLOT(borderColorChanged(QColor)));
+ connect(&border_,
+ SIGNAL(widthChanged(int)),
+ this,
+ SLOT(borderWidthChanged(int)));
}
QDeclarativeGeoMapRouteObject::~QDeclarativeGeoMapRouteObject()
@@ -56,21 +65,6 @@ QDeclarativeGeoMapRouteObject::~QDeclarativeGeoMapRouteObject()
delete route_;
}
-void QDeclarativeGeoMapRouteObject::setColor(const QColor &color)
-{
- if (color_ == color)
- return;
- color_ = color;
- QPen pen(color);
- route_->setPen(pen);
- emit colorChanged();
-}
-
-QColor QDeclarativeGeoMapRouteObject::color() const
-{
- return color_;
-}
-
void QDeclarativeGeoMapRouteObject::setRoute(QDeclarativeGeoRoute* route)
{
if (route == declarativeRoute_)
@@ -102,6 +96,29 @@ quint32 QDeclarativeGeoMapRouteObject::detailLevel() const
return route_->detailLevel();
}
+QDeclarativeGeoMapObjectBorder* QDeclarativeGeoMapRouteObject::border()
+{
+ return &border_;
+}
+
+void QDeclarativeGeoMapRouteObject::borderColorChanged(const QColor &color)
+{
+ QPen p = route_->pen();
+ p.setColor(color);
+ route_->setPen(p);
+}
+
+void QDeclarativeGeoMapRouteObject::borderWidthChanged(int width)
+{
+ QPen p = route_->pen();
+ p.setWidth(width);
+ if (width == 0)
+ p.setStyle(Qt::NoPen);
+ else
+ p.setStyle(Qt::SolidLine);
+ route_->setPen(p);
+}
+
#include "moc_qdeclarativegeomaprouteobject_p.cpp"
QT_END_NAMESPACE
diff --git a/src/imports/location/qdeclarativegeomaprouteobject_p.h b/src/imports/location/qdeclarativegeomaprouteobject_p.h
index 09319b8d..da2f8ebd 100644
--- a/src/imports/location/qdeclarativegeomaprouteobject_p.h
+++ b/src/imports/location/qdeclarativegeomaprouteobject_p.h
@@ -45,6 +45,7 @@
#include "qdeclarativegeomapobject_p.h"
#include "qdeclarativecoordinate_p.h"
#include "qdeclarativegeoroute_p.h"
+#include "qdeclarativegeomapobjectborder_p.h"
#include "qgeomaprouteobject.h"
QT_BEGIN_NAMESPACE
@@ -55,7 +56,7 @@ class QDeclarativeGeoMapRouteObject : public QDeclarativeGeoMapObject
Q_PROPERTY(QDeclarativeGeoRoute* route READ route WRITE setRoute NOTIFY routeChanged)
Q_PROPERTY(quint32 detailLevel READ detailLevel WRITE setDetailLevel NOTIFY detailLevelChanged)
- Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
+ Q_PROPERTY(QDeclarativeGeoMapObjectBorder* border READ border CONSTANT)
public:
QDeclarativeGeoMapRouteObject(QSGItem *parent = 0);
@@ -67,19 +68,23 @@ public:
quint32 detailLevel() const;
void setDetailLevel(quint32 radius);
- QColor color() const;
- void setColor(const QColor &color);
+ QDeclarativeGeoMapObjectBorder* border();
Q_SIGNALS:
void routeChanged();
void detailLevelChanged();
void colorChanged();
+private Q_SLOTS:
+ void borderColorChanged(const QColor &color);
+ void borderWidthChanged(int width);
+
private:
// The declarative route (datatype)
QDeclarativeGeoRoute* declarativeRoute_;
// Used internally as the visual map object
QGeoMapRouteObject* route_;
+ QDeclarativeGeoMapObjectBorder border_;
QColor color_;
};
diff --git a/src/imports/location/qdeclarativegeomaptextobject.cpp b/src/imports/location/qdeclarativegeomaptextobject.cpp
index 553f2e8f..80702091 100644
--- a/src/imports/location/qdeclarativegeomaptextobject.cpp
+++ b/src/imports/location/qdeclarativegeomaptextobject.cpp
@@ -41,6 +41,8 @@
****************************************************************************/
#include "qdeclarativegeomaptextobject_p.h"
+#include "qdeclarativegraphicsgeomap_p.h"
+#include "qgeomapdata.h"
#include <QPen>
#include <QBrush>
@@ -101,6 +103,13 @@ QDeclarativeGeoMapTextObject::QDeclarativeGeoMapTextObject(QSGItem *parent)
QDeclarativeGeoMapTextObject::~QDeclarativeGeoMapTextObject()
{
+ // Memory management is bit tricky because we do not know
+ // which will be deleted first, the Map or some/all of the
+ // MapObjects. Hence we need to make sure that the internal
+ // c++ map objects are removed from QGeoMapData in either place
+ // (but not both).
+ if (map_)
+ map_->removeMapObject(this);
delete text_;
}
diff --git a/src/imports/location/qdeclarativegeomaptextobject_p.h b/src/imports/location/qdeclarativegeomaptextobject_p.h
index d2a6421a..48a74d3f 100644
--- a/src/imports/location/qdeclarativegeomaptextobject_p.h
+++ b/src/imports/location/qdeclarativegeomaptextobject_p.h
@@ -116,7 +116,7 @@ private Q_SLOTS:
void coordinateAltitudeChanged(double altitude);
private:
- QGeoMapTextObject* text_;
+ QPointer<QGeoMapTextObject> text_;
QDeclarativeCoordinate *coordinate_;
QColor color_;
HorizontalAlignment hAlignment_;
diff --git a/src/imports/location/qdeclarativegeoroutemodel.cpp b/src/imports/location/qdeclarativegeoroutemodel.cpp
index 4a478a30..701d42c6 100644
--- a/src/imports/location/qdeclarativegeoroutemodel.cpp
+++ b/src/imports/location/qdeclarativegeoroutemodel.cpp
@@ -60,7 +60,7 @@ QDeclarativeGeoRouteModel::QDeclarativeGeoRouteModel(QObject *parent)
// Establish role names so that they can be queried from this model
QHash<int, QByteArray> roleNames;
roleNames = QAbstractItemModel::roleNames();
- roleNames.insert(RouteRole, "path");
+ roleNames.insert(RouteRole, "routeData");
setRoleNames(roleNames);
}
@@ -79,7 +79,7 @@ int QDeclarativeGeoRouteModel::count() const
return routes_.count();
}
-Q_INVOKABLE void QDeclarativeGeoRouteModel::clear()
+void QDeclarativeGeoRouteModel::clear()
{
int oldCount = routes_.count();
beginResetModel();
@@ -92,7 +92,7 @@ Q_INVOKABLE void QDeclarativeGeoRouteModel::clear()
endResetModel();
}
-Q_INVOKABLE void QDeclarativeGeoRouteModel::reset()
+void QDeclarativeGeoRouteModel::reset()
{
clear();
abortRequest();
@@ -109,7 +109,7 @@ void QDeclarativeGeoRouteModel::abortRequest()
}
}
-Q_INVOKABLE QDeclarativeGeoRoute* QDeclarativeGeoRouteModel::get(int index)
+QDeclarativeGeoRoute* QDeclarativeGeoRouteModel::get(int index)
{
if (index < 0 || index >= routes_.count()) {
qmlInfo(this) << tr("Error, invalid index for get(): ") << index;
diff --git a/src/imports/location/qdeclarativegraphicsgeomap.cpp b/src/imports/location/qdeclarativegraphicsgeomap.cpp
index ec0ea791..2bed338f 100644
--- a/src/imports/location/qdeclarativegraphicsgeomap.cpp
+++ b/src/imports/location/qdeclarativegraphicsgeomap.cpp
@@ -44,7 +44,7 @@
#include "qdeclarativecoordinate_p.h"
#include "qdeclarativegeoserviceprovider_p.h"
-#include "qdeclarativelandmark_p.h"
+//#include "qdeclarativelandmark_p.h"
#include "qdeclarativegeomapgroupobject_p.h"
#include <qgeoserviceprovider.h>
@@ -100,9 +100,8 @@ QT_BEGIN_NAMESPACE
The Map element is part of the \bold{QtMobility.location 1.2} module.
*/
-//QDeclarativeGraphicsGeoMap::QDeclarativeGraphicsGeoMap(QSGItem *parent)
+
QDeclarativeGraphicsGeoMap::QDeclarativeGraphicsGeoMap(QSGItem *parent)
- //: QSGItem(parent),
: QSGItem(parent),
plugin_(0),
mapData_(0),
@@ -125,22 +124,20 @@ QDeclarativeGraphicsGeoMap::QDeclarativeGraphicsGeoMap(QSGItem *parent)
QDeclarativeGraphicsGeoMap::~QDeclarativeGraphicsGeoMap()
{
- if (mapData_) {
+ QList<QDeclarativeGeoMapObject*> objects = mapObjects_;
+ // Remove all map objects (map does not manage their allocation)
+ for (int i = 0; i < objects.count(); ++i) {
+ removeMapObject(objects.at(i));
+ }
+ // Note: delete map object view before the map data,
+ // so that it removes its map objects from the qgeomapdata,
+ // otherwise qgeomapdata will delete data it doesn't own.
+ if (!mapViews_.isEmpty())
qDeleteAll(mapViews_);
- // Remove map objects, we can't allow mapObject
- // to delete the objects because they are owned
- // by the declarative elements.
- //QList<QGeoMapObject*> objects = objectMap_.keys();
- QList<QDeclarativeGeoMapObject*> objects = mapObjects_;
- for (int i = 0; i < objects.size(); ++i) {
- mapData_->removeMapObject(objects.at(i)->mapObject());
- }
+ if (mapData_)
delete mapData_;
- }
-
- if (initialCoordinate) {
+ if (initialCoordinate)
delete initialCoordinate;
- }
}
void QDeclarativeGraphicsGeoMap::componentComplete()
@@ -201,6 +198,7 @@ void QDeclarativeGraphicsGeoMap::populateMap()
recursiveAddToObjectMap(mapObject);
mapData_->addMapObject(mapObject->mapObject());
mapObject->setMap(this);
+ emit objectsChanged();
continue;
}
QDeclarativeGeoMapMouseArea *mouseArea
@@ -523,6 +521,41 @@ QDeclarativeGraphicsGeoMap::MapType QDeclarativeGraphicsGeoMap::mapType() const
}
}
+// TODO document this (list has objects managed by add/removeMapObject and
+// those declared as part of the class.
+QDeclarativeListProperty<QDeclarativeGeoMapObject> QDeclarativeGraphicsGeoMap::objects()
+{
+ return QDeclarativeListProperty<QDeclarativeGeoMapObject>(this,
+ 0, // opaque data parameter
+ objects_append,
+ objects_count,
+ objects_at,
+ objects_clear);
+}
+
+// not supported
+void QDeclarativeGraphicsGeoMap::objects_append(QDeclarativeListProperty<QDeclarativeGeoMapObject>* prop, QDeclarativeGeoMapObject* object)
+{
+ Q_UNUSED(prop);
+ Q_UNUSED(object);
+}
+
+int QDeclarativeGraphicsGeoMap::objects_count(QDeclarativeListProperty<QDeclarativeGeoMapObject>* prop)
+{
+ return static_cast<QDeclarativeGraphicsGeoMap*>(prop->object)->mapObjects_.count();
+}
+
+QDeclarativeGeoMapObject* QDeclarativeGraphicsGeoMap::objects_at(QDeclarativeListProperty<QDeclarativeGeoMapObject>* prop, int index)
+{
+ return static_cast<QDeclarativeGraphicsGeoMap*>(prop->object)->mapObjects_.at(index);
+}
+
+// not supported
+void QDeclarativeGraphicsGeoMap::objects_clear(QDeclarativeListProperty<QDeclarativeGeoMapObject>* prop)
+{
+ Q_UNUSED(prop);
+}
+
/*!
\qmlproperty enumeration Map::connectivityMode
@@ -904,6 +937,7 @@ void QDeclarativeGraphicsGeoMap::addMapObject(QDeclarativeGeoMapObject *object)
recursiveAddToObjectMap(object);
mapData_->addMapObject(object->mapObject());
object->setMap(this);
+ emit objectsChanged();
}
/*!
@@ -930,6 +964,26 @@ void QDeclarativeGraphicsGeoMap::removeMapObject(QDeclarativeGeoMapObject *objec
recursiveRemoveFromObjectMap(object->mapObject());
mapObjects_.removeOne(object);
mapData_->removeMapObject(object->mapObject());
+ object->setMap(0);
+ emit objectsChanged();
+}
+
+// TODO document. Removes all map items that are added with addMapObject,
+// leaves objects from model intact.
+void QDeclarativeGraphicsGeoMap::clearMapObjects()
+{
+ if (!mapData_ || mapObjects_.isEmpty())
+ return;
+ QList<QDeclarativeGeoMapObject*> mapObjects = mapObjects_;
+ for (int i = 0; i < mapObjects.count(); ++ i) {
+ if (!objectMap_.contains(mapObjects.at(i)->mapObject()))
+ continue;
+ recursiveRemoveFromObjectMap(mapObjects.at(i)->mapObject());
+ mapObjects_.removeOne(mapObjects.at(i));
+ mapData_->removeMapObject(mapObjects.at(i)->mapObject());
+ mapObjects.at(i)->setMap(0);
+ }
+ emit objectsChanged();
}
void QDeclarativeGraphicsGeoMap::setActiveMouseArea(QDeclarativeGeoMapMouseArea *area)
diff --git a/src/imports/location/qdeclarativegraphicsgeomap_p.h b/src/imports/location/qdeclarativegraphicsgeomap_p.h
index 136b8d5c..c2da9ce8 100644
--- a/src/imports/location/qdeclarativegraphicsgeomap_p.h
+++ b/src/imports/location/qdeclarativegraphicsgeomap_p.h
@@ -44,8 +44,8 @@
#include <qgraphicsgeomap.h>
#include <QPointer>
-//#include <QtQuick1/qdeclarativeitem.h>
#include <QtDeclarative/qsgitem.h>
+#include <QtDeclarative/QDeclarativeListProperty>
#include "qdeclarativegeomapobject_p.h"
@@ -82,6 +82,7 @@ class QDeclarativeGraphicsGeoMap : public QSGItem
Q_PROPERTY(qreal zoomLevel READ zoomLevel WRITE setZoomLevel NOTIFY zoomLevelChanged)
Q_PROPERTY(MapType mapType READ mapType WRITE setMapType NOTIFY mapTypeChanged)
Q_PROPERTY(QDeclarativeCoordinate* center READ center WRITE setCenter NOTIFY declarativeCenterChanged)
+ Q_PROPERTY(QDeclarativeListProperty<QDeclarativeGeoMapObject> objects READ objects NOTIFY objectsChanged)
Q_PROPERTY(ConnectivityMode connectivityMode READ connectivityMode WRITE setConnectivityMode NOTIFY connectivityModeChanged)
Q_INTERFACES(QDeclarativeParserStatus)
@@ -102,7 +103,6 @@ public:
};
public:
- //QDeclarativeGraphicsGeoMap(QSGItem *parent = 0);
QDeclarativeGraphicsGeoMap(QSGItem *parent = 0);
~QDeclarativeGraphicsGeoMap();
@@ -140,9 +140,14 @@ public:
ConnectivityMode connectivityMode() const;
QDeclarativeListProperty<QDeclarativeGeoMapObject> objects();
+ static void objects_append(QDeclarativeListProperty<QDeclarativeGeoMapObject>* prop, QDeclarativeGeoMapObject* object);
+ static int objects_count(QDeclarativeListProperty<QDeclarativeGeoMapObject>* prop);
+ static QDeclarativeGeoMapObject* objects_at(QDeclarativeListProperty<QDeclarativeGeoMapObject>* prop, int index);
+ static void objects_clear(QDeclarativeListProperty<QDeclarativeGeoMapObject>* prop);
Q_INVOKABLE void addMapObject(QDeclarativeGeoMapObject* object);
Q_INVOKABLE void removeMapObject(QDeclarativeGeoMapObject* object);
+ Q_INVOKABLE void clearMapObjects();
Q_INVOKABLE QDeclarativeCoordinate* toCoordinate(QPointF screenPosition) const;
Q_INVOKABLE QPointF toScreenPosition(QDeclarativeCoordinate* coordinate) const;
@@ -155,6 +160,8 @@ public:
void setActiveMouseArea(QDeclarativeGeoMapMouseArea *area);
QDeclarativeGeoMapMouseArea* activeMouseArea() const;
+ QGeoMapData* mapData() {return mapData_;}
+
public Q_SLOTS:
void pan(int dx, int dy);
@@ -170,6 +177,7 @@ protected:
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
Q_SIGNALS:
+ void objectsChanged();
void pluginChanged(QDeclarativeGeoServiceProvider *plugin);
void sizeChanged(const QSizeF &size);
void zoomLevelChanged(qreal zoomLevel);
@@ -216,6 +224,7 @@ private:
QList<QDeclarativeGeoMapMouseArea*> mouseAreas_;
friend class QDeclarativeGeoMapObjectView;
+ friend class QDeclarativeGeoMapObject;
Q_DISABLE_COPY(QDeclarativeGraphicsGeoMap)
};
diff --git a/tests/auto/declarative/tst_map.qml b/tests/auto/declarative/tst_map.qml
index 10504c8c..4ffa61dd 100644
--- a/tests/auto/declarative/tst_map.qml
+++ b/tests/auto/declarative/tst_map.qml
@@ -83,6 +83,8 @@ Item {
MapPolyline {id: polyline2; Coordinate{latitude: 0;longitude:1} Coordinate{latitude: 2;longitude:3} }
}
SignalSpy {id: polygon2PathSpy; target: polygon2; signalName: "pathChanged"}
+ SignalSpy {id: polygon2ColorSpy; target: polygon2.border; signalName: "colorChanged"}
+ SignalSpy {id: polygon2WidthSpy; target: polygon2.border; signalName: "widthChanged"}
function test_polygons() {
compare(polygon1.path.length, 0)
compare(polygon2.path.length, 2)
@@ -117,8 +119,35 @@ Item {
polygon2.clearCoordinates()
compare(polygon2.path.length, 0)
compare(polygon2PathSpy.count, 7)
+ // Check border properties
+ // Width
+ compare(polygon2WidthSpy.count, 0)
+ polygon2.border.width = 123
+ compare(polygon2WidthSpy.count, 1)
+ compare(polygon2.border.width, 123)
+ polygon2.border.width = 123
+ compare(polygon2WidthSpy.count, 1)
+ polygon2.border.width = -1
+ compare(polygon2WidthSpy.count, 1)
+ compare(polygon2.border.width, 123)
+ polygon2.border.width = 0
+ compare(polygon2WidthSpy.count, 1)
+ compare(polygon2.border.width, 123)
+ // Color
+ compare(polygon2ColorSpy.count, 0)
+ polygon2.border.color = "#008000"
+ compare(polygon2ColorSpy.count, 1)
+ verify (polygon2.border.color == "#008000")
+ compare(polygon2.border.color, "#008000")
+ polygon2.border.color = "#008000"
+ compare(polygon2ColorSpy.count, 1)
+ polygon2.border.color = "#008000"
+ compare(polygon2ColorSpy.count, 1)
+ compare(polygon2.border.color, "#008000")
}
SignalSpy {id: polyline2PathSpy; target: polyline2; signalName: "pathChanged"}
+ SignalSpy {id: polyline2ColorSpy; target: polyline2.border; signalName: "colorChanged"}
+ SignalSpy {id: polyline2WidthSpy; target: polyline2.border; signalName: "widthChanged"}
function test_polylines() {
compare(polyline1.path.length, 0)
compare(polyline2.path.length, 2)
@@ -153,9 +182,32 @@ Item {
polyline2.clearCoordinates()
compare(polyline2.path.length, 0)
compare(polyline2PathSpy.count, 7)
+ // Check border properties
+ // Width
+ compare(polyline2WidthSpy.count, 0)
+ polyline2.border.width = 123
+ compare(polyline2WidthSpy.count, 1)
+ compare(polyline2.border.width, 123)
+ polyline2.border.width = 123
+ compare(polyline2WidthSpy.count, 1)
+ polyline2.border.width = -1
+ compare(polyline2WidthSpy.count, 1)
+ compare(polyline2.border.width, 123)
+ polyline2.border.width = 0
+ compare(polyline2WidthSpy.count, 1)
+ compare(polyline2.border.width, 123)
+ // Color
+ compare(polyline2ColorSpy.count, 0)
+ polyline2.border.color = "#008000"
+ compare(polyline2ColorSpy.count, 1)
+ verify (polyline2.border.color == "#008000")
+ compare(polyline2.border.color, "#008000")
+ polyline2.border.color = "#008000"
+ compare(polyline2ColorSpy.count, 1)
+ polyline2.border.color = "#008000"
+ compare(polyline2ColorSpy.count, 1)
+ compare(polyline2.border.color, "#008000")
}
}
}
-
-
diff --git a/tests/auto/declarative/tst_map_objectview.qml b/tests/auto/declarative/tst_map_objectview.qml
index 245e1805..5c05db12 100644
--- a/tests/auto/declarative/tst_map_objectview.qml
+++ b/tests/auto/declarative/tst_map_objectview.qml
@@ -53,11 +53,34 @@ Item {
Coordinate{ id: mapDefaultCenter; latitude: 10; longitude: 30}
MapCircle {
+ objectName: "externalCircle"
id: externalCircle
radius: 2000000
center: mapDefaultCenter
}
+ MapRectangle {
+ objectName: "externalRectangle"
+ id: externalRectangle
+ }
+
+ MapPolygon {
+ objectName: "externalPolygon"
+ id: externalPolygon
+ }
+
+ MapText {
+ id: externalText
+ }
+
+ MapImage {
+ id: externalImage
+ }
+
+ MapPolyline {
+ id: externalPolyline
+ }
+
TestModel {
id: testModel
datatype: 'coordinate'
@@ -94,6 +117,7 @@ Item {
}
}
}
+
Map {
id: mapWithoutPlugin; center: mapDefaultCenter;
anchors.fill: parent; size.width: parent.width; size.height: parent.height; zoomLevel: 2
@@ -115,6 +139,15 @@ Item {
}
}
}
+ MapObjectView {
+ id: routeObjectView
+ model: routeModel
+ delegate: Component {
+ MapRoute {
+ route: routeData
+ }
+ }
+ }
}
TestCase {
@@ -159,6 +192,124 @@ Item {
mapWithoutPlugin.plugin = testPlugin
tryCompare(pluginChangedSpy, "count", 1, 1000)
compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 10) // 9 from testModel, + 1 from mapcircle
+ mapWithoutPlugin.clearMapObjects();
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 9) // 9 from testModel
+ testModel.reset();
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 0)
+ }
+ Plugin {
+ id: testPlugin_immediate;
+ name: "qmlgeo.test.plugin"
+ parameters: [
+ // Parms to guide the test plugin
+ PluginParameter { name: "gc_supported"; value: true},
+ PluginParameter { name: "gc_finishRequestImmediately"; value: true},
+ PluginParameter { name: "gc_validateWellKnownValues"; value: true}
+ ]
+ }
+ RouteQuery {id: routeQuery;
+ waypoints: [
+ Coordinate {id: fcoordinate1; latitude: 60; longitude: 60},
+ Coordinate {id: fcoordinate2; latitude: 61; longitude: 62},
+ Coordinate {id: fcoordinate3; latitude: 63; longitude: 64},
+ Coordinate {id: fcoordinate4; latitude: 65; longitude: 66},
+ Coordinate {id: fcoordinate5; latitude: 67; longitude: 68}
+ ]
+ }
+ // Test routemodel and object list of map
+ RouteModel {id: routeModel; plugin: testPlugin_immediate; query: routeQuery }
+ SignalSpy {id: objectsChangedSpy; target: mapWithoutPlugin; signalName: "objectsChanged"}
+ function test_d_routemodel() {
+ objectsChangedSpy.clear()
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 0) // precondition
+ compare(mapWithoutPlugin.objects.length, 0)
+ compare(objectsChangedSpy.count, 0)
+ routeQuery.numberAlternativeRoutes = 4
+ routeModel.update();
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 4)
+ compare(mapWithoutPlugin.objects.length, 0)
+ routeQuery.numberAlternativeRoutes = 3
+ routeModel.update();
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 3)
+ compare(mapWithoutPlugin.objects.length, 0)
+ routeModel.clear();
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 0)
+ compare(mapWithoutPlugin.objects.length, 0)
+ routeModel.clear(); // clear empty model
+ routeQuery.numberAlternativeRoutes = 3
+ routeModel.update();
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 3)
+ compare(mapWithoutPlugin.objects.length, 0)
+ compare(objectsChangedSpy.count, 0)
+ mapWithoutPlugin.addMapObject(externalCircle)
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 4)
+ compare(mapWithoutPlugin.objects.length, 1)
+ compare(objectsChangedSpy.count, 1)
+ compare(mapWithoutPlugin.objects[0], externalCircle)
+ routeModel.reset(); // all map objects based on model will be cleared
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 1)
+ compare(mapWithoutPlugin.objects.length, 1)
+ mapWithoutPlugin.clearMapObjects() // clears objects not stemming from model
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 0)
+ compare(mapWithoutPlugin.objects.length, 0)
+ compare(objectsChangedSpy.count, 2)
+
+ // Test the objects list
+ mapWithoutPlugin.addMapObject(externalCircle)
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 1)
+ compare(mapWithoutPlugin.objects.length, 1)
+ compare(objectsChangedSpy.count, 3)
+ compare(mapWithoutPlugin.objects[0], externalCircle)
+
+ mapWithoutPlugin.addMapObject(externalRectangle)
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 2)
+ compare(mapWithoutPlugin.objects.length, 2)
+ compare(objectsChangedSpy.count, 4)
+ compare(mapWithoutPlugin.objects[1], externalRectangle)
+
+ mapWithoutPlugin.addMapObject(externalRectangle)
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 2)
+ compare(mapWithoutPlugin.objects.length, 2)
+ compare(objectsChangedSpy.count, 4)
+ compare(mapWithoutPlugin.objects[1], externalRectangle)
+
+ mapWithoutPlugin.addMapObject(externalPolygon)
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 3)
+ compare(mapWithoutPlugin.objects.length, 3)
+ compare(objectsChangedSpy.count, 5)
+ compare(mapWithoutPlugin.objects[1], externalRectangle)
+
+ mapWithoutPlugin.removeMapObject(externalCircle)
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 2)
+ compare(mapWithoutPlugin.objects.length, 2)
+ compare(objectsChangedSpy.count, 6)
+ compare(mapWithoutPlugin.objects[0], externalRectangle)
+
+ mapWithoutPlugin.removeMapObject(externalRectangle)
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 1)
+ compare(mapWithoutPlugin.objects.length, 1)
+ compare(objectsChangedSpy.count, 7)
+ compare(mapWithoutPlugin.objects[0], externalPolygon)
+
+ mapWithoutPlugin.clearMapObjects()
+ compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 0)
+ compare(mapWithoutPlugin.objects.length, 0)
+ compare(objectsChangedSpy.count, 8)
+ }
+ function test_e_map_objects_on_delete() {
+ // Test that dynamic map & map object creation works
+ var dynamicMap = Qt.createQmlObject("import QtQuick 2.0; import Qt.location 5.0; Map {plugin: testPlugin;}", masterItem, "");
+ var dynamicCircle = Qt.createQmlObject("import QtQuick 2.0; import Qt.location 5.0; MapCircle {}", masterItem, "");
+ compare (dynamicMap.objects.length, 0)
+ dynamicMap.addMapObject(dynamicCircle)
+ compare (dynamicMap.objects.length, 1)
+ dynamicCircle.destroy(2); wait(100) // circle should remove itself from the map
+ compare (dynamicMap.objects.length, 0)
+
+ var dynamicRectangle = Qt.createQmlObject("import QtQuick 2.0; import Qt.location 5.0; MapRectangle {}", masterItem, "");
+ dynamicMap.addMapObject(dynamicRectangle)
+ dynamicMap.destroy(2); wait(100) // must act gracefully although has objects when destroyed
}
}
}
+
diff --git a/tests/auto/declarative/tst_map_routing.qml b/tests/auto/declarative/tst_map_routing.qml
index 11e9bb40..3f8f6bfb 100644
--- a/tests/auto/declarative/tst_map_routing.qml
+++ b/tests/auto/declarative/tst_map_routing.qml
@@ -74,25 +74,39 @@ Item {
Coordinate {id: emptyCoordinate}
SignalSpy {id: mapRouteDetailLevelSpy; target: emptyMapRoute; signalName: "detailLevelChanged"}
- SignalSpy {id: mapRouteColorSpy; target: emptyMapRoute; signalName: "colorChanged"}
+ SignalSpy {id: mapRouteColorSpy; target: emptyMapRoute.border; signalName: "colorChanged"}
+ SignalSpy {id: mapRouteWidthSpy; target: emptyMapRoute.border; signalName: "widthChanged"}
SignalSpy {id: mapRouteRouteSpy; target: emptyMapRoute; signalName: "routeChanged"}
function test_maproute_defaults() {
compare(mapRouteRouteSpy.count, 0)
compare(mapRouteColorSpy.count, 0)
compare(mapRouteDetailLevelSpy.count, 0)
compare (emptyMapRoute.detailLevel, 6)
- emptyMapRoute.color = 'green'
+ emptyMapRoute.border.color = 'green'
emptyMapRoute.detailLevel = 3
compare(mapRouteRouteSpy.count, 0)
compare(mapRouteColorSpy.count, 1)
compare(mapRouteDetailLevelSpy.count, 1)
- emptyMapRoute.color = 'green'
+ emptyMapRoute.border.color = 'green'
emptyMapRoute.detailLevel = 3
compare(mapRouteColorSpy.count, 1)
compare(mapRouteDetailLevelSpy.count, 1)
emptyMapRoute.route = emptyRoute
compare(mapRouteRouteSpy.count, 1)
compare(emptyMapRoute.route, emptyRoute)
+ // width
+ compare(mapRouteWidthSpy.count, 0)
+ emptyMapRoute.border.width = 123
+ compare(mapRouteWidthSpy.count, 1)
+ compare(emptyMapRoute.border.width, 123)
+ emptyMapRoute.border.width = 123
+ compare(mapRouteWidthSpy.count, 1)
+ emptyMapRoute.border.width = -1
+ compare(mapRouteWidthSpy.count, 1)
+ compare(emptyMapRoute.border.width, 123)
+ emptyMapRoute.border.width = 0
+ compare(mapRouteWidthSpy.count, 1)
+ compare(emptyMapRoute.border.width, 123)
}
function test_route_defaults() {
@@ -497,6 +511,7 @@ Item {
RouteQuery {id: routeQuery}
RouteQuery {id: filledRouteQuery;
+ numberAlternativeRoutes: 1
waypoints: [
Coordinate {id: fcoordinate1; latitude: 60; longitude: 60},
Coordinate {id: fcoordinate2; latitude: 61; longitude: 62},
@@ -512,8 +527,13 @@ Item {
Coordinate {id: f2coordinate3; latitude: 63; longitude: 64}
]
}
+ RouteModel {
+ id: routeModelAutomatic;
+ plugin: testPlugin_slacker;
+ query: filledRouteQuery;
+ autoUpdate: true
+ }
- RouteModel {id: routeModelAutomatic; plugin: testPlugin_slacker; query: filledRouteQuery; autoUpdate: true}
SignalSpy {id: automaticRoutesSpy; target: routeModelAutomatic; signalName: "routesChanged" }
RouteModel {id: routeModel; plugin: testPlugin_immediate; query: routeQuery }
@@ -570,7 +590,7 @@ Item {
// Check that results are cleared
routeModelSlack.update()
wait (300)
- compare (routeModelSlack.count, 1)
+ compare (routeModelSlack.count, 3) // numberALternativeRoutes
routeModelSlack.reset()
compare (routeModelSlack.count, 0)
// Check that changing plugin resets any ongoing requests
@@ -585,7 +605,7 @@ Item {
compare (testPluginSlackSpy.count, 1)
// test that works
routeModelSlack.update()
- compare (routeModelSlack.count, 1)
+ compare (routeModelSlack.count, 3)
// return back
routeModelSlack.plugin = testPlugin_slacker
}
@@ -632,6 +652,7 @@ Item {
routeQuery.addWaypoint(rcoordinate5)
compare (testWaypointsSpy.count, 5)
compare (routeQuery.waypoints.length, 5)
+ routeQuery.numberAlternativeRoutes = 1 // how many routes to get back, > 70 indicates error
routeModel.update()
tryCompare (testRoutesSpy, "count", 1) // 5 sec
tryCompare (testCountSpy, "count", 1)
@@ -688,16 +709,20 @@ Item {
compare(routeModelSlack.count, 1)
// Autoupdate
+ filledRouteQuery.numberAlternativeRoutes = 1 // 'altroutes - 70' is the echoed errorcode
+ wait (300)
automaticRoutesSpy.clear()
compare(routeModelAutomatic.count, 1) // There should be a route already
compare (routeModelAutomatic.get(0).path.length, 5)
compare (routeModelAutomatic.get(0).path[0].latitude, filledRouteQuery.waypoints[0].latitude)
+
// Remove a waypoint and check that autoupdate works
filledRouteQuery.removeWaypoint(fcoordinate2)
wait(300)
compare (routeModelAutomatic.get(0).path.length, 4)
compare (routeModelAutomatic.get(0).path[0].latitude, fcoordinate1.latitude)
compare (automaticRoutesSpy.count, 1)
+
// Change contents of a coordinate and check that autoupdate works
fcoordinate1.latitude++
wait(300)
@@ -705,6 +730,7 @@ Item {
compare (automaticRoutesSpy.count, 2)
// Change query
routeModelAutomatic.query = filledRouteQuery2
+ filledRouteQuery2.numberAlternativeRoutes = 3
wait(300)
compare (routeModelAutomatic.get(0).path.length, 3)
compare (automaticRoutesSpy.count, 3)
diff --git a/tests/auto/declarative/tst_plugin.qml b/tests/auto/declarative/tst_plugin.qml
index d0d25164..a261cf53 100644
--- a/tests/auto/declarative/tst_plugin.qml
+++ b/tests/auto/declarative/tst_plugin.qml
@@ -109,11 +109,3 @@ Item {
}
}
}
-
-
-
-
-
-
-
-
diff --git a/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h b/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h
index 481b505e..ec057d31 100644
--- a/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h
+++ b/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h
@@ -103,7 +103,7 @@ public:
setSupportsGeocoding(supported_);
setSupportsReverseGeocoding(supported_);
- setLocale(*(new QLocale (QLocale::German, QLocale::Germany)));
+ setLocale(QLocale (QLocale::German, QLocale::Germany));
}
QGeocodeReply* geocode(const QString &searchString,
diff --git a/tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h b/tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h
index c4233852..2ba6aba3 100644
--- a/tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h
+++ b/tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h
@@ -100,7 +100,7 @@ public:
finishRequestImmediately_ = qvariant_cast<bool>(parameters.value("gc_finishRequestImmediately"));
}
- setLocale(*(new QLocale (QLocale::German, QLocale::Germany)));
+ setLocale(QLocale (QLocale::German, QLocale::Germany));
setSupportedFeatureTypes (
QGeoRouteRequest::NoFeature | QGeoRouteRequest::TollFeature |
QGeoRouteRequest::HighwayFeature | QGeoRouteRequest::PublicTransitFeature |
@@ -158,9 +158,11 @@ public:
void setRoutes(const QGeoRouteRequest& request, RouteReplyTest* reply)
{
QList<QGeoRoute> routes;
- QGeoRoute route;
- route.setPath(request.waypoints());
- routes.append(route);
+ for (int i = 0; i < request.numberAlternativeRoutes(); ++i) {
+ QGeoRoute route;
+ route.setPath(request.waypoints());
+ routes.append(route);
+ }
reply->callSetRoutes(routes);
}
diff --git a/tests/auto/qgeocodingmanagerplugins/qgeocodingmanagerengine_test.h b/tests/auto/qgeocodingmanagerplugins/qgeocodingmanagerengine_test.h
index 171c2b12..ea08fb40 100644
--- a/tests/auto/qgeocodingmanagerplugins/qgeocodingmanagerengine_test.h
+++ b/tests/auto/qgeocodingmanagerplugins/qgeocodingmanagerengine_test.h
@@ -83,7 +83,7 @@ public:
Q_UNUSED(errorString)
setSupportsGeocoding(true);
setSupportsReverseGeocoding(true);
- setLocale(*(new QLocale (QLocale::German, QLocale::Germany)));
+ setLocale(QLocale(QLocale::German, QLocale::Germany));
}
QGeocodeReply* geocode ( const QString & searchString, int limit, int offset, QGeoBoundingArea * bounds )
diff --git a/tests/declarativetestplugin/qdeclarativelocationtestmodel.cpp b/tests/declarativetestplugin/qdeclarativelocationtestmodel.cpp
index e75bea72..89050516 100644
--- a/tests/declarativetestplugin/qdeclarativelocationtestmodel.cpp
+++ b/tests/declarativetestplugin/qdeclarativelocationtestmodel.cpp
@@ -97,6 +97,16 @@ void QDeclarativeLocationTestModel::repopulate()
endResetModel();
}
+void QDeclarativeLocationTestModel::reset()
+{
+ beginResetModel();
+ if (!dataobjects_.isEmpty()) {
+ qDeleteAll(dataobjects_);
+ dataobjects_.clear();
+ }
+ endResetModel();
+}
+
void QDeclarativeLocationTestModel::scheduleRepopulation()
{
if (!componentCompleted_)
diff --git a/tests/declarativetestplugin/qdeclarativelocationtestmodel_p.h b/tests/declarativetestplugin/qdeclarativelocationtestmodel_p.h
index def3d62b..ad0f1170 100644
--- a/tests/declarativetestplugin/qdeclarativelocationtestmodel_p.h
+++ b/tests/declarativetestplugin/qdeclarativelocationtestmodel_p.h
@@ -54,6 +54,8 @@ public:
QString datatype() const;
void setDatatype(QString datatype);
+ //Q_INVOKABLE void clear();
+ Q_INVOKABLE void reset();
//Q_INVOKABLE void reset();
signals: