summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjuhvu <qt-info@nokia.com>2011-10-20 11:24:34 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-20 07:08:21 +0200
commit0acb68f58dc276faea85c74311fee3920a99eac6 (patch)
tree43843899bad652d583eff61ec58438a4c6d5abfc
parent8f765817b02e72356a0a4461b2889344fdc83dea (diff)
downloadqtlocation-0acb68f58dc276faea85c74311fee3920a99eac6.tar.gz
QML Map pinch and flick part 1/3
Autotest fw changes. First autotests and related fixes. Map initialization order changed to avoid blinking in hardcoded geocoordinate during app startup. Change-Id: Iaad879c135b6283957e0705b991474517f933485 Reviewed-by: David Laing <david.laing@nokia.com>
-rw-r--r--examples/declarative/map3d/map3d.qml21
-rw-r--r--src/imports/location/qdeclarative3dgraphicsgeomap.cpp167
-rw-r--r--src/imports/location/qdeclarative3dgraphicsgeomap_p.h3
-rw-r--r--src/imports/location/qdeclarativegeomapflickable.cpp21
-rw-r--r--src/imports/location/qdeclarativegeomapflickable_p.h4
-rw-r--r--src/imports/location/qdeclarativegeomappincharea.cpp39
-rw-r--r--src/location/maps/qgeomappingmanager.cpp23
-rw-r--r--src/location/maps/qgeomappingmanager.h2
-rw-r--r--src/location/maps/qgeomappingmanagerengine.cpp40
-rw-r--r--src/location/maps/qgeomappingmanagerengine.h2
-rw-r--r--src/location/maps/qgeomappingmanagerengine_p.h2
-rw-r--r--src/plugins/geoservices/nokia/qgeomappingmanagerengine_nokia.cpp6
-rw-r--r--tests/auto/declarative/tst_map.qml10
-rw-r--r--tests/auto/declarative/tst_map_mouse.qml1
-rw-r--r--tests/auto/declarative/tst_map_pinch_and_flick.qml438
-rw-r--r--tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp88
-rw-r--r--tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h22
17 files changed, 780 insertions, 109 deletions
diff --git a/examples/declarative/map3d/map3d.qml b/examples/declarative/map3d/map3d.qml
index a2d8ace1..a1964ca0 100644
--- a/examples/declarative/map3d/map3d.qml
+++ b/examples/declarative/map3d/map3d.qml
@@ -184,6 +184,22 @@ Item {
onClicked: { mapCenterCoordinate.altitude -= 1}
}
}
+ Rectangle {color: "lightblue"; width: 80; height: 40;
+ Text {text: "Click:\pinch"}
+ MouseArea{ anchors.fill: parent;
+ onClicked: {
+ pinchGenerator.pinch(
+ Qt.point(100,100), // point1From
+ Qt.point(150,150), // point1To
+ Qt.point(300,300), // point2From
+ Qt.point(150,150), // point2To
+ 20, // interval between touch events (swipe1), default 20ms
+ 20, // interval between touch events (swipe2), defualt 20ms
+ 10, // number of touchevents in point1from -> point1to, default 10
+ 10); // number of touchevents in point2from -> point2to, default 10
+ }
+ }
+ }
}
/*
@@ -244,13 +260,11 @@ Item {
Map {
id: map
-
MapMouseArea {
id: mapMouseArea
onDoubleClicked: console.log('mapmousearea got clicked')
anchors.fill: parent
}
-
MapItem {
id: externalStaticMapItem1
visible: true
@@ -269,7 +283,6 @@ Item {
}
}
-
MapItem {
objectName: 'blinky static item'
zoomLevel: 7 // at which map's zoom level the width and height are '1-to-1'
@@ -382,7 +395,7 @@ Item {
//anchors.fill: page
width: page.width - 80
height: 1000
- zoomLevel: 5.1
+ zoomLevel: 9
// pinch.activeGestures: MapPinch.ZoomGesture | RotationGesture
pinch.activeGestures: MapPinch.NoGesture
diff --git a/src/imports/location/qdeclarative3dgraphicsgeomap.cpp b/src/imports/location/qdeclarative3dgraphicsgeomap.cpp
index 1d5a8d2e..f0778dd7 100644
--- a/src/imports/location/qdeclarative3dgraphicsgeomap.cpp
+++ b/src/imports/location/qdeclarative3dgraphicsgeomap.cpp
@@ -111,10 +111,10 @@ QDeclarative3DGraphicsGeoMap::QDeclarative3DGraphicsGeoMap(QSGItem *parent)
serviceProvider_(0),
mappingManager_(0),
center_(0),
- initialCoordinate(0),
// mapType_(NoMap),
// connectivityMode_(NoConnectivity),
componentCompleted_(false),
+ mappingManagerInitialized_(false),
flickable_(0),
pinchArea_(0),
mouseGrabberItem_(0),
@@ -123,25 +123,17 @@ QDeclarative3DGraphicsGeoMap::QDeclarative3DGraphicsGeoMap(QSGItem *parent)
tileCache_(0)
{
QLOC_TRACE0;
- initialCoordinate = new QGeoCoordinate(-27.0, 153.0);
zoomLevel_ = 8;
size_ = QSizeF(100.0, 100.0);
setAcceptHoverEvents(false);
setAcceptedMouseButtons(Qt::LeftButton | Qt::MidButton | Qt::RightButton);
setFlags(QSGItem::ItemHasContents);
+ // Create internal flickable and pinch area.
tileCache_ = new TileCache();
map_ = new Map(tileCache_, this);
- connect(map_,
- SIGNAL(updateRequired()),
- this,
- SLOT(update()));
- connect(map_,
- SIGNAL(cameraDataChanged(CameraData)),
- this,
- SLOT(cameraDataChanged(CameraData)));
- // Create internal flickable and pinch area.
- flickable_ = new QDeclarativeGeoMapFlickable(map_, this);
+ flickable_ = new QDeclarativeGeoMapFlickable(this);
+ flickable_->setMap(map_);
pinchArea_ = new QDeclarativeGeoMapPinchArea(this, this);
setRenderTarget(QSGPaintedItem::FramebufferObject);
}
@@ -193,9 +185,6 @@ QDeclarative3DGraphicsGeoMap::~QDeclarative3DGraphicsGeoMap()
mouseAreas_.clear();
if (serviceProvider_)
delete serviceProvider_;
- if (initialCoordinate) {
- delete initialCoordinate;
- }
}
void QDeclarative3DGraphicsGeoMap::componentComplete()
@@ -203,12 +192,6 @@ void QDeclarative3DGraphicsGeoMap::componentComplete()
QLOC_TRACE0;
componentCompleted_ = true;
populateMap();
- map_->resize(width(), height());
- CameraData cameraData = map_->cameraData();
- map_->setCameraData(cameraData);
- map_->update();
- if (mappingManager_)
- pinchArea_->zoomLevelLimits(mappingManager_->minimumZoomLevel(), mappingManager_->maximumZoomLevel());
QSGItem::componentComplete();
}
@@ -226,8 +209,6 @@ void QDeclarative3DGraphicsGeoMap::itemChange(ItemChange change, const ItemChang
void QDeclarative3DGraphicsGeoMap::populateMap()
{
- if (!componentCompleted_)
- return;
QObjectList kids = children();
for (int i = 0; i < kids.size(); ++i) {
// dispatch items appropriately
@@ -277,6 +258,8 @@ qreal ViewportSubsurface::aspectRatio() const
void QDeclarative3DGraphicsGeoMap::updateAspectRatio()
{
+ if (!mappingManagerInitialized_)
+ return;
map_->resize(width(), height());
if (!map_->autoUpdate())
map_->update();
@@ -291,6 +274,8 @@ void QDeclarative3DGraphicsGeoMap::geometryChanged(const QRectF &newGeometry, co
void QDeclarative3DGraphicsGeoMap::keyPressEvent(QKeyEvent *e)
{
+ if (!mappingManagerInitialized_)
+ return;
QLOC_TRACE2(" key: ", e->key());
CameraData cameraData = map_->cameraData();
if (e->key() == Qt::Key_Left) {
@@ -357,7 +342,7 @@ void QDeclarative3DGraphicsGeoMap::keyPressEvent(QKeyEvent *e)
void QDeclarative3DGraphicsGeoMap::paint(QPainter* p)
{
- if (!isVisible())
+ if (!isVisible() || !mappingManagerInitialized_)
return;
QGLPainter painter(p);
@@ -398,6 +383,8 @@ void QDeclarative3DGraphicsGeoMap::paint(QPainter* p)
void QDeclarative3DGraphicsGeoMap::setCameraData(const CameraData &camera)
{
+ if (!mappingManagerInitialized_)
+ return;
map_->setCameraData(camera);
if (!map_->autoUpdate())
map_->update();
@@ -405,6 +392,8 @@ void QDeclarative3DGraphicsGeoMap::setCameraData(const CameraData &camera)
CameraData QDeclarative3DGraphicsGeoMap::cameraData() const
{
+ if (!mappingManagerInitialized_)
+ return CameraData();
return map_->cameraData();
}
@@ -464,10 +453,8 @@ void QDeclarative3DGraphicsGeoMap::earlyDraw(QGLPainter *painter)
void QDeclarative3DGraphicsGeoMap::paintGL(QGLPainter *painter)
{
- if (map_) {
- painter->projectionMatrix().scale(1,-1, 1); // qt3d and qsg interpret y differently
- map_->paintGL(painter);
- }
+ painter->projectionMatrix().scale(1,-1, 1); // qt3d and qsg interpret y differently
+ map_->paintGL(painter);
}
/*!
@@ -504,8 +491,11 @@ void QDeclarative3DGraphicsGeoMap::setPlugin(QDeclarativeGeoServiceProvider *plu
mappingManager_ = 0;
return;
}
-
- map_->setMappingManager(mappingManager_);
+ pinchArea_->zoomLevelLimits(mappingManager_->minimumZoomLevel(), mappingManager_->maximumZoomLevel());
+ if (!mappingManager_->isInitialized())
+ connect(mappingManager_, SIGNAL(initialized()), this, SLOT(mappingManagerInitialized()));
+ else
+ mappingManagerInitialized();
// mapData_ = mappingManager_->createMapData();
// mapData_->init();
@@ -523,8 +513,6 @@ void QDeclarative3DGraphicsGeoMap::setPlugin(QDeclarativeGeoServiceProvider *plu
// mapData_->setMapType(QGraphicsGeoMap::MapType(mapType_));
// mapData_->setConnectivityMode(QGraphicsGeoMap::ConnectivityMode(connectivityMode_));
- // Populate the map objects.
- populateMap();
// setup signals
// connect(mapData_,
// SIGNAL(updateMapDisplay(QRectF)),
@@ -557,6 +545,27 @@ void QDeclarative3DGraphicsGeoMap::setPlugin(QDeclarativeGeoServiceProvider *plu
// SIGNAL(zoomLevelChanged(qreal)));
}
+// this function will only be ever called once
+void QDeclarative3DGraphicsGeoMap::mappingManagerInitialized()
+{
+ mappingManagerInitialized_ = true;
+ connect(map_,
+ SIGNAL(updateRequired()),
+ this,
+ SLOT(update()));
+ connect(map_,
+ SIGNAL(cameraDataChanged(CameraData)),
+ this,
+ SLOT(cameraDataChanged(CameraData)));
+ map_->setMappingManager(mappingManager_);
+ map_->resize(width(), height());
+ CameraData cameraData = map_->cameraData();
+ cameraData.setCenter(center_->coordinate());
+ cameraData.setZoomFactor(zoomLevel_);
+ map_->setCameraData(cameraData);
+ map_->update();
+}
+
void QDeclarative3DGraphicsGeoMap::updateMapDisplay(const QRectF &target)
{
Q_UNUSED(target);
@@ -643,12 +652,17 @@ void QDeclarative3DGraphicsGeoMap::setZoomLevel(qreal zoomLevel)
{
if (zoomLevel_ == zoomLevel)
return;
+ if (!componentCompleted_) {
+ zoomLevel_ = zoomLevel;
+ return;
+ }
if (mappingManager_ &&
(zoomLevel < mappingManager_->minimumZoomLevel() ||
- zoomLevel > mappingManager_->maximumZoomLevel()))
+ zoomLevel > mappingManager_->maximumZoomLevel())) {
return;
+ }
zoomLevel_ = zoomLevel;
- if (map_) {
+ if (mappingManagerInitialized_) {
CameraData cameraData = map_->cameraData();
cameraData.setZoomFactor(zoomLevel);
map_->setCameraData(cameraData);
@@ -660,11 +674,10 @@ void QDeclarative3DGraphicsGeoMap::setZoomLevel(qreal zoomLevel)
qreal QDeclarative3DGraphicsGeoMap::zoomLevel() const
{
- if (map_) {
+ if (mappingManagerInitialized_)
return map_->cameraData().zoomFactor();
- } else {
+ else
return zoomLevel_;
- }
}
/*!
@@ -695,7 +708,7 @@ void QDeclarative3DGraphicsGeoMap::setCenter(QDeclarativeCoordinate *center)
SIGNAL(altitudeChanged(double)),
this,
SLOT(centerAltitudeChanged(double)));
- if (center_->coordinate().isValid()) {
+ if (center_->coordinate().isValid() && mappingManagerInitialized_) {
CameraData cameraData = map_->cameraData();
cameraData.setCenter(center_->coordinate());
map_->setCameraData(cameraData);
@@ -708,7 +721,10 @@ void QDeclarative3DGraphicsGeoMap::setCenter(QDeclarativeCoordinate *center)
QDeclarativeCoordinate* QDeclarative3DGraphicsGeoMap::center()
{
if (!center_) {
- center_ = new QDeclarativeCoordinate(map_->cameraData().center());
+ if (mappingManagerInitialized_)
+ center_ = new QDeclarativeCoordinate(map_->cameraData().center());
+ else
+ center_ = new QDeclarativeCoordinate(QGeoCoordinate(0,0));
connect(center_,
SIGNAL(latitudeChanged(double)),
this,
@@ -727,6 +743,8 @@ QDeclarativeCoordinate* QDeclarative3DGraphicsGeoMap::center()
void QDeclarative3DGraphicsGeoMap::cameraDataChanged(const CameraData &cameraData)
{
+ if (!componentCompleted_)
+ return;
// check what has changed and emit appropriate signals
if (!center_ || cameraData.center() != center_->coordinate()) {
QDeclarativeCoordinate* currentCenter = center();
@@ -743,12 +761,14 @@ void QDeclarative3DGraphicsGeoMap::centerLatitudeChanged(double latitude)
{
if (qIsNaN(latitude))
return;
- CameraData cameraData = map_->cameraData();
- QGeoCoordinate coord = cameraData.center();
- coord.setLatitude(latitude);
- cameraData.setCenter(coord);
- map_->setCameraData(cameraData);
- update();
+ if (mappingManagerInitialized_) {
+ CameraData cameraData = map_->cameraData();
+ QGeoCoordinate coord = cameraData.center();
+ coord.setLatitude(latitude);
+ cameraData.setCenter(coord);
+ map_->setCameraData(cameraData);
+ update();
+ }
emit centerChanged(center_);
}
@@ -756,12 +776,14 @@ void QDeclarative3DGraphicsGeoMap::centerLongitudeChanged(double longitude)
{
if (qIsNaN(longitude))
return;
- CameraData cameraData = map_->cameraData();
- QGeoCoordinate coord = cameraData.center();
- coord.setLongitude(longitude);
- cameraData.setCenter(coord);
- map_->setCameraData(cameraData);
- update();
+ if (mappingManagerInitialized_) {
+ CameraData cameraData = map_->cameraData();
+ QGeoCoordinate coord = cameraData.center();
+ coord.setLongitude(longitude);
+ cameraData.setCenter(coord);
+ map_->setCameraData(cameraData);
+ update();
+ }
emit centerChanged(center_);
}
@@ -769,12 +791,14 @@ void QDeclarative3DGraphicsGeoMap::centerAltitudeChanged(double altitude)
{
if (qIsNaN(altitude))
return;
- CameraData cameraData = map_->cameraData();
- QGeoCoordinate coord = cameraData.center();
- coord.setAltitude(altitude);
- cameraData.setCenter(coord);
- map_->setCameraData(cameraData);
- update();
+ if (mappingManagerInitialized_) {
+ CameraData cameraData = map_->cameraData();
+ QGeoCoordinate coord = cameraData.center();
+ coord.setAltitude(altitude);
+ cameraData.setCenter(coord);
+ map_->setCameraData(cameraData);
+ update();
+ }
emit centerChanged(center_);
}
@@ -888,7 +912,7 @@ void QDeclarative3DGraphicsGeoMap::centerAltitudeChanged(double altitude)
QDeclarativeCoordinate* QDeclarative3DGraphicsGeoMap::toCoordinate(QPointF screenPosition) const
{
QGeoCoordinate coordinate;
- if (map_)
+ if (mappingManagerInitialized_)
coordinate = map_->screenPositionToCoordinate(screenPosition);
// by default objects returned from method call get javascript ownership,
// so we don't need to worry about this as long as we don't set the parent
@@ -908,7 +932,7 @@ QDeclarativeCoordinate* QDeclarative3DGraphicsGeoMap::toCoordinate(QPointF scree
QPointF QDeclarative3DGraphicsGeoMap::toScreenPosition(QDeclarativeCoordinate* coordinate) const
{
QPointF point;
- if (map_)
+ if (mappingManagerInitialized_)
point = map_->coordinateToScreenPosition(coordinate->coordinate());
return point;
}
@@ -922,6 +946,10 @@ void QDeclarative3DGraphicsGeoMap::pan(int dx, int dy)
void QDeclarative3DGraphicsGeoMap::touchEvent(QTouchEvent *event)
{
+ if (!mappingManagerInitialized_) {
+ event->ignore();
+ return;
+ }
QLOC_TRACE0;
event->accept();
pinchArea_->touchEvent(event);
@@ -1005,6 +1033,10 @@ bool QDeclarative3DGraphicsGeoMap::deliverInitialMousePressEvent(QDeclarativeGeo
void QDeclarative3DGraphicsGeoMap::mousePressEvent(QMouseEvent *event)
{
QLOC_TRACE2(" ~~~~~~~ event, coordinates: ", event->pos());
+ if (!mappingManagerInitialized_) {
+ event->ignore();
+ return;
+ }
bool consumed = deliverMouseEvent(event);
consumed |= flickable_->mousePressEvent(event);
if (consumed)
@@ -1029,6 +1061,10 @@ QList<QDeclarativeGeoMapMouseArea*> QDeclarative3DGraphicsGeoMap::mouseAreasAt(Q
void QDeclarative3DGraphicsGeoMap::mouseReleaseEvent(QMouseEvent *event)
{
QLOC_TRACE2(" ~~~~~~~ event, coordinates: ", event->pos());
+ if (!mappingManagerInitialized_) {
+ event->ignore();
+ return;
+ }
bool consumed = false;
if (mouseGrabberItem_) {
consumed = deliverMouseEvent(event);
@@ -1044,6 +1080,10 @@ void QDeclarative3DGraphicsGeoMap::mouseReleaseEvent(QMouseEvent *event)
void QDeclarative3DGraphicsGeoMap::mouseDoubleClickEvent(QMouseEvent *event)
{
QLOC_TRACE2(" ~~~~~~~ event, coordinates: ", event->pos());
+ if (!mappingManagerInitialized_) {
+ event->ignore();
+ return;
+ }
if (!mouseGrabberItem_ && (event->button() & event->buttons()) == event->buttons()) {
QList<QDeclarativeGeoMapMouseArea*> mouseAreas = mouseAreasAt(event->pos());
for (int i = 0; i < mouseAreas.count(); ++i) {
@@ -1063,7 +1103,10 @@ void QDeclarative3DGraphicsGeoMap::mouseDoubleClickEvent(QMouseEvent *event)
void QDeclarative3DGraphicsGeoMap::mouseMoveEvent(QMouseEvent *event)
{
- //QLOC_TRACE2(" ~~~~~~~ event, coordinates: ", event->pos());
+ if (!mappingManagerInitialized_) {
+ event->ignore();
+ return;
+ }
bool consumed = false;
if (mouseGrabberItem_)
consumed = deliverMouseEvent(event);
@@ -1126,7 +1169,7 @@ void QDeclarative3DGraphicsGeoMap::removeMapItem(QDeclarativeGeoMapItem *item)
{
QLOC_TRACE0;
#ifdef QSGSHADEREFFECTSOURCE_AVAILABLE
- if (!item)
+ if (!item || !map_)
return;
if (mapItemsPending_.contains(item)) {
mapItemsPending_.removeAll(item);
@@ -1151,7 +1194,7 @@ void QDeclarative3DGraphicsGeoMap::removeMapItem(QDeclarativeGeoMapItem *item)
// TODO clears all items including ones from models/MapItemview which is not intended
void QDeclarative3DGraphicsGeoMap::clearMapItems()
{
- if (mapItems_.isEmpty())
+ if (mapItems_.isEmpty() || !map_)
return;
updateMutex_.lock();
mapItems_.clear();
diff --git a/src/imports/location/qdeclarative3dgraphicsgeomap_p.h b/src/imports/location/qdeclarative3dgraphicsgeomap_p.h
index 2fd4ed25..c178e172 100644
--- a/src/imports/location/qdeclarative3dgraphicsgeomap_p.h
+++ b/src/imports/location/qdeclarative3dgraphicsgeomap_p.h
@@ -221,6 +221,7 @@ private Q_SLOTS:
void centerAltitudeChanged(double altitude);
void mapItemDestroyed(QObject* item);
void cameraDataChanged(const CameraData &cameraData);
+ void mappingManagerInitialized();
private:
void setupMapView(QDeclarativeGeoMapItemView *view);
@@ -252,12 +253,12 @@ private:
qreal zoomLevel_;
QPointer<QDeclarativeCoordinate> center_;
- QGeoCoordinate* initialCoordinate;
// QDeclarative3DGraphicsGeoMap::MapType mapType_;
// QDeclarative3DGraphicsGeoMap::ConnectivityMode connectivityMode_;
QSizeF size_;
bool componentCompleted_;
+ bool mappingManagerInitialized_;
QList<QDeclarativeGeoMapItemView*> mapViews_;
QDeclarativeGeoMapFlickable* flickable_;
diff --git a/src/imports/location/qdeclarativegeomapflickable.cpp b/src/imports/location/qdeclarativegeomapflickable.cpp
index 41eb2ea8..4646f529 100644
--- a/src/imports/location/qdeclarativegeomapflickable.cpp
+++ b/src/imports/location/qdeclarativegeomapflickable.cpp
@@ -80,32 +80,35 @@ const qreal MinimumFlickVelocity = 75.0;
QT_BEGIN_NAMESPACE
-QDeclarativeGeoMapFlickable::QDeclarativeGeoMapFlickable(Map* map, QObject *parent)
+QDeclarativeGeoMapFlickable::QDeclarativeGeoMapFlickable(QObject *parent)
: QObject(parent),
pressed_(false),
maxVelocity_(QML_FLICK_DEFAULTMAXVELOCITY),
deceleration_(QML_FLICK_DEFAULTDECELERATION),
flicking_(false),
- map_(map),
+ map_(0),
enabled_(false),
moving_(false)
{
- Q_ASSERT(map_);
pressTime_.invalidate();
lastPosTime_.invalidate();
velocityTime_.invalidate();
- //animation_ = new QPropertyAnimation(map_->mapCamera(), "cameraData", this);
- //animation_ = new QPropertyAnimation(map_->mapCamera(), "center", this);
- animation_ = new QPropertyAnimation(map_, "camera", this);
- animation_->setEasingCurve(QEasingCurve(QEasingCurve::OutQuad));
- connect(animation_, SIGNAL(finished()), this, SLOT(flickAnimationFinished()));
- //connect(animation_, SIGNAL(valueChanged(const QVariant&)), this, SLOT(flickAnimationValueChanged(const QVariant&)));
}
QDeclarativeGeoMapFlickable::~QDeclarativeGeoMapFlickable()
{
}
+void QDeclarativeGeoMapFlickable::setMap(Map* map)
+{
+ if (map_ || !map)
+ return;
+ map_ = map;
+ animation_ = new QPropertyAnimation(map_, "camera", this);
+ animation_->setEasingCurve(QEasingCurve(QEasingCurve::OutQuad));
+ connect(animation_, SIGNAL(finished()), this, SLOT(flickAnimationFinished()));
+}
+
qreal QDeclarativeGeoMapFlickable::deceleration() const
{
return deceleration_;
diff --git a/src/imports/location/qdeclarativegeomapflickable_p.h b/src/imports/location/qdeclarativegeomapflickable_p.h
index ee2e7ced..8b57343a 100644
--- a/src/imports/location/qdeclarativegeomapflickable_p.h
+++ b/src/imports/location/qdeclarativegeomapflickable_p.h
@@ -71,7 +71,7 @@ class QDeclarativeGeoMapFlickable: public QObject
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged())
public:
- QDeclarativeGeoMapFlickable(Map* map, QObject *parent = 0);
+ QDeclarativeGeoMapFlickable(QObject *parent = 0);
~QDeclarativeGeoMapFlickable();
qreal deceleration() const;
@@ -80,6 +80,8 @@ public:
bool enabled() const;
void setEnabled(bool enabled);
+ void setMap(Map* map);
+
bool mousePressEvent(QMouseEvent *event);
bool mouseMoveEvent(QMouseEvent *event);
bool mouseReleaseEvent(QMouseEvent *event);
diff --git a/src/imports/location/qdeclarativegeomappincharea.cpp b/src/imports/location/qdeclarativegeomappincharea.cpp
index d0e0feb7..016be089 100644
--- a/src/imports/location/qdeclarativegeomappincharea.cpp
+++ b/src/imports/location/qdeclarativegeomappincharea.cpp
@@ -55,10 +55,10 @@ QDeclarativeGeoMapPinchArea::QDeclarativeGeoMapPinchArea(QDeclarative3DGraphicsG
map_(map),
enabled_(true),
active_(false),
- minimumZoomLevel_(0.0),
- maximumZoomLevel_(100.0),
+ minimumZoomLevel_(-1.0),
+ maximumZoomLevel_(-1.0),
minimumRotation_(0.0),
- maximumRotation_(0.0),
+ maximumRotation_(45.0),
inPinch_(false),
pinchRejected_(false),
pinchActivated_(false),
@@ -71,10 +71,11 @@ QDeclarativeGeoMapPinchArea::QDeclarativeGeoMapPinchArea(QDeclarative3DGraphicsG
pinchRotation_(0.0),
id1_(-1),
maximumZoomLevelChange_(2.0),
+ rotationSpeed_(1.0),
activeGestures_(ZoomGesture | RotationGesture),
minimumTilt_(0.0),
maximumTilt_(90.0),
- maximumTiltChange_(10.0),
+ maximumTiltChange_(20.0),
pinchLastTilt_(0.0),
pinchStartTilt_(0.0)
{
@@ -108,7 +109,7 @@ void QDeclarativeGeoMapPinchArea::setActive(bool active)
{
if (active == active_)
return;
- active = active_;
+ active_ = active;
emit activeChanged();
}
@@ -121,7 +122,7 @@ void QDeclarativeGeoMapPinchArea::setEnabled(bool enabled)
{
if (enabled == enabled_)
return;
- enabled = enabled_;
+ enabled_ = enabled;
emit enabledChanged();
}
@@ -132,7 +133,9 @@ qreal QDeclarativeGeoMapPinchArea::minimumZoomLevel() const
void QDeclarativeGeoMapPinchArea::setMinimumZoomLevel(qreal zoomLevel)
{
- if (zoomLevel == minimumZoomLevel_ || zoomLevel < map_->minimumZoomLevel())
+ if (zoomLevel == minimumZoomLevel_ ||
+ zoomLevel < map_->minimumZoomLevel() ||
+ (maximumZoomLevel_ != -1.0 && zoomLevel > maximumZoomLevel_) )
return;
minimumZoomLevel_ = zoomLevel;
emit minimumZoomLevelChanged();
@@ -145,7 +148,9 @@ qreal QDeclarativeGeoMapPinchArea::maximumZoomLevel() const
void QDeclarativeGeoMapPinchArea::setMaximumZoomLevel(qreal zoomLevel)
{
- if (zoomLevel == maximumZoomLevel_ || zoomLevel > map_->maximumZoomLevel())
+ if (zoomLevel == maximumZoomLevel_ ||
+ zoomLevel > map_->maximumZoomLevel() ||
+ (minimumZoomLevel_ != - 1.0 && zoomLevel < minimumZoomLevel_))
return;
maximumZoomLevel_ = zoomLevel;
emit maximumZoomLevelChanged();
@@ -156,9 +161,9 @@ void QDeclarativeGeoMapPinchArea::setMaximumZoomLevel(qreal zoomLevel)
// it possible to check against mapping plugins' limits)
void QDeclarativeGeoMapPinchArea::zoomLevelLimits(qreal min, qreal max)
{
- if (min > minimumZoomLevel_)
+ if (minimumZoomLevel_ == -1.0 || min > minimumZoomLevel_)
setMinimumZoomLevel(min);
- if (max < maximumZoomLevel_)
+ if (maximumZoomLevel_ == -1.0 || max < maximumZoomLevel_)
setMaximumZoomLevel(max);
}
@@ -169,7 +174,7 @@ qreal QDeclarativeGeoMapPinchArea::maximumZoomLevelChange() const
void QDeclarativeGeoMapPinchArea::setMaximumZoomLevelChange(qreal maxChange)
{
- if (maxChange == maximumZoomLevelChange_ || maxChange < 0.1)
+ if (maxChange == maximumZoomLevelChange_ || maxChange < 0.1 || maxChange > 10.0)
return;
maximumZoomLevelChange_ = maxChange;
emit maximumZoomLevelChangeChanged();
@@ -182,7 +187,9 @@ qreal QDeclarativeGeoMapPinchArea::minimumRotation() const
void QDeclarativeGeoMapPinchArea::setMinimumRotation(qreal rotation)
{
- if (rotation == minimumRotation_ || rotation < 0.1)
+ if (rotation == minimumRotation_ ||
+ rotation < 0 ||
+ rotation > maximumRotation_)
return;
minimumRotation_ = rotation;
emit minimumRotationChanged();
@@ -195,7 +202,9 @@ qreal QDeclarativeGeoMapPinchArea::maximumRotation() const
void QDeclarativeGeoMapPinchArea::setMaximumRotation(qreal rotation)
{
- if (rotation == maximumRotation_ || rotation > 360)
+ if (rotation == maximumRotation_ ||
+ rotation > 360 ||
+ rotation < minimumRotation_)
return;
maximumRotation_ = rotation;
emit maximumRotationChanged();
@@ -208,7 +217,9 @@ qreal QDeclarativeGeoMapPinchArea::rotationSpeed() const
void QDeclarativeGeoMapPinchArea::setRotationSpeed(qreal speed)
{
- if (rotationSpeed_ == speed || speed < 0.1)
+ if (rotationSpeed_ == speed ||
+ speed < 0 ||
+ speed > 10)
return;
rotationSpeed_ = speed;
emit rotationSpeedChanged();
diff --git a/src/location/maps/qgeomappingmanager.cpp b/src/location/maps/qgeomappingmanager.cpp
index 6cc8a5fe..37a59c57 100644
--- a/src/location/maps/qgeomappingmanager.cpp
+++ b/src/location/maps/qgeomappingmanager.cpp
@@ -123,6 +123,11 @@ QGeoMappingManager::QGeoMappingManager(QGeoMappingManagerEngine *engine, QObject
SLOT(threadStarted()),
Qt::QueuedConnection);
+ connect(d_ptr->engine,
+ SIGNAL(initialized()),
+ this,
+ SIGNAL(initialized()));
+
d_ptr->engine->moveToThread(d_ptr->thread);
QTimer::singleShot(0, d_ptr->thread, SLOT(start()));
}
@@ -136,6 +141,13 @@ QGeoMappingManager::~QGeoMappingManager()
}
/*!
+ \fn void QGeoMappingManager::initialized()
+
+ This signal is emitted when the mapping manager has been initialized
+ and is ready to be used.
+*/
+
+/*!
Returns the name of the engine which implements the behaviour of this
mapping manager.
@@ -232,6 +244,17 @@ bool QGeoMappingManager::supportsBearing() const
}
/*!
+ Return whether the manager has been initialized
+ (will be done automatically but may take some time).
+
+*/
+bool QGeoMappingManager::isInitialized() const
+{
+ return d_ptr->engine->isInitialized();
+}
+
+
+/*!
Return whether tilting is supported by this manager.
*/
bool QGeoMappingManager::supportsTilting() const
diff --git a/src/location/maps/qgeomappingmanager.h b/src/location/maps/qgeomappingmanager.h
index deac7227..33d42426 100644
--- a/src/location/maps/qgeomappingmanager.h
+++ b/src/location/maps/qgeomappingmanager.h
@@ -94,6 +94,7 @@ public:
qreal maximumZoomLevel() const;
bool supportsBearing() const;
+ bool isInitialized() const;
bool supportsTilting() const;
qreal minimumTilt() const;
@@ -106,6 +107,7 @@ Q_SIGNALS:
void tileFinished(const TileSpec &spec, const QByteArray &bytes);
void tileError(const TileSpec &spec, const QString &errorString);
void queueFinished();
+ void initialized();
private:
QGeoMappingManager(QGeoMappingManagerEngine *engine, QObject *parent = 0);
diff --git a/src/location/maps/qgeomappingmanagerengine.cpp b/src/location/maps/qgeomappingmanagerengine.cpp
index b70cd5a8..242c2e02 100644
--- a/src/location/maps/qgeomappingmanagerengine.cpp
+++ b/src/location/maps/qgeomappingmanagerengine.cpp
@@ -79,6 +79,7 @@ QGeoMappingManagerEngine::QGeoMappingManagerEngine(const QMap<QString, QVariant>
d_ptr(new QGeoMappingManagerEnginePrivate())
{
d_ptr->parameters = parameters;
+ d_ptr->initialized = false;
}
/*!
@@ -103,8 +104,21 @@ QMap<QString, QVariant> QGeoMappingManagerEngine::parameters() const
return d->parameters;
}
+/*!
+ Initializes the engine. Subclasses of QGeoMappingManagerEngine may
+ implement this function to perform (potentially asynchronous) initialization.
+
+ Static/already known data (such as min/max zoom levels) is better to
+ initialize already earlier (e.g. in constructor).
+
+ Once subclasses are done with initialization, they should call this baseclass
+ implementation of init().
+*/
void QGeoMappingManagerEngine::init()
{
+ Q_D(QGeoMappingManagerEngine);
+ d->initialized = true;
+ emit initialized();
}
void QGeoMappingManagerEngine::threadStarted()
@@ -344,6 +358,17 @@ QSize QGeoMappingManagerEngine::tileSize() const
return d->tileSize;
}
+
+/*!
+ Return whether the engine has been initialized and is ready to be used.
+*/
+
+bool QGeoMappingManagerEngine::isInitialized() const
+{
+ Q_D(const QGeoMappingManagerEngine);
+ return d->initialized;
+}
+
/*!
Sets the minimum zoom level supported by this engine to \a minimumZoom.
@@ -360,6 +385,17 @@ void QGeoMappingManagerEngine::setMinimumZoomLevel(qreal minimumZoom)
}
/*!
+ \fn void QGeoMappingManagerEngine::initialized()
+
+ This signal is emitted when the mapping manager has been initialized
+ and is ready to be used.
+
+ Subclasses of QGeoMappingManagerEngine should call the
+ QGeoMappingManagerEngine init() when they have initialized themselves.
+*/
+
+
+/*!
Sets the maximum zoom level supported by this engine to \a maximumZoom.
Larger values of the zoom level correspond to more detailed views of the
@@ -503,8 +539,8 @@ QLocale QGeoMappingManagerEngine::locale() const
QGeoMappingManagerEnginePrivate::QGeoMappingManagerEnginePrivate()
: managerVersion(-1),
- minimumZoomLevel(1.0),
- maximumZoomLevel(20.0), // todo fixme, this needs to come from plugin
+ minimumZoomLevel(-2.0),
+ maximumZoomLevel(-2.0), // todo fixme, this needs to come from plugin
supportsBearing(false),
supportsTilting(false),
minimumTilt(0.0),
diff --git a/src/location/maps/qgeomappingmanagerengine.h b/src/location/maps/qgeomappingmanagerengine.h
index 9beb567b..d9df0017 100644
--- a/src/location/maps/qgeomappingmanagerengine.h
+++ b/src/location/maps/qgeomappingmanagerengine.h
@@ -97,6 +97,7 @@ public:
QLocale locale() const;
virtual void init();
+ bool isInitialized() const;
public Q_SLOTS:
void threadStarted();
@@ -110,6 +111,7 @@ Q_SIGNALS:
void tileFinished(const TileSpec &spec, const QByteArray &bytes);
void tileError(const TileSpec &spec, const QString &errorString);
void queueFinished();
+ void initialized();
protected:
QGeoMappingManagerEngine(QGeoMappingManagerEnginePrivate *dd, QObject *parent = 0);
diff --git a/src/location/maps/qgeomappingmanagerengine_p.h b/src/location/maps/qgeomappingmanagerengine_p.h
index e262cc2c..bbfed6f8 100644
--- a/src/location/maps/qgeomappingmanagerengine_p.h
+++ b/src/location/maps/qgeomappingmanagerengine_p.h
@@ -88,8 +88,8 @@ public:
qreal maximumTilt;
QLocale locale;
-
bool started_;
+ bool initialized;
QTimer *timer_;
QList<TileSpec> queue_;
QHash<QGeoTiledMapReply*, TileSpec> map_;
diff --git a/src/plugins/geoservices/nokia/qgeomappingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeomappingmanagerengine_nokia.cpp
index 164e9460..74475d5d 100644
--- a/src/plugins/geoservices/nokia/qgeomappingmanagerengine_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeomappingmanagerengine_nokia.cpp
@@ -115,6 +115,8 @@ QGeoMappingManagerEngineNokia::QGeoMappingManagerEngineNokia(const QMap<QString,
{
Q_UNUSED(error)
Q_UNUSED(errorString)
+ setMinimumZoomLevel(0.0);
+ setMaximumZoomLevel(20.0);
}
QGeoMappingManagerEngineNokia::~QGeoMappingManagerEngineNokia() {}
@@ -122,9 +124,6 @@ QGeoMappingManagerEngineNokia::~QGeoMappingManagerEngineNokia() {}
void QGeoMappingManagerEngineNokia::init()
{
setTileSize(QSize(256, 256));
- setMinimumZoomLevel(0.0);
- setMaximumZoomLevel(20.0);
-
// QList<QGraphicsGeoMap::MapType> types;
// types << QGraphicsGeoMap::StreetMap;
// types << QGraphicsGeoMap::SatelliteMapDay;
@@ -206,6 +205,7 @@ void QGeoMappingManagerEngineNokia::init()
m_networkManager->setCache(m_cache);
}
#endif
+ QGeoMappingManagerEngine::init();
}
QGeoTiledMapReply* QGeoMappingManagerEngineNokia::getTileImage(const TileSpec &spec)
diff --git a/tests/auto/declarative/tst_map.qml b/tests/auto/declarative/tst_map.qml
index 6625a255..68ee1e7b 100644
--- a/tests/auto/declarative/tst_map.qml
+++ b/tests/auto/declarative/tst_map.qml
@@ -63,6 +63,12 @@ Item {
function test_aa_map_properties_without_plugin() {
// TODO
+ compare(pluginlessMap.minimumZoomLevel, -1.0)
+ compare(pluginlessMap.maximumZoomLevel, -1.0)
+ // set the plugin and see that values change properly
+ pluginlessMap.plugin = nokiaPlugin;
+ compare(pluginlessMap.minimumZoomLevel, 0)
+ compare(pluginlessMap.maximumZoomLevel, 20)
}
function test_ab_map_properties_with_plugin() {
// TODO
@@ -73,8 +79,8 @@ Item {
compare(pluginlessMap.center.latitude, 10)
compare(pluginlessMap.center.longitude, 11)
// default coordinate (coordinate is not explicitly set)
- compare(map.center.latitude, -27.5)
- compare(map.center.longitude, 153)
+ compare(map.center.latitude, 0)
+ compare(map.center.longitude, 0)
map.center.latitude = 5
compare(centerSpy.count, 1)
map.center.longitude = 10
diff --git a/tests/auto/declarative/tst_map_mouse.qml b/tests/auto/declarative/tst_map_mouse.qml
index fa4a1cd7..62847940 100644
--- a/tests/auto/declarative/tst_map_mouse.qml
+++ b/tests/auto/declarative/tst_map_mouse.qml
@@ -288,6 +288,7 @@ Item {
function test_aaa_basic_properties() // _aaa_ to ensure execution first
{
clear_data()
+ wait(50)
// default values
compare(mouseUpper.containsMouse, false)
compare(mouseUpper.pressed, false)
diff --git a/tests/auto/declarative/tst_map_pinch_and_flick.qml b/tests/auto/declarative/tst_map_pinch_and_flick.qml
new file mode 100644
index 00000000..9b327fa2
--- /dev/null
+++ b/tests/auto/declarative/tst_map_pinch_and_flick.qml
@@ -0,0 +1,438 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtTest 1.0
+import QtLocation 5.0
+import QtLocation.test 5.0
+
+Item {
+ // General-purpose elements for the test:
+ id: page
+ width: 100
+ height: 100
+ //Plugin { id: testPlugin; name: "qmlgeo.test.plugin" }
+ Plugin { id: nokiaPlugin; name: "nokia"; PluginParameter {name: "mapping.host"; value: "for.nonexistent"} }
+ Coordinate{ id: coordinate1; latitude: 10; longitude: 11}
+ Coordinate{ id: coordinate2; latitude: 12; longitude: 13}
+ Map {
+ id: map
+ plugin: nokiaPlugin
+ center: coordinate1;
+ zoomLevel: 9;
+ anchors.fill: page
+ x:0; y:0
+ }
+
+ SignalSpy {id: centerSpy; target: map; signalName: 'centerChanged'}
+ SignalSpy {id: coordinate2LatitudeSpy; target: coordinate2; signalName: 'latitudeChanged'}
+ SignalSpy {id: coordinate2LongitudeSpy; target: coordinate2; signalName: 'longitudeChanged'}
+ SignalSpy {id: coordinate2AltitudeSpy; target: coordinate2; signalName: 'altitudeChanged'}
+ SignalSpy {id: pinchStartedSpy; target: map.pinch; signalName: 'pinchStarted'}
+ SignalSpy {id: pinchUpdatedSpy; target: map.pinch; signalName: 'pinchUpdated'}
+ SignalSpy {id: pinchFinishedSpy; target: map.pinch; signalName: 'pinchFinished'}
+ SignalSpy {id: pinchMaximumZoomLevelChangeSpy; target: map.pinch; signalName: 'maximumZoomLevelChangeChanged'}
+ SignalSpy {id: pinchMinimumZoomLevelSpy; target: map.pinch; signalName: 'minimumZoomLevelChanged'}
+ SignalSpy {id: pinchMaximumZoomLevelSpy; target: map.pinch; signalName: 'maximumZoomLevelChanged'}
+ SignalSpy {id: pinchMinimumRotationSpy; target: map.pinch; signalName: 'minimumRotationChanged'}
+ SignalSpy {id: pinchMaximumRotationSpy; target: map.pinch; signalName: 'maximumRotationChanged'}
+ SignalSpy {id: pinchRotationSpeedSpy; target: map.pinch; signalName: 'rotationSpeedChanged'}
+ SignalSpy {id: pinchEnabledSpy; target: map.pinch; signalName: 'enabledChanged'}
+ SignalSpy {id: pinchActiveSpy; target: map.pinch; signalName: 'activeChanged'}
+ SignalSpy {id: pinchActiveGesturesSpy; target: map.pinch; signalName: 'activeGesturesChanged'}
+
+ // From QtLocation.test plugin
+ PinchGenerator {
+ id: pinchGenerator
+ anchors.fill: parent
+ target: map
+ enabled: false
+ }
+
+ TestCase {
+ when: windowShown
+ name: "Map pinch"
+
+ function clear_data() {
+ centerSpy.clear()
+ coordinate2AltitudeSpy.clear()
+ coordinate2LatitudeSpy.clear()
+ coordinate2LongitudeSpy.clear()
+ pinchStartedSpy.clear()
+ pinchUpdatedSpy.clear()
+ pinchFinishedSpy.clear()
+ pinchMaximumZoomLevelChangeSpy.clear()
+ pinchMinimumZoomLevelSpy.clear()
+ pinchMaximumZoomLevelSpy.clear()
+ pinchMinimumRotationSpy.clear()
+ pinchMaximumRotationSpy.clear()
+ pinchRotationSpeedSpy.clear()
+ pinchEnabledSpy.clear()
+ pinchActiveSpy.clear()
+ pinchActiveGesturesSpy.clear()
+ }
+
+ function test_basic_properties() {
+ clear_data()
+
+ // pinch
+ compare(map.pinch.enabled, true)
+ map.pinch.enabled = false
+ compare(pinchEnabledSpy.count, 1)
+ compare(map.pinch.enabled, false)
+ map.pinch.enabled = false
+ compare(pinchEnabledSpy.count, 1)
+ compare(map.pinch.enabled, false)
+ map.pinch.enabled = true
+ compare(pinchEnabledSpy.count, 2)
+ compare(map.pinch.enabled, true)
+
+ compare(map.pinch.active, false)
+
+ verify(map.pinch.activeGestures & MapPinch.ZoomGesture)
+ verify(map.pinch.activeGestures & MapPinch.RotationGesture)
+ verify(!(map.pinch.activeGestures & MapPinch.TiltGesture))
+ map.pinch.activeGestures = MapPinch.NoGesture
+ compare(map.pinch.activeGestures, MapPinch.NoGesture)
+ compare(pinchActiveGesturesSpy.count, 1)
+ map.pinch.activeGestures = MapPinch.NoGesture
+ compare(map.pinch.activeGestures, MapPinch.NoGesture)
+ compare(pinchActiveGesturesSpy.count, 1)
+ map.pinch.activeGestures = MapPinch.ZoomGesture | MapPinch.RotationGesture
+ compare(map.pinch.activeGestures, MapPinch.ZoomGesture | MapPinch.RotationGesture)
+ compare(pinchActiveGesturesSpy.count, 2)
+ map.pinch.activeGestures = MapPinch.RotationGesture
+ compare(map.pinch.activeGestures, MapPinch.RotationGesture)
+ compare(pinchActiveGesturesSpy.count, 3)
+ map.pinch.activeGestures = MapPinch.ZoomGesture
+ compare(map.pinch.activeGestures, MapPinch.ZoomGesture)
+ compare(pinchActiveGesturesSpy.count, 4)
+
+ compare(map.pinch.minimumZoomLevel, map.minimumZoomLevel)
+ map.pinch.minimumZoomLevel = 5
+ compare(pinchMinimumZoomLevelSpy.count, 1)
+ compare(map.pinch.minimumZoomLevel, 5)
+ map.pinch.minimumZoomLevel = -1 // too small
+ map.pinch.minimumZoomLevel = 492 // too big
+ compare(pinchMinimumZoomLevelSpy.count, 1)
+ compare(map.pinch.minimumZoomLevel, 5)
+ map.pinch.minimumZoomLevel = map.minimumZoomLevel
+ compare(pinchMinimumZoomLevelSpy.count, 2)
+ compare(map.pinch.minimumZoomLevel, map.minimumZoomLevel)
+
+ compare(map.pinch.maximumZoomLevel, map.maximumZoomLevel)
+ map.pinch.maximumZoomLevel = 9
+ compare (pinchMaximumZoomLevelSpy.count, 1)
+ compare(map.pinch.maximumZoomLevel, 9)
+ map.pinch.maximumZoomLevel = -1 // too small
+ map.pinch.maximumZoomLevel = 3234 // too big
+ compare(pinchMaximumZoomLevelSpy.count, 1)
+ compare(map.pinch.maximumZoomLevel, 9)
+ map.pinch.maximumZoomLevel = map.maximumZoomLevel
+ compare(pinchMaximumZoomLevelSpy.count, 2)
+ compare(map.pinch.maximumZoomLevel, map.maximumZoomLevel)
+
+ clear_data()
+ map.pinch.minimumZoomLevel = 5 // ok
+ map.pinch.maximumZoomLevel = 9 // ok
+ map.pinch.minimumZoomLevel = 10 // bigger than max
+ map.pinch.maximumZoomLevel = 4 // smaller than min
+ compare (pinchMaximumZoomLevelSpy.count, 1)
+ compare (pinchMinimumZoomLevelSpy.count, 1)
+ compare(map.pinch.maximumZoomLevel, 9)
+ compare(map.pinch.minimumZoomLevel, 5)
+ map.pinch.minimumZoomLevel = map.minimumZoomLevel
+ map.pinch.maximumZoomLevel = map.maximumZoomLevel
+
+ compare(map.pinch.maximumZoomLevelChange, 2)
+ map.pinch.maximumZoomLevelChange = 4
+ compare(pinchMaximumZoomLevelChangeSpy.count, 1)
+ compare (map.pinch.maximumZoomLevelChange, 4)
+ map.pinch.maximumZoomLevelChange = 4
+ compare(pinchMaximumZoomLevelChangeSpy.count, 1)
+ compare (map.pinch.maximumZoomLevelChange, 4)
+ map.pinch.maximumZoomLevelChange = 11 // too big
+ map.pinch.maximumZoomLevelChange = 0.01 // too small
+ map.pinch.maximumZoomLevelChange = -1 // too small
+ compare(pinchMaximumZoomLevelChangeSpy.count, 1)
+ compare (map.pinch.maximumZoomLevelChange, 4)
+ map.pinch.maximumZoomLevelChange = 2
+ compare(pinchMaximumZoomLevelChangeSpy.count, 2)
+ compare (map.pinch.maximumZoomLevelChange, 2)
+
+ compare(map.pinch.minimumRotation, 0)
+ map.pinch.minimumRotation = 10
+ compare(pinchMinimumRotationSpy.count, 1)
+ compare(map.pinch.minimumRotation, 10)
+ map.pinch.minimumRotation = 10
+ compare(pinchMinimumRotationSpy.count, 1)
+ compare(map.pinch.minimumRotation, 10)
+ map.pinch.minimumRotation = -1 // too small
+ map.pinch.minimumRotation = 361 // too big
+ compare(pinchMinimumRotationSpy.count, 1)
+ compare(map.pinch.minimumRotation, 10)
+ map.pinch.minimumRotation = 0
+ compare(pinchMinimumRotationSpy.count, 2)
+ compare(map.pinch.minimumRotation, 0)
+
+ compare(map.pinch.maximumRotation, 45)
+ map.pinch.maximumRotation = 55
+ compare(pinchMaximumRotationSpy.count,1)
+ compare(map.pinch.maximumRotation, 55)
+ map.pinch.maximumRotation = 55
+ compare(pinchMaximumRotationSpy.count,1)
+ compare(map.pinch.maximumRotation, 55)
+ map.pinch.maximumRotation = -1 // too small
+ map.pinch.maximumRotation = 362 // too big
+ compare(pinchMaximumRotationSpy.count,1)
+ compare(map.pinch.maximumRotation, 55)
+ map.pinch.maximumRotation = 45
+ compare(pinchMaximumRotationSpy.count,2)
+ compare(map.pinch.maximumRotation, 45)
+
+ compare(map.pinch.rotationSpeed, 1)
+ map.pinch.rotationSpeed = 2
+ compare(pinchRotationSpeedSpy.count, 1)
+ compare(map.pinch.rotationSpeed, 2)
+ map.pinch.rotationSpeed = 2
+ compare(pinchRotationSpeedSpy.count, 1)
+ compare(map.pinch.rotationSpeed, 2)
+ map.pinch.rotationSpeed = -1 // too small
+ map.pinch.rotationSpeed = 11 // too big
+ compare(pinchRotationSpeedSpy.count, 1)
+ compare(map.pinch.rotationSpeed, 2)
+ map.pinch.rotationSpeed = 1
+ compare(pinchRotationSpeedSpy.count, 2)
+ compare(map.pinch.rotationSpeed, 1)
+
+ compare(map.pinch.maximumTilt, 90)
+ compare(map.pinch.minimumTilt, 0)
+ compare(map.pinch.maximumTiltChange, 20)
+
+ // flick
+
+
+ }
+
+ function test_pinch_rotation() {
+ map.pinch.activeGestures = MapPinch.RotationGesture
+ clear_data()
+ // todo
+
+ }
+
+
+ function test_pinch_zoom() {
+ map.pinch.activeGestures = MapPinch.ZoomGesture
+ clear_data()
+ // 1. typical zoom in
+ compare(map.zoomLevel, 9)
+ map.pinch.maximumZoomLevelChange = 2
+ compare(map.pinch.active, false)
+ pinchGenerator.pinch(
+ Qt.point(0,50), // point1From
+ Qt.point(50,50), // point1To
+ Qt.point(100,50), // point2From
+ Qt.point(50,50), // point2To
+ 20, // interval between touch events (swipe1), default 20ms
+ 20, // interval between touch events (swipe2), default 20ms
+ 10, // number of touchevents in point1from -> point1to, default 10
+ 10); // number of touchevents in point2from -> point2to, default 10
+ tryCompare(pinchStartedSpy, "count", 1);
+ wait(50);
+ compare(pinchActiveSpy.count,1) // check that pinch is active
+ compare(map.pinch.active, true)
+ wait(200);
+ verify(pinchUpdatedSpy.count >= 5); // verify 'sane' number of updates received
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(pinchActiveSpy.count,2)
+ compare(map.pinch.active, false)
+ compare(map.zoomLevel, 8)
+ // 2. typical zoom out
+ clear_data();
+ map.pinch.maximumZoomLevelChange = 2
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50));
+ tryCompare(pinchStartedSpy, "count", 1);
+ wait(250);
+ verify(pinchUpdatedSpy.count >= 5); // verify 'sane' number of updates received
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 9)
+ // 3. zoom in and back out (direction change during same pinch)
+ clear_data();
+ pinchGenerator.pinch(Qt.point(0,50), Qt.point(100,50), Qt.point(100,50),Qt.point(0,50));
+ tryCompare(pinchStartedSpy, "count", 1);
+ wait(250);
+ verify(pinchUpdatedSpy.count >= 5); // verify 'sane' number of updates received
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 9) // should remain the same
+ // 4. typical zoom in with different change level
+ clear_data();
+ map.pinch.maximumZoomLevelChange = 4
+ compare (map.pinch.maximumZoomLevelChange, 4)
+ pinchGenerator.pinch(Qt.point(0,50),Qt.point(50,50),Qt.point(100,50),Qt.point(50,50));
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 7)
+ // 5. typical zoom out with different change level
+ clear_data();
+ map.pinch.maximumZoomLevelChange = 1
+ compare (map.pinch.maximumZoomLevelChange, 1)
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50));
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 7.5)
+
+ // 6. try to zoom in below minimum zoom level
+ clear_data()
+ map.pinch.maximumZoomLevelChange = 4
+ map.pinch.minimumZoomLevel = 7
+ pinchGenerator.pinch(Qt.point(0,50),Qt.point(50,50),Qt.point(100,50),Qt.point(50,50));
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 7) // would go to 5.5
+
+ // 7. try to zoom out above maximum zoom level
+ clear_data()
+ map.pinch.maximumZoomLevelChange = 4
+ map.pinch.maximumZoomLevel = 8
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50));
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 8) // would go to 9
+
+ // 8. pinch when max and min are same
+ clear_data()
+ map.pinch.maximumZoomLevel = 8
+ map.pinch.minimumZoomLevel = 8
+ compare(map.pinch.maximumZoomLevel, 8)
+ compare(map.pinch.minimumZoomLevel, 8)
+ pinchGenerator.pinch(Qt.point(0,50),Qt.point(50,50),Qt.point(100,50),Qt.point(50,50));
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 8)
+
+ // 9. pinch when max..min is not where map zoomLevel currently is
+ clear_data()
+ map.pinch.maximumZoomLevelChange = 4
+ map.pinch.minimumZoomLevel = 4
+ map.pinch.maximumZoomLevel = 6
+ // first when above the zoom range
+ map.zoomLevel = 10
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50)); // zoom out
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 1);
+ compare(map.zoomLevel, 6)
+ map.zoomLevel = 10
+ pinchGenerator.pinch(Qt.point(0,50),Qt.point(50,50),Qt.point(100,50),Qt.point(50,50)); // zoom in
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 2);
+ compare(map.zoomLevel, 6)
+ console.log('the zoomLevel after pinching outside of range: ' + map.zoomLevel)
+ pinchGenerator.pinch(Qt.point(0,50),Qt.point(50,50),Qt.point(100,50),Qt.point(50,50)); // zoom in
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 3);
+ compare(map.zoomLevel, 4)
+ // when below the zoom range
+ map.zoomLevel = 1
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50)); // zoom out
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 4);
+ compare(map.zoomLevel, 4)
+ map.zoomLevel = 1
+ pinchGenerator.pinch(Qt.point(0,50),Qt.point(50,50),Qt.point(100,50),Qt.point(50,50)); // zoom in
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 5);
+ compare(map.zoomLevel, 4)
+ console.log('the zoomLevel after pinching outside of range: ' + map.zoomLevel)
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50)); // zoom out
+ wait(250);
+ tryCompare(pinchFinishedSpy, "count", 6);
+ compare(map.zoomLevel, 6)
+ map.pinch.minimumZoomLevel = map.minimumZoomLevel
+ map.pinch.maximumZoomLevel = map.maximumZoomLevel
+
+ // 10. pinch while pinch area is disabled
+ clear_data()
+ map.pinch.enabled = false
+ map.pinch.maximumZoomLevelChange = 2
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50));
+ wait(100);
+ compare(pinchActiveSpy.count, 0)
+ compare(map.pinch.active, false)
+ compare(pinchStartedSpy.count, 0)
+ compare(pinchUpdatedSpy.count, 0);
+ compare(pinchFinishedSpy.count, 0);
+ compare(map.zoomLevel, 6)
+ pinchGenerator.stop()
+ map.pinch.enabled = true
+
+ // 11. pinch disabling during pinching
+ clear_data()
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50));
+ wait(250)
+ map.pinch.enabled = false
+ // check that pinch is active. then disable the pinch. pinch area should still process
+ // as long as it is active
+ compare(pinchActiveSpy.count,1)
+ compare(map.pinch.active, true)
+ compare(pinchStartedSpy.count, 1)
+ compare(pinchFinishedSpy.count, 0)
+ var pinchupdates = pinchUpdatedSpy.count
+ console.log('this many pinches there were ------ ' + pinchupdates)
+ verify(pinchupdates > 0)
+ tryCompare(pinchFinishedSpy, "count", 1)
+ compare(pinchActiveSpy.count,2)
+ compare(map.pinch.active, false)
+ map.pinch.enabled = true
+
+ // 12. check nuthin happens if no active gestures
+ clear_data()
+ map.pinch.activeGestures = MapPinch.NoGesture
+ pinchGenerator.pinch(Qt.point(50,50), Qt.point(0,50),Qt.point(50,50), Qt.point(100,50));
+ tryCompare(pinchStartedSpy, "count", 0);
+ wait(250);
+ compare(pinchUpdatedSpy.count, 0);
+ compare(pinchStartedSpy.count, 0);
+ compare(map.zoomLevel, 7)
+ map.pinch.activeGestures = MapPinch.ZoomGesture
+ }
+ }
+}
diff --git a/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp b/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp
index c32c77ef..05c24287 100644
--- a/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp
+++ b/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp
@@ -120,8 +120,13 @@ void QDeclarativePinchGenerator::setEnabled(bool enabled)
QTouchEvent::TouchPoint QDeclarativePinchGenerator::mouseEventToTouchPoint(QMouseEvent *event)
{
+ return createTouchPoint(event->type(), event->pos());
+}
+
+QTouchEvent::TouchPoint QDeclarativePinchGenerator::createTouchPoint(QEvent::Type type, QPoint pos)
+{
QTouchEvent::TouchPoint touchPoint;
- switch (event->type()) {
+ switch (type) {
//case QEvent::GraphicsSceneMousePress:
case QEvent::MouseButtonPress:
touchPoint.setState(Qt::TouchPointPressed);
@@ -140,10 +145,10 @@ QTouchEvent::TouchPoint QDeclarativePinchGenerator::mouseEventToTouchPoint(QMous
//touchPoint.setId(touchPointId_++); // running number
touchPoint.setId(0);
touchPoint.setPressure(0.75);
- touchPoint.setPos(event->pos());
- touchPoint.setLastPos(event->pos());
- touchPoint.setScenePos(target_->mapToScene(event->pos()));
- touchPoint.setLastScenePos(target_->mapToScene(event->pos()));
+ touchPoint.setPos(pos);
+ touchPoint.setLastPos(pos);
+ touchPoint.setScenePos(target_->mapToScene(pos));
+ touchPoint.setLastScenePos(target_->mapToScene(pos));
return touchPoint;
}
@@ -434,6 +439,79 @@ Q_INVOKABLE void QDeclarativePinchGenerator::replay()
setState(Replaying);
}
+void QDeclarativePinchGenerator::pinch(QPoint point1From,
+ QPoint point1To,
+ QPoint point2From,
+ QPoint point2To,
+ int interval1,
+ int interval2,
+ int samples1,
+ int samples2)
+{
+ //qDebug() << __FUNCTION__ << point1From << point1To << point2From << point2To << interval1 << interval2 << samples1 << samples2 << state_;
+ Q_ASSERT(state_ == Idle);
+ //Q_ASSERT(!point1From.isNull());
+ //Q_ASSERT(!point1To.isNull());
+ //Q_ASSERT(!point2From.isNull());
+ //Q_ASSERT(!point2To.isNull());
+ Q_ASSERT(interval1 > 10);
+ Q_ASSERT(interval2 > 10);
+ Q_ASSERT(samples1 >= 2); // we need press and release events at minimum
+ Q_ASSERT(samples2 >= 2);
+
+ // generate swipes based on the parameters
+ if (!swipes_.isEmpty()) {
+ qDeleteAll(swipes_);
+ swipes_.clear();
+ }
+ generateSwipe(point1From, point1To, interval1, samples1);
+ generateSwipe(point2From, point2To, interval2, samples2);
+ Q_ASSERT(swipes_.at(0));
+ Q_ASSERT(swipes_.at(1));
+
+ if (swipes_.at(0)->touchPoints.count() >= swipes_.at(1)->touchPoints.count())
+ masterSwipe_ = 0;
+ else
+ masterSwipe_ = 1;
+ replayTimer_ = startTimer(swipes_.at(masterSwipe_)->touchPointDurations.at(0) / replaySpeedFactor_);
+ replayBookmark_ = 0;
+ setState(Replaying);
+}
+
+void QDeclarativePinchGenerator::generateSwipe(QPoint from, QPoint to, int interval, int samples)
+{
+ //qDebug() << __FUNCTION__ << "generate swipe from, to, interval, samplecount: " << from << to << interval << samples;
+ int deltaX = (to.x() - from.x()) / samples;
+ int deltaY = (to.y() - from.y()) / samples;
+ //qDebug() << __FUNCTION__ << "deltaX, deltaY: " << deltaX << deltaY;
+ Q_ASSERT(qAbs(deltaX) > 0 || qAbs(deltaY) > 0);
+
+ activeSwipe_ = new Swipe;
+ // create press event
+ activeSwipe_->touchPointDurations.append(interval);
+ activeSwipe_->totalDuration += interval;
+ activeSwipe_->touchPoints.append(createTouchPoint(QEvent::MouseButtonPress, from));
+ //qDebug() << __FUNCTION__ << "press X, Y: " << from.x() << from.y();
+
+ // create move events
+ for (int i = 1; i < samples - 1; ++i) {
+ activeSwipe_->touchPointDurations.append(interval);
+ activeSwipe_->totalDuration += interval;
+ int nextX = from.x() + (i * deltaX);
+ int nextY = from.y() + (i * deltaY);
+ //qDebug() << __FUNCTION__ << "move X, Y: " << nextX << nextY;
+ activeSwipe_->touchPoints.append(createTouchPoint(QEvent::MouseMove, QPoint(nextX, nextY)));
+ }
+ // create release event
+ activeSwipe_->touchPointDurations.append(interval);
+ activeSwipe_->totalDuration += interval;
+ activeSwipe_->touchPoints.append(createTouchPoint(QEvent::MouseButtonRelease, to));
+ //qDebug() << __FUNCTION__ << "release X, Y: " << to.x() << to.y();
+
+ // append the swipe
+ swipes_.append(activeSwipe_);
+}
+
Q_INVOKABLE void QDeclarativePinchGenerator::clear()
{
stop();
diff --git a/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h b/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h
index 536d09f9..f3017903 100644
--- a/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h
+++ b/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h
@@ -43,12 +43,13 @@
#define QDECLARATIVEPINCHGENERATOR_H
#include <QtDeclarative/QSGItem>
-#include <QMouseEvent>
-#include <QElapsedTimer>
-#include <QTouchEvent>
#include <QSGCanvas>
-#include <QKeyEvent>
-#include <QList>
+#include <QtGui/QMouseEvent>
+#include <QtGui/QTouchEvent>
+#include <QtGui/QKeyEvent>
+#include <QtCore/QElapsedTimer>
+#include <QtCore/QList>
+#include <QtCore/QPoint>
#include <QDebug>
// how many concurrent "swipes" should we have
@@ -112,6 +113,15 @@ public:
Q_INVOKABLE void clear();
Q_INVOKABLE void stop();
+ // programmatic interface, useful for autotests
+ Q_INVOKABLE void pinch(QPoint point1From,
+ QPoint point1To,
+ QPoint point2From,
+ QPoint point2To,
+ int interval1 = 20,
+ int interval2 = 20,
+ int samples1 = 10,
+ int samples2 = 10);
signals:
void stateChanged();
void countChanged();
@@ -144,7 +154,9 @@ protected:
private:
void setState(GeneratorState state);
QTouchEvent::TouchPoint mouseEventToTouchPoint(QMouseEvent* event);
+ QTouchEvent::TouchPoint createTouchPoint(QEvent::Type type, QPoint pos);
QTouchEvent::TouchPoint convertToPrimary(QTouchEvent::TouchPoint original);
+ void generateSwipe(QPoint from, QPoint to, int duration, int samples);
private:
QSGItem* target_;