diff options
author | Juha Vuolle <juha.vuolle@nokia.com> | 2011-12-12 16:30:53 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-13 10:50:46 +0100 |
commit | 73790e789c095f06ea4467e501cea315d758a4f5 (patch) | |
tree | 53acf95dbe77a51e879e7ebd87eb3f54e5b2e92a | |
parent | 9655258398566a408a90d820ad9988b437b8de3f (diff) | |
download | qtlocation-73790e789c095f06ea4467e501cea315d758a4f5.tar.gz |
First set of map(-item, -view) quick autotests.
Fixed misc findings.
Change-Id: I8dce4e6ac557a4a2abaff0c0676c62c383b1e901
Reviewed-by: Juha Vuolle <juha.vuolle@nokia.com>
9 files changed, 333 insertions, 215 deletions
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index e250f402..0ef985fc 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -71,8 +71,6 @@ #include <QtQuick/QSGEngine> #include <QtGui/QGuiApplication> -#include <QDebug> - QT_BEGIN_NAMESPACE /*! @@ -140,21 +138,11 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent) QDeclarativeGeoMap::~QDeclarativeGeoMap() { - // TODO we do not clear the map items atm -// if (mapData_) { -// qDeleteAll(mapViews_); -// // Remove map objects, we can't allow MapItem -// // to delete the objects because they are owned -// // by the declarative elements. -// QList<QDeclarativeGeoMapItem*> objects = MapItems_; -// for (int i = 0; i < objects.size(); ++i) { -// mapData_->removeMapItem(objects.at(i)->MapItem()); -// } -// delete mapData_; -// } - foreach (QDeclarativeGeoMapItemBase* item, mapItems_) { - item->setMap(0,0); - } + if (!mapViews_.isEmpty()) + qDeleteAll(mapViews_); + // remove any map items associations + for (int i = 0; i < mapItems_.count(); ++i) + qobject_cast<QDeclarativeGeoMapItemBase*>(mapItems_.at(i))->setMap(0,0); mapItems_.clear(); } @@ -201,6 +189,10 @@ bool QDeclarativeGeoMap::mouseEvent(QMouseEvent* event) } } +QDeclarativeGeoMapPinchArea* QDeclarativeGeoMap::pinch() { + return pinchArea_; +} + QDeclarativeGeoMapFlickable* QDeclarativeGeoMap::flick() { return flickable_; @@ -351,6 +343,7 @@ void QDeclarativeGeoMap::setPlugin(QDeclarativeGeoServiceProvider *plugin) } pinchArea_->zoomLevelLimits(mappingManager_->minimumZoomLevel(), mappingManager_->maximumZoomLevel()); + if (!mappingManager_->isInitialized()) connect(mappingManager_, SIGNAL(initialized()), this, SLOT(mappingManagerInitialized())); else @@ -794,16 +787,33 @@ void QDeclarativeGeoMap::wheelEvent(QWheelEvent *event) void QDeclarativeGeoMap::addMapItem(QDeclarativeGeoMapItemBase *item) { QLOC_TRACE0; - if (!item || mapItems_.contains(item)) + if (!item || item->quickMap()) return; updateMutex_.lock(); item->setParentItem(this); item->setMap(this, map_); mapItems_.append(item); - connect(item, SIGNAL(destroyed(QObject*)), this, SLOT(mapItemDestroyed(QObject*))); + emit mapItemsChanged(); updateMutex_.unlock(); } +/*! + \qmlmethod QtLocation5::Map::mapItems() + + Returns the list of all map items in no particular order. + These items include items that were declared statically as part of + the element declaration, as well as dynamical items (\l addMapItem, + \l MapItemView). + + \snippet TODO + +*/ + +QList<QObject*> QDeclarativeGeoMap::mapItems() +{ + return mapItems_; +} + void QDeclarativeGeoMap::removeMapItem(QDeclarativeGeoMapItemBase *item) { QLOC_TRACE0; @@ -814,29 +824,27 @@ void QDeclarativeGeoMap::removeMapItem(QDeclarativeGeoMapItemBase *item) updateMutex_.lock(); item->setParentItem(0); item->setMap(0, 0); - // stop listening to destroyed() - item->disconnect(this); // these can be optmized for perf, as we already check the 'contains' above mapItems_.removeOne(item); + emit mapItemsChanged(); updateMutex_.unlock(); } void QDeclarativeGeoMap::clearMapItems() { + QLOC_TRACE0; if (mapItems_.isEmpty()) return; updateMutex_.lock(); + for (int i = 0; i < mapItems_.count(); ++i) { + qobject_cast<QDeclarativeGeoMapItemBase*>(mapItems_.at(i))->setParentItem(0); + qobject_cast<QDeclarativeGeoMapItemBase*>(mapItems_.at(i))->setMap(0, 0); + } mapItems_.clear(); + emit mapItemsChanged(); updateMutex_.unlock(); } -void QDeclarativeGeoMap::mapItemDestroyed(QObject* item) -{ - QDeclarativeGeoMapItemBase* mapItem = qobject_cast<QDeclarativeGeoMapItemBase*>(item); - if (mapItem) - removeMapItem(mapItem); -} - void QDeclarativeGeoMap::setActiveMapType(QDeclarativeGeoMapType *mapType) { activeMapType_ = mapType; @@ -863,12 +871,6 @@ QDeclarativeGeoMapType * QDeclarativeGeoMap::activeMapType() const */ -// This function is strictly for testing purposes -int QDeclarativeGeoMap::testGetDeclarativeMapItemCount() -{ - return 0; -} - #include "moc_qdeclarativegeomap_p.cpp" QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h index f80fcdfc..2ea93c90 100644 --- a/src/imports/location/qdeclarativegeomap_p.h +++ b/src/imports/location/qdeclarativegeomap_p.h @@ -106,6 +106,7 @@ class QDeclarativeGeoMap : public QQuickItem Q_PROPERTY(QDeclarativeGeoMapType* activeMapType READ activeMapType WRITE setActiveMapType NOTIFY activeMapTypeChanged) Q_PROPERTY(QDeclarativeListProperty<QDeclarativeGeoMapType> supportedMapTypes READ supportedMapTypes NOTIFY supportedMapTypesChanged) Q_PROPERTY(QDeclarativeCoordinate* center READ center WRITE setCenter NOTIFY centerChanged) + Q_PROPERTY(QList<QObject*> mapItems READ mapItems NOTIFY mapItemsChanged) // Tilt and bearing are not part of supported API Q_PROPERTY(qreal tilt READ tilt WRITE setTilt NOTIFY tiltChanged) Q_PROPERTY(qreal bearing READ bearing WRITE setBearing NOTIFY bearingChanged) @@ -148,26 +149,18 @@ public: QDeclarativeListProperty<QDeclarativeGeoMapType> supportedMapTypes(); - // do we need this? - //QDeclarativeListProperty<QDeclarativeGeoMapItemBase> items(); - Q_INVOKABLE void removeMapItem(QDeclarativeGeoMapItemBase *item); Q_INVOKABLE void addMapItem(QDeclarativeGeoMapItemBase *item); Q_INVOKABLE void clearMapItems(); + QList<QObject*> mapItems(); Q_INVOKABLE QDeclarativeCoordinate* toCoordinate(QPointF screenPosition) const; Q_INVOKABLE QPointF toScreenPosition(QDeclarativeCoordinate* coordinate) const; - // This function is strictly for testing purposes and may be removed at - // any time without any notice (hence also the obscure naming to avoid - // accidental usage): - Q_INVOKABLE int testGetDeclarativeMapItemCount(); // callback for map mouse areas bool mouseEvent(QMouseEvent* event); - QDeclarativeGeoMapPinchArea* pinch() { - return pinchArea_; - } + QDeclarativeGeoMapPinchArea* pinch(); public Q_SLOTS: void pan(int dx, int dy); @@ -192,13 +185,13 @@ Q_SIGNALS: void supportedMapTypesChanged(); void minimumZoomLevelChanged(); void maximumZoomLevelChanged(); + void mapItemsChanged(); private Q_SLOTS: void updateMapDisplay(const QRectF& target); void centerLatitudeChanged(double latitude); void centerLongitudeChanged(double longitude); void centerAltitudeChanged(double altitude); - void mapItemDestroyed(QObject* item); void mappingManagerInitialized(); void mapZoomLevelChanged(qreal zoom); void mapTiltChanged(qreal tilt); @@ -238,7 +231,7 @@ private: TileCache *tileCache_; Map *map_; - QList<QDeclarativeGeoMapItemBase*> mapItems_; + QList<QObject*> mapItems_; QMutex updateMutex_; friend class QDeclarativeGeoMapItem; diff --git a/src/imports/location/qdeclarativegeomapitembase.cpp b/src/imports/location/qdeclarativegeomapitembase.cpp index 0917cb10..572b8258 100644 --- a/src/imports/location/qdeclarativegeomapitembase.cpp +++ b/src/imports/location/qdeclarativegeomapitembase.cpp @@ -56,6 +56,9 @@ QDeclarativeGeoMapItemBase::QDeclarativeGeoMapItemBase(QQuickItem *parent) QDeclarativeGeoMapItemBase::~QDeclarativeGeoMapItemBase() { + //qDebug() << __FUNCTION__ << objectName() << quickMap(); + if (quickMap_) + quickMap_->removeMapItem(this); } void QDeclarativeGeoMapItemBase::mapChanged() diff --git a/src/imports/location/qdeclarativegeomapitemview.cpp b/src/imports/location/qdeclarativegeomapitemview.cpp index 655f6b08..e266871d 100644 --- a/src/imports/location/qdeclarativegeomapitemview.cpp +++ b/src/imports/location/qdeclarativegeomapitemview.cpp @@ -44,7 +44,6 @@ #include "qdeclarativegeomap_p.h" #include "qdeclarativegeomapitembase_p.h" -#include <QDebug> #include <QDeclarativeParserStatus> #include <QAbstractItemModel> #include <QDeclarativeContext> @@ -75,10 +74,6 @@ QDeclarativeGeoMapItemView::~QDeclarativeGeoMapItemView() { if (map_) removeInstantiatedItems(); - // Remove group from map, and items from the group. This is to - // prevent their deletion. The items are owned by the - // declarative items and are to be deleted by them. - // TODO the concept of group objects need to be analyzed - is it needed anymore? } void QDeclarativeGeoMapItemView::componentComplete() diff --git a/src/imports/location/qdeclarativegeomapquickitem.cpp b/src/imports/location/qdeclarativegeomapquickitem.cpp index c9b9e0ee..0f0f070f 100644 --- a/src/imports/location/qdeclarativegeomapquickitem.cpp +++ b/src/imports/location/qdeclarativegeomapquickitem.cpp @@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE QDeclarativeGeoMapQuickItem::QDeclarativeGeoMapQuickItem(QQuickItem *parent) : QDeclarativeGeoMapItemBase(parent), - coordinate_(0), + coordinate_(&internalCoordinate_), sourceItem_(0), zoomLevel_(0.0), inUpdate_(false), diff --git a/tests/applications/declarative_map/map3d.qml b/tests/applications/declarative_map/map3d.qml index be8b0b51..c05e37f3 100644 --- a/tests/applications/declarative_map/map3d.qml +++ b/tests/applications/declarative_map/map3d.qml @@ -534,10 +534,9 @@ Rectangle { z: 11 objectName: "3d item" coordinate: londonCoordinate - sourceItem: Item {//Rectangle { + sourceItem: Item { width: 200 height: 200 - //color: Qt.rgba(0, 0, 1, 0) Viewport { width: 200 height: 200 @@ -600,9 +599,9 @@ Rectangle { } */ - /* + MapItemView { - id: theObjectView + id: theItemView model: testModel delegate: Component { MapQuickItem { @@ -637,7 +636,6 @@ Rectangle { } } } - */ // From location.test plugin PinchGenerator { @@ -827,7 +825,7 @@ Rectangle { //flick.onMovementEnded: {console.log ('movement ended signal M Stop ------------------ ') } onWheel: { - console.log('map wheel event, rotation in degrees: ' + delta/8); + //console.log('map wheel event, rotation in degrees: ' + delta/8); if (delta > 0) map.zoomLevel += 0.25 else map.zoomLevel -= 0.25 } diff --git a/tests/auto/declarative_ui/tst_map_itemview.qml b/tests/auto/declarative_ui/tst_map_itemview.qml index f2084279..4548582e 100644 --- a/tests/auto/declarative_ui/tst_map_itemview.qml +++ b/tests/auto/declarative_ui/tst_map_itemview.qml @@ -52,17 +52,58 @@ Item { Plugin { id: testPlugin; name : "nokia"; PluginParameter {name: "mapping.host"; value: "for.nonexistent"}} Coordinate{ id: mapDefaultCenter; latitude: 10; longitude: 30} - TestCase { - name: "MapItemView" - function test_todo() { + Map { + id: map + objectName: 'staticallyDeclaredMap' + center: mapDefaultCenter; + plugin: testPlugin; + width: 100 + height: 100 + zoomLevel: 2 + MapCircle { + id: prepopulatedCircle + objectName: 'prepopulatedCircle' + center: mapDefaultCenter; + radius: 100 } } - /* TODO - when we have map items + Map { + id: map3 + objectName: 'staticallyDeclaredMapWithView' + center: mapDefaultCenter; + plugin: testPlugin; + width: 100 + height: 100 + zoomLevel: 2 + MapItemView { + id: theItemView3 + model: testModel3 + delegate: Component { + MapCircle { + radius: 1500000 + center: Coordinate { + latitude: modeldata.coordinate.latitude; + longitude: modeldata.coordinate.longitude; + } + } + } + } + } MapCircle { - objectName: "externalCircle" id: externalCircle + objectName: 'externalCircle' + radius: 200 + center: mapDefaultCenter + } + + SignalSpy {id: mapItemSpy; target: map; signalName: 'mapItemsChanged'} + + + MapCircle { + objectName: "externalCircle2" + id: externalCircle2 radius: 2000000 center: mapDefaultCenter } @@ -77,18 +118,17 @@ Item { id: externalPolygon } - MapText { - id: externalText - } - - MapImage { - id: externalImage - } - MapPolyline { + objectName: 'externalPolyline' id: externalPolyline } + MapQuickItem { + objectName: 'externalQuickItem' + id: externalQuickItem + sourceItem: Rectangle {} + } + TestModel { id: testModel datatype: 'coordinate' @@ -103,16 +143,49 @@ Item { delay: 0 } + TestModel { + id: testModel3 + datatype: 'coordinate' + datacount: 0 + delay: 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} + ] + } + + RouteModel {id: routeModel; plugin: testPlugin_immediate; query: routeQuery } + SignalSpy {id: mapItemsChangedSpy; target: mapForViewWithoutPlugin; signalName: "mapItemsChanged"} + Map { - id: mapWithPlugin; center: mapDefaultCenter; plugin: testPlugin; - anchors.fill: parent; size.width: parent.width; size.height: parent.height; zoomLevel: 2 + id: mapForView; + center: mapDefaultCenter; + plugin: testPlugin; + anchors.fill: parent; + zoomLevel: 2 MapCircle { id: internalCircle radius: 2000000 center: mapDefaultCenter } MapItemView { - id: theObjectView + id: theItemView model: testModel delegate: Component { MapCircle { @@ -127,15 +200,17 @@ Item { } Map { - id: mapWithoutPlugin; center: mapDefaultCenter; - anchors.fill: parent; size.width: parent.width; size.height: parent.height; zoomLevel: 2 + id: mapForViewWithoutPlugin; + center: mapDefaultCenter; + anchors.fill: parent; + zoomLevel: 2 MapCircle { id: internalCircle2 radius: 2000000 center: mapDefaultCenter } MapItemView { - id: theObjectView2 + id: theItemView2 model: testModel delegate: Component { MapCircle { @@ -148,7 +223,7 @@ Item { } } MapItemView { - id: routeObjectView + id: routeItemView model: routeModel delegate: Component { MapRoute { @@ -159,166 +234,212 @@ Item { } TestCase { - name: "MapItemView" - function test_a_add_and_remove() { + name: "MapItem" + when: windowShown + function clear_data() { + mapItemSpy.clear() + } + + function test_aaa_basic_add_remove() { // aaa to ensure execution first + clear_data() + compare(map.mapItems.length, 1) + compare(map.mapItems[0], prepopulatedCircle) + compare(mapItemSpy.count, 0) + // nonexistent + map.removeMapItem(externalCircle) + compare(mapItemSpy.count, 0) + compare(map.mapItems.length, 1) + compare(map.mapItems[0], prepopulatedCircle) + // real + map.removeMapItem(prepopulatedCircle) + compare(mapItemSpy.count, 1) + compare(map.mapItems.length, 0) + map.addMapItem(externalCircle) + map.addMapItem(prepopulatedCircle) + compare(mapItemSpy.count, 3) + compare(map.mapItems.length, 2) + // same again + map.addMapItem(prepopulatedCircle) + compare(mapItemSpy.count, 3) + compare(map.mapItems.length, 2) + compare(map.mapItems[0], externalCircle) + compare(map.mapItems[1], prepopulatedCircle) + map.removeMapItem(externalCircle) + compare(map.mapItems[0], prepopulatedCircle) + compare(mapItemSpy.count, 4) + compare(map.mapItems.length, 1) + map.clearMapItems() + compare(mapItemSpy.count, 5) + compare(map.mapItems.length, 0) + // empty map, do not crash + map.clearMapItems() + compare(mapItemSpy.count, 5) + compare(map.mapItems.length, 0) + } + + function test_dynamic_map_and_items() { + clear_data(); + // basic create-destroy without items, mustn't crash + var dynamicMap = Qt.createQmlObject('import QtQuick 2.0; import QtLocation 5.0; Map { x:0; y:0; objectName: \'dynomik map\'; width: masterItem.width; height: masterItem.height; plugin: testPlugin} ', masterItem, "dynamicCreationErrors" ); + verify(dynamicMap !== null) + dynamicMap.destroy(1) + wait(5) + + // add rm add, destroy with item on it + dynamicMap = Qt.createQmlObject('import QtQuick 2.0; import QtLocation 5.0; Map { x:0; y:0; objectName: \'dynomik map\'; width: masterItem.width; height: masterItem.height; plugin: testPlugin} ', masterItem, "dynamicCreationErrors" ); + verify(dynamicMap !== null) + dynamicMap.addMapItem(externalCircle); + compare(dynamicMap.mapItems.length, 1) + dynamicMap.removeMapItem(externalCircle); + compare(dynamicMap.mapItems.length, 0) + dynamicMap.addMapItem(externalCircle); + compare(dynamicMap.mapItems.length, 1) + dynamicMap.destroy(1) + wait(5) + + // try adding same item to two maps, will not be allowed + var dynamicMap2 = Qt.createQmlObject('import QtQuick 2.0; import QtLocation 5.0; Map { x:0; y:0; objectName: \'dynomik map2\'; width: masterItem.width; height: masterItem.height; plugin: testPlugin} ', masterItem, "dynamicCreationErrors" ); + dynamicMap = Qt.createQmlObject('import QtQuick 2.0; import QtLocation 5.0; Map { x:0; y:0; objectName: \'dynomik map\'; width: masterItem.width; height: masterItem.height; plugin: testPlugin} ', masterItem, "dynamicCreationErrors" ); + verify(dynamicMap !== null) + verify(dynamicMap2 !== null) + compare(dynamicMap.mapItems.length, 0) + dynamicMap.addMapItem(externalCircle); + compare(dynamicMap.mapItems.length, 1) + dynamicMap2.addMapItem(externalCircle); + compare(dynamicMap2.mapItems.length, 0) + + // create and destroy a dynamic item that is in the map + var dynamicCircle = Qt.createQmlObject('import QtQuick 2.0; import QtLocation 5.0; MapCircle { objectName: \'dynamic circle 1\'; center: Coordinate { latitude: 5; longitude: 5 } radius: 15 } ', masterItem, "dynamicCreationErrors" ); + verify (dynamicCircle !== null) + compare(map.mapItems.length, 0) + map.addMapItem(dynamicCircle) + compare(mapItemSpy.count, 1) + compare(map.mapItems.length, 1) + dynamicCircle.destroy(1) + tryCompare(mapItemSpy, "count", 2) + compare(map.mapItems.length, 0) + + // leave one map item, will be destroyed at the end of the case + dynamicMap.addMapItem(externalCircle); + compare(dynamicMap.mapItems.length, 1) + + // leave a handful of item from model to the map and let it destroy + compare(map3.mapItems.length, 0) + testModel3.datacount = 4 + testModel3.update() + compare(map3.mapItems.length, 4) + } + + function test_add_and_remove_with_view() { // Basic adding and removing of static object - compare(mapWithPlugin.testGetDeclarativeMapObjectCount(), 8) - mapWithPlugin.addMapObject(internalCircle) - compare(mapWithPlugin.testGetDeclarativeMapObjectCount(), 8) - mapWithPlugin.removeMapObject(internalCircle) - compare(mapWithPlugin.testGetDeclarativeMapObjectCount(), 7) - mapWithPlugin.removeMapObject(internalCircle) - compare(mapWithPlugin.testGetDeclarativeMapObjectCount(), 7) + compare(mapForView.mapItems.length, 8) // 1 declared and 7 from model + mapForView.addMapItem(internalCircle) + compare(mapForView.mapItems.length, 8) + mapForView.removeMapItem(internalCircle) + compare(mapForView.mapItems.length, 7) + mapForView.removeMapItem(internalCircle) + compare(mapForView.mapItems.length, 7) // Basic adding and removing of dynamic object - var dynamicCircle = Qt.createQmlObject( "import QtQuick 2.0; import QtLocation 5.0; MapCircle {radius: 4000; center: mapDefaultCenter}", mapWithPlugin, ""); - mapWithPlugin.addMapObject(dynamicCircle) - compare(mapWithPlugin.testGetDeclarativeMapObjectCount(), 8) - mapWithPlugin.removeMapObject(dynamicCircle) - compare(mapWithPlugin.testGetDeclarativeMapObjectCount(), 7) - mapWithPlugin.removeMapObject(dynamicCircle) - compare(mapWithPlugin.testGetDeclarativeMapObjectCount(), 7) + var dynamicCircle = Qt.createQmlObject( "import QtQuick 2.0; import QtLocation 5.0; MapCircle {radius: 4000; center: mapDefaultCenter}", map, ""); + mapForView.addMapItem(dynamicCircle) + compare(mapForView.mapItems.length, 8) + mapForView.removeMapItem(dynamicCircle) + compare(mapForView.mapItems.length, 7) + mapForView.removeMapItem(dynamicCircle) + compare(mapForView.mapItems.length, 7) } - SignalSpy {id: model1Spy; target: testModel; signalName: "modelChanged"} SignalSpy {id: model2Spy; target: testModel2; signalName: "modelChanged"} - function test_b_model_change() { + function test_model_change() { // Change the model of an MapItemView on the fly // and verify that object counts change accordingly. - compare(mapWithPlugin.testGetDeclarativeMapObjectCount(), 7) + testModel.datacount = 7 + testModel.update() + compare(mapForView.mapItems.length, 7) testModel.datacount += 2 testModel2.datacount += 1 - compare(mapWithPlugin.testGetDeclarativeMapObjectCount(), 9) - theObjectView.model = testModel - compare(mapWithPlugin.testGetDeclarativeMapObjectCount(), 9) - theObjectView.model = testModel2 - compare(mapWithPlugin.testGetDeclarativeMapObjectCount(), 4) + compare(mapForView.mapItems.length, 9) + theItemView.model = testModel + compare(mapForView.mapItems.length, 9) + theItemView.model = testModel2 + compare(mapForView.mapItems.length, 4) } - SignalSpy {id: pluginChangedSpy; target: mapWithoutPlugin; signalName: "pluginChanged"} - function test_c_plugin_set_later() { - compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 0) - mapWithoutPlugin.plugin = testPlugin + SignalSpy {id: pluginChangedSpy; target: mapForViewWithoutPlugin; signalName: "pluginChanged"} + function test_plugin_set_later() { + testModel.datacount = 7 + testModel.update() + compare(mapForViewWithoutPlugin.mapItems.length, 8) // 7 from testModel, + 1 from mapcircle + mapForViewWithoutPlugin.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 + compare(mapForViewWithoutPlugin.mapItems.length, 8) + mapForViewWithoutPlugin.clearMapItems(); + compare(mapForViewWithoutPlugin.mapItems.length, 0) 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} - ] + compare(mapForViewWithoutPlugin.mapItems.length, 0) + testModel.reset(); + testModel.datacount = 7 + testModel.update() + compare(mapForViewWithoutPlugin.mapItems.length, 7) } - // 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) + + function test_routemodel() { + testModel.reset(); + mapItemsChangedSpy.clear() + compare(mapForViewWithoutPlugin.mapItems.length, 0) // precondition + compare(mapItemsChangedSpy.count, 0) routeQuery.numberAlternativeRoutes = 4 routeModel.update(); - compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 4) - compare(mapWithoutPlugin.objects.length, 0) + compare(mapForViewWithoutPlugin.mapItems.length, 4) routeQuery.numberAlternativeRoutes = 3 routeModel.update(); - compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 3) - compare(mapWithoutPlugin.objects.length, 0) + compare(mapForViewWithoutPlugin.mapItems.length, 3) routeModel.clear(); - compare(mapWithoutPlugin.testGetDeclarativeMapObjectCount(), 0) - compare(mapWithoutPlugin.objects.length, 0) + compare(mapForViewWithoutPlugin.mapItems.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 QtLocation 5.0; Map {plugin: testPlugin;}", masterItem, ""); - var dynamicCircle = Qt.createQmlObject("import QtQuick 2.0; import QtLocation 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 QtLocation 5.0; MapRectangle {}", masterItem, ""); - dynamicMap.addMapObject(dynamicRectangle) - dynamicMap.destroy(2); wait(100) // must act gracefully although has objects when destroyed + compare(mapForViewWithoutPlugin.mapItems.length, 3) + mapForViewWithoutPlugin.addMapItem(externalCircle2) + compare(mapForViewWithoutPlugin.mapItems.length, 4) + compare(mapForViewWithoutPlugin.mapItems[3], externalCircle2) + routeModel.reset(); + compare(mapForViewWithoutPlugin.mapItems.length, 1) + mapForViewWithoutPlugin.clearMapItems() + compare(mapForViewWithoutPlugin.mapItems.length, 0) + + // Test the mapItems list + mapForViewWithoutPlugin.addMapItem(externalCircle2) + compare(mapForViewWithoutPlugin.mapItems.length, 1) + compare(mapForViewWithoutPlugin.mapItems[0], externalCircle2) + + mapForViewWithoutPlugin.addMapItem(externalRectangle) + compare(mapForViewWithoutPlugin.mapItems.length, 2) + compare(mapForViewWithoutPlugin.mapItems[1], externalRectangle) + + mapForViewWithoutPlugin.addMapItem(externalRectangle) + compare(mapForViewWithoutPlugin.mapItems.length, 2) + compare(mapForViewWithoutPlugin.mapItems[1], externalRectangle) + + mapForViewWithoutPlugin.addMapItem(externalPolygon) + compare(mapForViewWithoutPlugin.mapItems.length, 3) + compare(mapForViewWithoutPlugin.mapItems[2], externalPolygon) + + mapForViewWithoutPlugin.addMapItem(externalQuickItem) + compare(mapForViewWithoutPlugin.mapItems.length, 4) + compare(mapForViewWithoutPlugin.mapItems[3], externalQuickItem) + + mapForViewWithoutPlugin.removeMapItem(externalCircle2) + compare(mapForViewWithoutPlugin.mapItems.length, 3) + compare(mapForViewWithoutPlugin.mapItems[0], externalRectangle) + + mapForViewWithoutPlugin.removeMapItem(externalRectangle) + compare(mapForViewWithoutPlugin.mapItems.length, 2) + compare(mapForViewWithoutPlugin.mapItems[0], externalPolygon) + + mapForViewWithoutPlugin.clearMapItems() + compare(mapForViewWithoutPlugin.mapItems.length, 0) } } - */ } diff --git a/tests/plugins/declarativetestplugin/qdeclarativelocationtestmodel.cpp b/tests/plugins/declarativetestplugin/qdeclarativelocationtestmodel.cpp index 12718054..0455d09a 100644 --- a/tests/plugins/declarativetestplugin/qdeclarativelocationtestmodel.cpp +++ b/tests/plugins/declarativetestplugin/qdeclarativelocationtestmodel.cpp @@ -196,6 +196,11 @@ void QDeclarativeLocationTestModel::repopulate() endResetModel(); } +void QDeclarativeLocationTestModel::update() +{ + scheduleRepopulation(); +} + void QDeclarativeLocationTestModel::reset() { if (timer_.isActive()) diff --git a/tests/plugins/declarativetestplugin/qdeclarativelocationtestmodel_p.h b/tests/plugins/declarativetestplugin/qdeclarativelocationtestmodel_p.h index 2fb2296f..762db365 100644 --- a/tests/plugins/declarativetestplugin/qdeclarativelocationtestmodel_p.h +++ b/tests/plugins/declarativetestplugin/qdeclarativelocationtestmodel_p.h @@ -105,6 +105,7 @@ public: //Q_INVOKABLE void clear(); Q_INVOKABLE void reset(); + Q_INVOKABLE void update(); //Q_INVOKABLE void reset(); signals: |