summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2017-07-25 17:11:32 +0200
committerBogDan Vatra <bogdan@kdab.com>2017-08-24 12:16:32 +0000
commit8ac6377e62af803b567449cdf30c669b92114cc4 (patch)
tree0a8d9d797df2dbc32524f28510712f2ceacde764
parent2dc1acb63777c983cfc4cbdbd2176a8dab112209 (diff)
Make QGeoRoute extensible
This change makes it possible to subclass QGeoRoute, QGeoRouteSegment or QGeoRouteManeuver, with custom private implementations. It also attempts to minimize the cost that creating a QDeclarativeGeoRoute currently has, by deferring the initialization of QDeclarativeGeoRoute::segments_ to the first access, and also populating the list only to the requested point. Change-Id: I4c87391bcc380ddca6523c748ebb97d2a44ed9d2 Reviewed-by: BogDan Vatra <bogdan@kdab.com>
-rw-r--r--src/location/declarativemaps/qdeclarativegeoroute.cpp53
-rw-r--r--src/location/declarativemaps/qdeclarativegeoroute_p.h5
-rw-r--r--src/location/maps/qgeomaneuver.cpp280
-rw-r--r--src/location/maps/qgeomaneuver.h4
-rw-r--r--src/location/maps/qgeomaneuver_p.h84
-rw-r--r--src/location/maps/qgeoroute.cpp301
-rw-r--r--src/location/maps/qgeoroute.h4
-rw-r--r--src/location/maps/qgeoroute_p.h89
-rw-r--r--src/location/maps/qgeoroutesegment.cpp212
-rw-r--r--src/location/maps/qgeoroutesegment.h3
-rw-r--r--src/location/maps/qgeoroutesegment_p.h66
-rw-r--r--tests/auto/declarative_core/tst_routing.qml96
-rw-r--r--tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h29
13 files changed, 1018 insertions, 208 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeoroute.cpp b/src/location/declarativemaps/qdeclarativegeoroute.cpp
index 039b1297..5540263c 100644
--- a/src/location/declarativemaps/qdeclarativegeoroute.cpp
+++ b/src/location/declarativemaps/qdeclarativegeoroute.cpp
@@ -37,6 +37,7 @@
#include "qdeclarativegeoroute_p.h"
#include "locationvaluetypehelper_p.h"
#include <QtLocation/private/qgeomap_p.h>
+#include <QtLocation/private/qgeoroute_p.h>
#include <QtQml/QQmlEngine>
#include <QtQml/qqmlinfo.h>
@@ -77,29 +78,37 @@ QT_BEGIN_NAMESPACE
*/
QDeclarativeGeoRoute::QDeclarativeGeoRoute(QObject *parent)
- : QObject(parent)
+ : QObject(parent), segmentsDirty_(true)
{
- this->init();
}
QDeclarativeGeoRoute::QDeclarativeGeoRoute(const QGeoRoute &route, QObject *parent)
- : QObject(parent),
- route_(route)
+ : QObject(parent), route_(route), segmentsDirty_(true)
{
- this->init();
}
QDeclarativeGeoRoute::~QDeclarativeGeoRoute() {}
-void QDeclarativeGeoRoute::init()
+void QDeclarativeGeoRoute::initSegments(unsigned int lastIndex) // -1 turns it into unsigned int max
{
+ if (!segmentsDirty_)
+ return;
+
QGeoRouteSegment segment = route_.firstRouteSegment();
+ unsigned int idx = 0;
+ unsigned int initialListSize = static_cast<unsigned int>(segments_.size());
while (segment.isValid()) {
- QDeclarativeGeoRouteSegment *routeSegment = new QDeclarativeGeoRouteSegment(segment, this);
- QQmlEngine::setContextForObject(routeSegment, QQmlEngine::contextForObject(this));
- segments_.append(routeSegment);
+ if (idx >= initialListSize) {
+ QDeclarativeGeoRouteSegment *routeSegment = new QDeclarativeGeoRouteSegment(segment, this);
+ QQmlEngine::setContextForObject(routeSegment, QQmlEngine::contextForObject(this));
+ segments_.append(routeSegment);
+ }
+ ++idx;
segment = segment.nextRouteSegment();
+ if (idx > lastIndex && segment.isValid()) // Do not clean segmentsDirty_ if there are still segments to initialize
+ return;
}
+ segmentsDirty_ = false;
}
/*!
@@ -229,7 +238,9 @@ QQmlListProperty<QDeclarativeGeoRouteSegment> QDeclarativeGeoRoute::segments()
void QDeclarativeGeoRoute::segments_append(QQmlListProperty<QDeclarativeGeoRouteSegment> *prop,
QDeclarativeGeoRouteSegment *segment)
{
- static_cast<QDeclarativeGeoRoute *>(prop->object)->appendSegment(segment);
+ QDeclarativeGeoRoute *declRoute = static_cast<QDeclarativeGeoRoute *>(prop->object);
+ declRoute->initSegments();
+ declRoute->appendSegment(segment);
}
/*!
@@ -237,7 +248,8 @@ void QDeclarativeGeoRoute::segments_append(QQmlListProperty<QDeclarativeGeoRoute
*/
int QDeclarativeGeoRoute::segments_count(QQmlListProperty<QDeclarativeGeoRouteSegment> *prop)
{
- return static_cast<QDeclarativeGeoRoute *>(prop->object)->segments_.count();
+ QDeclarativeGeoRoute *declRoute = static_cast<QDeclarativeGeoRoute *>(prop->object);
+ return declRoute->segmentsCount();
}
/*!
@@ -245,7 +257,9 @@ int QDeclarativeGeoRoute::segments_count(QQmlListProperty<QDeclarativeGeoRouteSe
*/
QDeclarativeGeoRouteSegment *QDeclarativeGeoRoute::segments_at(QQmlListProperty<QDeclarativeGeoRouteSegment> *prop, int index)
{
- return static_cast<QDeclarativeGeoRoute *>(prop->object)->segments_.at(index);
+ QDeclarativeGeoRoute *declRoute = static_cast<QDeclarativeGeoRoute *>(prop->object);
+ declRoute->initSegments(index); // init only what's needed.
+ return declRoute->segments_.at(index);
}
/*!
@@ -272,4 +286,19 @@ void QDeclarativeGeoRoute::clearSegments()
segments_.clear();
}
+/*!
+ \qmlmethod int QtLocation::Route::segmentsCount()
+
+ Returns the number of segments in the route
+
+ \sa RouteSegment
+
+ \since 5.11
+*/
+
+int QDeclarativeGeoRoute::segmentsCount() const
+{
+ return qMax(route_.d_ptr->segmentsCount(), segments_.count());
+}
+
QT_END_NAMESPACE
diff --git a/src/location/declarativemaps/qdeclarativegeoroute_p.h b/src/location/declarativemaps/qdeclarativegeoroute_p.h
index e4501770..738d2089 100644
--- a/src/location/declarativemaps/qdeclarativegeoroute_p.h
+++ b/src/location/declarativemaps/qdeclarativegeoroute_p.h
@@ -84,6 +84,8 @@ public:
void appendSegment(QDeclarativeGeoRouteSegment *segment);
void clearSegments();
+ int segmentsCount() const;
+
Q_SIGNALS:
void pathChanged();
@@ -93,11 +95,12 @@ private:
static QDeclarativeGeoRouteSegment *segments_at(QQmlListProperty<QDeclarativeGeoRouteSegment> *prop, int index);
static void segments_clear(QQmlListProperty<QDeclarativeGeoRouteSegment> *prop);
- void init();
+ void initSegments(unsigned int lastIndex = -1);
QList<QGeoCoordinate> routePath();
QGeoRoute route_;
QList<QDeclarativeGeoRouteSegment *> segments_;
+ bool segmentsDirty_;
friend class QDeclarativeRouteMapItem;
};
diff --git a/src/location/maps/qgeomaneuver.cpp b/src/location/maps/qgeomaneuver.cpp
index f38cb293..78efb971 100644
--- a/src/location/maps/qgeomaneuver.cpp
+++ b/src/location/maps/qgeomaneuver.cpp
@@ -115,7 +115,7 @@ The instruction indicates that the direction of travel should bear to the left.
setWaypoint() is called.
*/
QGeoManeuver::QGeoManeuver()
- : d_ptr(new QGeoManeuverPrivate()) {}
+ : d_ptr(new QGeoManeuverPrivateDefault()) {}
/*!
Constructs a maneuver object from the contents of \a other.
@@ -165,7 +165,7 @@ bool QGeoManeuver::operator!= (const QGeoManeuver &other) const
*/
bool QGeoManeuver::isValid() const
{
- return d_ptr->valid;
+ return d_ptr->valid();
}
/*!
@@ -174,8 +174,8 @@ bool QGeoManeuver::isValid() const
*/
void QGeoManeuver::setPosition(const QGeoCoordinate &position)
{
- d_ptr->valid = true;
- d_ptr->position = position;
+ d_ptr->setValid(true);
+ d_ptr->setPosition(position);
}
/*!
@@ -183,7 +183,7 @@ void QGeoManeuver::setPosition(const QGeoCoordinate &position)
*/
QGeoCoordinate QGeoManeuver::position() const
{
- return d_ptr->position;
+ return d_ptr->position();
}
/*!
@@ -191,8 +191,8 @@ QGeoCoordinate QGeoManeuver::position() const
*/
void QGeoManeuver::setInstructionText(const QString &instructionText)
{
- d_ptr->valid = true;
- d_ptr->text = instructionText;
+ d_ptr->setValid(true);
+ d_ptr->setText(instructionText);
}
/*!
@@ -200,7 +200,7 @@ void QGeoManeuver::setInstructionText(const QString &instructionText)
*/
QString QGeoManeuver::instructionText() const
{
- return d_ptr->text;
+ return d_ptr->text();
}
/*!
@@ -209,8 +209,8 @@ QString QGeoManeuver::instructionText() const
*/
void QGeoManeuver::setDirection(QGeoManeuver::InstructionDirection direction)
{
- d_ptr->valid = true;
- d_ptr->direction = direction;
+ d_ptr->setValid(true);
+ d_ptr->setDirection(direction);
}
/*!
@@ -218,7 +218,7 @@ void QGeoManeuver::setDirection(QGeoManeuver::InstructionDirection direction)
*/
QGeoManeuver::InstructionDirection QGeoManeuver::direction() const
{
- return d_ptr->direction;
+ return d_ptr->direction();
}
/*!
@@ -228,8 +228,8 @@ QGeoManeuver::InstructionDirection QGeoManeuver::direction() const
*/
void QGeoManeuver::setTimeToNextInstruction(int secs)
{
- d_ptr->valid = true;
- d_ptr->timeToNextInstruction = secs;
+ d_ptr->setValid(true);
+ d_ptr->setTimeToNextInstruction(secs);
}
/*!
@@ -239,7 +239,7 @@ void QGeoManeuver::setTimeToNextInstruction(int secs)
*/
int QGeoManeuver::timeToNextInstruction() const
{
- return d_ptr->timeToNextInstruction;
+ return d_ptr->timeToNextInstruction();
}
/*!
@@ -249,8 +249,8 @@ int QGeoManeuver::timeToNextInstruction() const
*/
void QGeoManeuver::setDistanceToNextInstruction(qreal distance)
{
- d_ptr->valid = true;
- d_ptr->distanceToNextInstruction = distance;
+ d_ptr->setValid(true);
+ d_ptr->setDistanceToNextInstruction(distance);
}
/*!
@@ -260,7 +260,7 @@ void QGeoManeuver::setDistanceToNextInstruction(qreal distance)
*/
qreal QGeoManeuver::distanceToNextInstruction() const
{
- return d_ptr->distanceToNextInstruction;
+ return d_ptr->distanceToNextInstruction();
}
/*!
@@ -268,8 +268,8 @@ qreal QGeoManeuver::distanceToNextInstruction() const
*/
void QGeoManeuver::setWaypoint(const QGeoCoordinate &coordinate)
{
- d_ptr->valid = true;
- d_ptr->waypoint = coordinate;
+ d_ptr->setValid(true);
+ d_ptr->setWaypoint(coordinate);
}
/*!
@@ -280,39 +280,231 @@ void QGeoManeuver::setWaypoint(const QGeoCoordinate &coordinate)
*/
QGeoCoordinate QGeoManeuver::waypoint() const
{
- return d_ptr->waypoint;
+ return d_ptr->waypoint();
}
+QGeoManeuver::QGeoManeuver(const QSharedDataPointer<QGeoManeuverPrivate> &dd)
+ : d_ptr(dd) {}
+
+
/*******************************************************************************
*******************************************************************************/
QGeoManeuverPrivate::QGeoManeuverPrivate()
- : valid(false),
- direction(QGeoManeuver::NoDirection),
- timeToNextInstruction(0),
- distanceToNextInstruction(0.0) {}
+{
+
+}
QGeoManeuverPrivate::QGeoManeuverPrivate(const QGeoManeuverPrivate &other)
- : QSharedData(other),
- valid(other.valid),
- position(other.position),
- text(other.text),
- direction(other.direction),
- timeToNextInstruction(other.timeToNextInstruction),
- distanceToNextInstruction(other.distanceToNextInstruction),
- waypoint(other.waypoint) {}
-
-QGeoManeuverPrivate::~QGeoManeuverPrivate() {}
-
-bool QGeoManeuverPrivate::operator ==(const QGeoManeuverPrivate &other) const
-{
- return ((valid == other.valid)
- && (position == other.position)
- && (text == other.text)
- && (direction == other.direction)
- && (timeToNextInstruction == other.timeToNextInstruction)
- && (distanceToNextInstruction == other.distanceToNextInstruction)
- && (waypoint == other.waypoint));
+ : QSharedData(other)
+{
+
+}
+
+QGeoManeuverPrivate::~QGeoManeuverPrivate()
+{
+
+}
+
+bool QGeoManeuverPrivate::operator==(const QGeoManeuverPrivate &other) const
+{
+ return ((valid() == other.valid())
+ && (position() == other.position())
+ && (text() == other.text())
+ && (direction() == other.direction())
+ && (timeToNextInstruction() == other.timeToNextInstruction())
+ && (distanceToNextInstruction() == other.distanceToNextInstruction())
+ && (waypoint() == other.waypoint()));
+}
+
+bool QGeoManeuverPrivate::valid() const
+{
+ return false;
+}
+
+void QGeoManeuverPrivate::setValid(bool valid)
+{
+ Q_UNUSED(valid)
+}
+
+QString QGeoManeuverPrivate::id() const
+{
+ return QString();
+}
+
+void QGeoManeuverPrivate::setId(const QString id)
+{
+ Q_UNUSED(id)
+}
+
+QGeoCoordinate QGeoManeuverPrivate::position() const
+{
+ return QGeoCoordinate();
+}
+
+void QGeoManeuverPrivate::setPosition(const QGeoCoordinate &position)
+{
+ Q_UNUSED(position)
+}
+
+QString QGeoManeuverPrivate::text() const
+{
+ return QString();
+}
+
+void QGeoManeuverPrivate::setText(const QString &text)
+{
+ Q_UNUSED(text)
+}
+
+QGeoManeuver::InstructionDirection QGeoManeuverPrivate::direction() const
+{
+ return QGeoManeuver::NoDirection;
+}
+
+void QGeoManeuverPrivate::setDirection(QGeoManeuver::InstructionDirection direction)
+{
+ Q_UNUSED(direction)
+}
+
+int QGeoManeuverPrivate::timeToNextInstruction() const
+{
+ return 0;
+}
+
+void QGeoManeuverPrivate::setTimeToNextInstruction(int timeToNextInstruction)
+{
+ Q_UNUSED(timeToNextInstruction)
+}
+
+qreal QGeoManeuverPrivate::distanceToNextInstruction() const
+{
+ return 0;
+}
+
+void QGeoManeuverPrivate::setDistanceToNextInstruction(qreal distanceToNextInstruction)
+{
+ Q_UNUSED(distanceToNextInstruction)
+}
+
+QGeoCoordinate QGeoManeuverPrivate::waypoint() const
+{
+ return QGeoCoordinate();
+}
+
+void QGeoManeuverPrivate::setWaypoint(const QGeoCoordinate &waypoint)
+{
+ Q_UNUSED(waypoint)
+}
+
+
+
+/*******************************************************************************
+*******************************************************************************/
+
+QGeoManeuverPrivateDefault::QGeoManeuverPrivateDefault()
+ : m_valid(false),
+ m_direction(QGeoManeuver::NoDirection),
+ m_timeToNextInstruction(0),
+ m_distanceToNextInstruction(0.0) {}
+
+QGeoManeuverPrivateDefault::QGeoManeuverPrivateDefault(const QGeoManeuverPrivateDefault &other)
+ : QGeoManeuverPrivate(other),
+ m_valid(other.m_valid),
+ m_position(other.m_position),
+ m_text(other.m_text),
+ m_direction(other.m_direction),
+ m_timeToNextInstruction(other.m_timeToNextInstruction),
+ m_distanceToNextInstruction(other.m_distanceToNextInstruction),
+ m_waypoint(other.m_waypoint) {}
+
+QGeoManeuverPrivateDefault::~QGeoManeuverPrivateDefault() {}
+
+
+
+bool QGeoManeuverPrivateDefault::operator ==(const QGeoManeuverPrivateDefault &other) const
+{
+ return QGeoManeuverPrivateDefault::operator ==(other);
+}
+
+bool QGeoManeuverPrivateDefault::valid() const
+{
+ return m_valid;
+}
+
+void QGeoManeuverPrivateDefault::setValid(bool valid)
+{
+ m_valid = valid;
+}
+
+QString QGeoManeuverPrivateDefault::id() const
+{
+ return m_id;
+}
+
+void QGeoManeuverPrivateDefault::setId(const QString id)
+{
+ m_id = id;
+}
+
+QGeoCoordinate QGeoManeuverPrivateDefault::position() const
+{
+ return m_position;
+}
+
+void QGeoManeuverPrivateDefault::setPosition(const QGeoCoordinate &position)
+{
+ m_position = position;
+}
+
+QString QGeoManeuverPrivateDefault::text() const
+{
+ return m_text;
+}
+
+void QGeoManeuverPrivateDefault::setText(const QString &text)
+{
+ m_text = text;
+}
+
+QGeoManeuver::InstructionDirection QGeoManeuverPrivateDefault::direction() const
+{
+ return m_direction;
+}
+
+void QGeoManeuverPrivateDefault::setDirection(QGeoManeuver::InstructionDirection direction)
+{
+ m_direction = direction;
+}
+
+int QGeoManeuverPrivateDefault::timeToNextInstruction() const
+{
+ return m_timeToNextInstruction;
+}
+
+void QGeoManeuverPrivateDefault::setTimeToNextInstruction(int timeToNextInstruction)
+{
+ m_timeToNextInstruction = timeToNextInstruction;
+}
+
+qreal QGeoManeuverPrivateDefault::distanceToNextInstruction() const
+{
+ return m_distanceToNextInstruction;
+}
+
+void QGeoManeuverPrivateDefault::setDistanceToNextInstruction(qreal distanceToNextInstruction)
+{
+ m_distanceToNextInstruction = distanceToNextInstruction;
+}
+
+QGeoCoordinate QGeoManeuverPrivateDefault::waypoint() const
+{
+ return m_waypoint;
+}
+
+void QGeoManeuverPrivateDefault::setWaypoint(const QGeoCoordinate &waypoint)
+{
+ m_waypoint = waypoint;
}
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeomaneuver.h b/src/location/maps/qgeomaneuver.h
index 9710f8fc..1e4bff24 100644
--- a/src/location/maps/qgeomaneuver.h
+++ b/src/location/maps/qgeomaneuver.h
@@ -95,7 +95,9 @@ public:
void setWaypoint(const QGeoCoordinate &coordinate);
QGeoCoordinate waypoint() const;
-private:
+protected:
+ QGeoManeuver(const QSharedDataPointer<QGeoManeuverPrivate> &dd);
+
QSharedDataPointer<QGeoManeuverPrivate> d_ptr;
};
diff --git a/src/location/maps/qgeomaneuver_p.h b/src/location/maps/qgeomaneuver_p.h
index c048f132..484354ba 100644
--- a/src/location/maps/qgeomaneuver_p.h
+++ b/src/location/maps/qgeomaneuver_p.h
@@ -48,31 +48,91 @@
// We mean it.
//
-#include "qgeomaneuver.h"
-#include "qgeocoordinate.h"
+#include <QtLocation/private/qlocationglobal_p.h>
+#include <QtLocation/qgeomaneuver.h>
+#include <QtPositioning/qgeocoordinate.h>
#include <QSharedData>
#include <QString>
QT_BEGIN_NAMESPACE
-class QGeoManeuverPrivate : public QSharedData
+class Q_LOCATION_PRIVATE_EXPORT QGeoManeuverPrivate : public QSharedData
{
public:
QGeoManeuverPrivate();
QGeoManeuverPrivate(const QGeoManeuverPrivate &other);
- ~QGeoManeuverPrivate();
+ virtual ~QGeoManeuverPrivate();
bool operator== (const QGeoManeuverPrivate &other) const;
- bool valid;
- QString id;
- QGeoCoordinate position;
- QString text;
- QGeoManeuver::InstructionDirection direction;
- int timeToNextInstruction;
- qreal distanceToNextInstruction;
- QGeoCoordinate waypoint;
+ virtual bool valid() const;
+ virtual void setValid(bool valid);
+
+ virtual QString id() const;
+ virtual void setId(const QString id);
+
+ virtual QGeoCoordinate position() const;
+ virtual void setPosition(const QGeoCoordinate &position);
+
+ virtual QString text() const;
+ virtual void setText(const QString &text);
+
+ virtual QGeoManeuver::InstructionDirection direction() const;
+ virtual void setDirection(QGeoManeuver::InstructionDirection direction);
+
+ virtual int timeToNextInstruction() const;
+ virtual void setTimeToNextInstruction(int timeToNextInstruction);
+
+ virtual qreal distanceToNextInstruction() const;
+ virtual void setDistanceToNextInstruction(qreal distanceToNextInstruction);
+
+ virtual QGeoCoordinate waypoint() const;
+ virtual void setWaypoint(const QGeoCoordinate &waypoint);
+
+};
+
+class Q_LOCATION_PRIVATE_EXPORT QGeoManeuverPrivateDefault : public QGeoManeuverPrivate
+{
+public:
+ QGeoManeuverPrivateDefault();
+ QGeoManeuverPrivateDefault(const QGeoManeuverPrivateDefault &other);
+ ~QGeoManeuverPrivateDefault();
+
+ bool operator== (const QGeoManeuverPrivateDefault &other) const;
+
+ virtual bool valid() const override;
+ virtual void setValid(bool valid) override;
+
+ virtual QString id() const override;
+ virtual void setId(const QString id) override;
+
+ virtual QGeoCoordinate position() const override;
+ virtual void setPosition(const QGeoCoordinate &position) override;
+
+ virtual QString text() const override;
+ virtual void setText(const QString &text) override;
+
+ virtual QGeoManeuver::InstructionDirection direction() const override;
+ virtual void setDirection(QGeoManeuver::InstructionDirection direction) override;
+
+ virtual int timeToNextInstruction() const override;
+ virtual void setTimeToNextInstruction(int timeToNextInstruction) override;
+
+ virtual qreal distanceToNextInstruction() const override;
+ virtual void setDistanceToNextInstruction(qreal distanceToNextInstruction) override;
+
+ virtual QGeoCoordinate waypoint() const override;
+ virtual void setWaypoint(const QGeoCoordinate &waypoint) override;
+
+ bool m_valid;
+ QString m_id;
+ QGeoCoordinate m_position;
+ QString m_text;
+ QGeoManeuver::InstructionDirection m_direction;
+ int m_timeToNextInstruction;
+ qreal m_distanceToNextInstruction;
+ QGeoCoordinate m_waypoint;
};
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeoroute.cpp b/src/location/maps/qgeoroute.cpp
index facf1949..95603218 100644
--- a/src/location/maps/qgeoroute.cpp
+++ b/src/location/maps/qgeoroute.cpp
@@ -71,7 +71,14 @@ QT_BEGIN_NAMESPACE
Constructs a route object.
*/
QGeoRoute::QGeoRoute()
- : d_ptr(new QGeoRoutePrivate()) {}
+ : d_ptr(new QGeoRoutePrivateDefault()) {}
+
+/*!
+ Constructs a route object using dd as private implementation.
+*/
+QGeoRoute::QGeoRoute(const QExplicitlySharedDataPointer<QGeoRoutePrivate> &dd): d_ptr(dd)
+{
+}
/*!
Constructs a route object from the contents of \a other.
@@ -104,7 +111,8 @@ QGeoRoute &QGeoRoute::operator= (const QGeoRoute & other)
*/
bool QGeoRoute::operator ==(const QGeoRoute &other) const
{
- return (*d_ptr.constData() == *other.d_ptr.constData());
+ return ( (d_ptr.constData() == other.d_ptr.constData())
+ || (*d_ptr) == (*other.d_ptr));
}
/*!
@@ -112,7 +120,7 @@ bool QGeoRoute::operator ==(const QGeoRoute &other) const
*/
bool QGeoRoute::operator !=(const QGeoRoute &other) const
{
- return !(*d_ptr.constData() == *other.d_ptr.constData());
+ return !(operator==(other));
}
/*!
@@ -124,7 +132,7 @@ bool QGeoRoute::operator !=(const QGeoRoute &other) const
*/
void QGeoRoute::setRouteId(const QString &id)
{
- d_ptr->id = id;
+ d_ptr->setId(id);
}
/*!
@@ -136,7 +144,7 @@ void QGeoRoute::setRouteId(const QString &id)
*/
QString QGeoRoute::routeId() const
{
- return d_ptr->id;
+ return d_ptr->id();
}
/*!
@@ -145,7 +153,7 @@ QString QGeoRoute::routeId() const
*/
void QGeoRoute::setRequest(const QGeoRouteRequest &request)
{
- d_ptr->request = request;
+ d_ptr->setRequest(request);
}
/*!
@@ -154,7 +162,7 @@ void QGeoRoute::setRequest(const QGeoRouteRequest &request)
*/
QGeoRouteRequest QGeoRoute::request() const
{
- return d_ptr->request;
+ return d_ptr->request();
}
/*!
@@ -162,7 +170,7 @@ QGeoRouteRequest QGeoRoute::request() const
*/
void QGeoRoute::setBounds(const QGeoRectangle &bounds)
{
- d_ptr->bounds = bounds;
+ d_ptr->setBounds(bounds);
}
/*!
@@ -170,7 +178,7 @@ void QGeoRoute::setBounds(const QGeoRectangle &bounds)
*/
QGeoRectangle QGeoRoute::bounds() const
{
- return d_ptr->bounds;
+ return d_ptr->bounds();
}
/*!
@@ -178,7 +186,7 @@ QGeoRectangle QGeoRoute::bounds() const
*/
void QGeoRoute::setFirstRouteSegment(const QGeoRouteSegment &routeSegment)
{
- d_ptr->firstSegment = routeSegment;
+ d_ptr->setFirstSegment(routeSegment);
}
/*!
@@ -192,7 +200,7 @@ void QGeoRoute::setFirstRouteSegment(const QGeoRouteSegment &routeSegment)
*/
QGeoRouteSegment QGeoRoute::firstRouteSegment() const
{
- return d_ptr->firstSegment;
+ return d_ptr->firstSegment();
}
/*!
@@ -201,7 +209,7 @@ QGeoRouteSegment QGeoRoute::firstRouteSegment() const
*/
void QGeoRoute::setTravelTime(int secs)
{
- d_ptr->travelTime = secs;
+ d_ptr->setTravelTime(secs);
}
/*!
@@ -210,7 +218,7 @@ void QGeoRoute::setTravelTime(int secs)
*/
int QGeoRoute::travelTime() const
{
- return d_ptr->travelTime;
+ return d_ptr->travelTime();
}
/*!
@@ -218,7 +226,7 @@ int QGeoRoute::travelTime() const
*/
void QGeoRoute::setDistance(qreal distance)
{
- d_ptr->distance = distance;
+ d_ptr->setDistance(distance);
}
/*!
@@ -226,7 +234,7 @@ void QGeoRoute::setDistance(qreal distance)
*/
qreal QGeoRoute::distance() const
{
- return d_ptr->distance;
+ return d_ptr->distance();
}
/*!
@@ -236,7 +244,7 @@ qreal QGeoRoute::distance() const
*/
void QGeoRoute::setTravelMode(QGeoRouteRequest::TravelMode mode)
{
- d_ptr->travelMode = mode;
+ d_ptr->setTravelMode(mode);
}
/*!
@@ -246,7 +254,7 @@ void QGeoRoute::setTravelMode(QGeoRouteRequest::TravelMode mode)
*/
QGeoRouteRequest::TravelMode QGeoRoute::travelMode() const
{
- return d_ptr->travelMode;
+ return d_ptr->travelMode();
}
/*!
@@ -257,7 +265,7 @@ QGeoRouteRequest::TravelMode QGeoRoute::travelMode() const
*/
void QGeoRoute::setPath(const QList<QGeoCoordinate> &path)
{
- d_ptr->path = path;
+ d_ptr->setPath(path);
}
/*!
@@ -268,34 +276,37 @@ void QGeoRoute::setPath(const QList<QGeoCoordinate> &path)
*/
QList<QGeoCoordinate> QGeoRoute::path() const
{
- return d_ptr->path;
+ return d_ptr->path();
}
/*******************************************************************************
*******************************************************************************/
QGeoRoutePrivate::QGeoRoutePrivate()
- : travelTime(0),
- distance(0.0),
- travelMode(QGeoRouteRequest::CarTravel) {}
-
-QGeoRoutePrivate::QGeoRoutePrivate(const QGeoRoutePrivate &other)
- : QSharedData(other),
- id(other.id),
- request(other.request),
- bounds(other.bounds),
- travelTime(other.travelTime),
- distance(other.distance),
- travelMode(other.travelMode),
- path(other.path),
- firstSegment(other.firstSegment) {}
+{
+
+}
+
+QGeoRoutePrivate::QGeoRoutePrivate(const QGeoRoutePrivate &other) : QSharedData(other)
+{
+
+}
QGeoRoutePrivate::~QGeoRoutePrivate() {}
bool QGeoRoutePrivate::operator ==(const QGeoRoutePrivate &other) const
{
- QGeoRouteSegment s1 = firstSegment;
- QGeoRouteSegment s2 = other.firstSegment;
+ return equals(other);
+}
+
+bool QGeoRoutePrivate::equals(const QGeoRoutePrivate &other) const
+{
+ if (!other.engineName().isEmpty()) // only way to know if other comes from an engine without dynamic_cast
+ return false;
+
+ // here both routes are of type QGeoRoutePrivateDefault
+ QGeoRouteSegment s1 = firstSegment();
+ QGeoRouteSegment s2 = other.firstSegment();
while (true) {
if (s1.isValid() != s2.isValid())
@@ -308,13 +319,219 @@ bool QGeoRoutePrivate::operator ==(const QGeoRoutePrivate &other) const
s2 = s2.nextRouteSegment();
}
- return ((id == other.id)
- && (request == other.request)
- && (bounds == other.bounds)
- && (travelTime == other.travelTime)
- && (distance == other.distance)
- && (travelMode == other.travelMode)
- && (path == other.path));
+ return ((id() == other.id())
+ && (request() == other.request())
+ && (bounds() == other.bounds())
+ && (travelTime() == other.travelTime())
+ && (distance() == other.distance())
+ && (travelMode() == other.travelMode())
+ && (path() == other.path()));
+}
+
+void QGeoRoutePrivate::setId(const QString &id)
+{
+ Q_UNUSED(id)
+}
+
+QString QGeoRoutePrivate::id() const
+{
+ return QString();
+}
+
+void QGeoRoutePrivate::setRequest(const QGeoRouteRequest &request)
+{
+ Q_UNUSED(request)
+}
+
+QGeoRouteRequest QGeoRoutePrivate::request() const
+{
+ return QGeoRouteRequest();
+}
+
+void QGeoRoutePrivate::setBounds(const QGeoRectangle &bounds)
+{
+ Q_UNUSED(bounds)
+}
+
+QGeoRectangle QGeoRoutePrivate::bounds() const
+{
+ return QGeoRectangle();
+}
+
+void QGeoRoutePrivate::setTravelTime(int travelTime)
+{
+ Q_UNUSED(travelTime)
+}
+
+int QGeoRoutePrivate::travelTime() const
+{
+ return 0;
+}
+
+void QGeoRoutePrivate::setDistance(qreal distance)
+{
+ Q_UNUSED(distance)
+}
+
+qreal QGeoRoutePrivate::distance() const
+{
+ return 0;
+}
+
+void QGeoRoutePrivate::setTravelMode(QGeoRouteRequest::TravelMode mode)
+{
+ Q_UNUSED(mode)
+}
+
+QGeoRouteRequest::TravelMode QGeoRoutePrivate::travelMode() const
+{
+ return QGeoRouteRequest::CarTravel;
+}
+
+void QGeoRoutePrivate::setPath(const QList<QGeoCoordinate> &path)
+{
+ Q_UNUSED(path)
+}
+
+QList<QGeoCoordinate> QGeoRoutePrivate::path() const
+{
+ return QList<QGeoCoordinate>();
+}
+
+void QGeoRoutePrivate::setFirstSegment(const QGeoRouteSegment &firstSegment)
+{
+ Q_UNUSED(firstSegment)
+}
+
+QGeoRouteSegment QGeoRoutePrivate::firstSegment() const
+{
+ return QGeoRouteSegment();
+}
+
+/*******************************************************************************
+*******************************************************************************/
+
+
+QGeoRoutePrivateDefault::QGeoRoutePrivateDefault()
+ : m_travelTime(0),
+ m_distance(0.0),
+ m_travelMode(QGeoRouteRequest::CarTravel),
+ m_numSegments(-1) {}
+
+QGeoRoutePrivateDefault::QGeoRoutePrivateDefault(const QGeoRoutePrivateDefault &other)
+ : QGeoRoutePrivate(other),
+ m_id(other.m_id),
+ m_request(other.m_request),
+ m_bounds(other.m_bounds),
+ m_routeSegments(other.m_routeSegments),
+ m_travelTime(other.m_travelTime),
+ m_distance(other.m_distance),
+ m_travelMode(other.m_travelMode),
+ m_path(other.m_path),
+ m_firstSegment(other.m_firstSegment),
+ m_numSegments(other.m_numSegments){}
+
+
+QGeoRoutePrivateDefault::~QGeoRoutePrivateDefault() {}
+
+void QGeoRoutePrivateDefault::setId(const QString &id)
+{
+ m_id = id;
+}
+
+QString QGeoRoutePrivateDefault::id() const
+{
+ return m_id;
+}
+
+void QGeoRoutePrivateDefault::setRequest(const QGeoRouteRequest &request)
+{
+ m_request = request;
+}
+
+QGeoRouteRequest QGeoRoutePrivateDefault::request() const
+{
+ return m_request;
+}
+
+void QGeoRoutePrivateDefault::setBounds(const QGeoRectangle &bounds)
+{
+ m_bounds = bounds;
+}
+
+QGeoRectangle QGeoRoutePrivateDefault::bounds() const
+{
+ return m_bounds;
+}
+
+void QGeoRoutePrivateDefault::setTravelTime(int travelTime)
+{
+ m_travelTime = travelTime;
+}
+
+int QGeoRoutePrivateDefault::travelTime() const
+{
+ return m_travelTime;
+}
+
+void QGeoRoutePrivateDefault::setDistance(qreal distance)
+{
+ m_distance = distance;
+}
+
+qreal QGeoRoutePrivateDefault::distance() const
+{
+ return m_distance;
+}
+
+void QGeoRoutePrivateDefault::setTravelMode(QGeoRouteRequest::TravelMode mode)
+{
+ m_travelMode = mode;
+}
+
+QGeoRouteRequest::TravelMode QGeoRoutePrivateDefault::travelMode() const
+{
+ return m_travelMode;
+}
+
+void QGeoRoutePrivateDefault::setPath(const QList<QGeoCoordinate> &path)
+{
+ m_path = path;
+}
+
+QList<QGeoCoordinate> QGeoRoutePrivateDefault::path() const
+{
+ return m_path;
+}
+
+void QGeoRoutePrivateDefault::setFirstSegment(const QGeoRouteSegment &firstSegment)
+{
+ m_firstSegment = firstSegment;
+}
+
+QGeoRouteSegment QGeoRoutePrivateDefault::firstSegment() const
+{
+ return m_firstSegment;
+}
+
+QString QGeoRoutePrivateDefault::engineName() const
+{
+ return QString();
+}
+
+int QGeoRoutePrivateDefault::segmentsCount() const
+{
+ if (m_numSegments >= 0)
+ return m_numSegments;
+
+ int count = 0;
+ QGeoRouteSegment segment = m_firstSegment;
+ while (segment.isValid()) {
+ ++count;
+ segment = segment.nextRouteSegment();
+ }
+ m_numSegments = count;
+ return count;
}
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeoroute.h b/src/location/maps/qgeoroute.h
index 68e73c09..7dee719f 100644
--- a/src/location/maps/qgeoroute.h
+++ b/src/location/maps/qgeoroute.h
@@ -87,8 +87,10 @@ public:
void setPath(const QList<QGeoCoordinate> &path);
QList<QGeoCoordinate> path() const;
-private:
+protected:
+ QGeoRoute(const QExplicitlySharedDataPointer<QGeoRoutePrivate> &dd);
QExplicitlySharedDataPointer<QGeoRoutePrivate> d_ptr;
+ friend class QDeclarativeGeoRoute;
};
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeoroute_p.h b/src/location/maps/qgeoroute_p.h
index 66ef3c68..1a8f9b0c 100644
--- a/src/location/maps/qgeoroute_p.h
+++ b/src/location/maps/qgeoroute_p.h
@@ -48,6 +48,7 @@
// We mean it.
//
+#include <QtLocation/private/qlocationglobal_p.h>
#include "qgeoroute.h"
#include "qgeorouterequest.h"
#include "qgeorectangle.h"
@@ -59,29 +60,95 @@ QT_BEGIN_NAMESPACE
class QGeoCoordinate;
-class QGeoRoutePrivate : public QSharedData
+class Q_LOCATION_PRIVATE_EXPORT QGeoRoutePrivate : public QSharedData
{
public:
QGeoRoutePrivate();
QGeoRoutePrivate(const QGeoRoutePrivate &other);
- ~QGeoRoutePrivate();
+ virtual ~QGeoRoutePrivate();
bool operator == (const QGeoRoutePrivate &other) const;
- QString id;
- QGeoRouteRequest request;
+ virtual void setId(const QString &id);
+ virtual QString id() const;
- QGeoRectangle bounds;
-// QList<QGeoRouteSegment> routeSegments;
+ virtual void setRequest(const QGeoRouteRequest &request);
+ virtual QGeoRouteRequest request() const;
- int travelTime;
- qreal distance;
+ virtual void setBounds(const QGeoRectangle &bounds);
+ virtual QGeoRectangle bounds() const;
- QGeoRouteRequest::TravelMode travelMode;
+ virtual void setTravelTime(int travelTime);
+ virtual int travelTime() const;
- QList<QGeoCoordinate> path;
+ virtual void setDistance(qreal distance);
+ virtual qreal distance() const;
- QGeoRouteSegment firstSegment;
+ virtual void setTravelMode(QGeoRouteRequest::TravelMode mode);
+ virtual QGeoRouteRequest::TravelMode travelMode() const;
+
+ virtual void setPath(const QList<QGeoCoordinate> &path);
+ virtual QList<QGeoCoordinate> path() const;
+
+ virtual void setFirstSegment(const QGeoRouteSegment &firstSegment);
+ virtual QGeoRouteSegment firstSegment() const;
+
+ virtual bool equals(const QGeoRoutePrivate &other) const;
+
+ virtual QString engineName() const = 0;
+ virtual int segmentsCount() const = 0;
+};
+
+class Q_LOCATION_PRIVATE_EXPORT QGeoRoutePrivateDefault : public QGeoRoutePrivate
+{
+public:
+ QGeoRoutePrivateDefault();
+ QGeoRoutePrivateDefault(const QGeoRoutePrivateDefault &other);
+ ~QGeoRoutePrivateDefault();
+
+ virtual void setId(const QString &id) override;
+ virtual QString id() const override;
+
+ virtual void setRequest(const QGeoRouteRequest &request) override;
+ virtual QGeoRouteRequest request() const override;
+
+ virtual void setBounds(const QGeoRectangle &bounds) override;
+ virtual QGeoRectangle bounds() const override;
+
+ virtual void setTravelTime(int travelTime) override;
+ virtual int travelTime() const override;
+
+ virtual void setDistance(qreal distance) override;
+ virtual qreal distance() const override;
+
+ virtual void setTravelMode(QGeoRouteRequest::TravelMode mode) override;
+ virtual QGeoRouteRequest::TravelMode travelMode() const override;
+
+ virtual void setPath(const QList<QGeoCoordinate> &path) override;
+ virtual QList<QGeoCoordinate> path() const override;
+
+ virtual void setFirstSegment(const QGeoRouteSegment &firstSegment) override;
+ virtual QGeoRouteSegment firstSegment() const override;
+
+ virtual QString engineName() const override;
+ virtual int segmentsCount() const override;
+
+
+ QString m_id;
+ QGeoRouteRequest m_request;
+
+ QGeoRectangle m_bounds;
+ mutable QList<QGeoRouteSegment> m_routeSegments;
+
+ int m_travelTime;
+ qreal m_distance;
+
+ QGeoRouteRequest::TravelMode m_travelMode;
+
+ QList<QGeoCoordinate> m_path;
+
+ QGeoRouteSegment m_firstSegment;
+ mutable int m_numSegments;
};
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeoroutesegment.cpp b/src/location/maps/qgeoroutesegment.cpp
index 45c2cc69..d9de9870 100644
--- a/src/location/maps/qgeoroutesegment.cpp
+++ b/src/location/maps/qgeoroutesegment.cpp
@@ -67,7 +67,7 @@ QT_BEGIN_NAMESPACE
setTravelTime(), setDistance(), setPath() or setManeuver() is called.
*/
QGeoRouteSegment::QGeoRouteSegment()
- : d_ptr(new QGeoRouteSegmentPrivate()) {}
+ : d_ptr(new QGeoRouteSegmentPrivateDefault()) {}
/*!
Constructs a route segment object from the contents of \a other.
@@ -78,8 +78,8 @@ QGeoRouteSegment::QGeoRouteSegment(const QGeoRouteSegment &other)
/*!
\internal
*/
-QGeoRouteSegment::QGeoRouteSegment(QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> &d_ptr)
- : d_ptr(d_ptr) {}
+QGeoRouteSegment::QGeoRouteSegment(const QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> &dd)
+ : d_ptr(dd) {}
/*!
Destroys this route segment object.
@@ -129,7 +129,7 @@ bool QGeoRouteSegment::operator !=(const QGeoRouteSegment &other) const
*/
bool QGeoRouteSegment::isValid() const
{
- return d_ptr->valid;
+ return d_ptr->valid();
}
/*!
@@ -137,8 +137,8 @@ bool QGeoRouteSegment::isValid() const
*/
void QGeoRouteSegment::setNextRouteSegment(const QGeoRouteSegment &routeSegment)
{
- d_ptr->valid = true;
- d_ptr->nextSegment = routeSegment.d_ptr;
+ d_ptr->setValid(true);
+ d_ptr->setNextRouteSegment(routeSegment.d_ptr);
}
/*!
@@ -149,12 +149,10 @@ void QGeoRouteSegment::setNextRouteSegment(const QGeoRouteSegment &routeSegment)
*/
QGeoRouteSegment QGeoRouteSegment::nextRouteSegment() const
{
- if (d_ptr->valid && d_ptr->nextSegment)
- return QGeoRouteSegment(d_ptr->nextSegment);
+ if (d_ptr->valid() && d_ptr->m_nextSegment)
+ return QGeoRouteSegment(d_ptr->m_nextSegment);
- QGeoRouteSegment segment;
- segment.d_ptr->valid = false;
- return segment;
+ return QGeoRouteSegment();
}
/*!
@@ -163,8 +161,8 @@ QGeoRouteSegment QGeoRouteSegment::nextRouteSegment() const
*/
void QGeoRouteSegment::setTravelTime(int secs)
{
- d_ptr->valid = true;
- d_ptr->travelTime = secs;
+ d_ptr->setValid(true);
+ d_ptr->setTravelTime(secs);
}
/*!
@@ -173,7 +171,7 @@ void QGeoRouteSegment::setTravelTime(int secs)
*/
int QGeoRouteSegment::travelTime() const
{
- return d_ptr->travelTime;
+ return d_ptr->travelTime();
}
/*!
@@ -181,8 +179,8 @@ int QGeoRouteSegment::travelTime() const
*/
void QGeoRouteSegment::setDistance(qreal distance)
{
- d_ptr->valid = true;
- d_ptr->distance = distance;
+ d_ptr->setValid(true);
+ d_ptr->setDistance(distance);
}
/*!
@@ -190,7 +188,7 @@ void QGeoRouteSegment::setDistance(qreal distance)
*/
qreal QGeoRouteSegment::distance() const
{
- return d_ptr->distance;
+ return d_ptr->distance();
}
/*!
@@ -201,8 +199,8 @@ qreal QGeoRouteSegment::distance() const
*/
void QGeoRouteSegment::setPath(const QList<QGeoCoordinate> &path)
{
- d_ptr->valid = true;
- d_ptr->path = path;
+ d_ptr->setValid(true);
+ d_ptr->setPath(path);
}
/*!
@@ -214,7 +212,7 @@ void QGeoRouteSegment::setPath(const QList<QGeoCoordinate> &path)
QList<QGeoCoordinate> QGeoRouteSegment::path() const
{
- return d_ptr->path;
+ return d_ptr->path();
}
/*!
@@ -222,8 +220,8 @@ QList<QGeoCoordinate> QGeoRouteSegment::path() const
*/
void QGeoRouteSegment::setManeuver(const QGeoManeuver &maneuver)
{
- d_ptr->valid = true;
- d_ptr->maneuver = maneuver;
+ d_ptr->setValid(true);
+ d_ptr->setManeuver(maneuver);
}
/*!
@@ -234,42 +232,174 @@ void QGeoRouteSegment::setManeuver(const QGeoManeuver &maneuver)
*/
QGeoManeuver QGeoRouteSegment::maneuver() const
{
- return d_ptr->maneuver;
+ return d_ptr->maneuver();
}
/*******************************************************************************
*******************************************************************************/
-QGeoRouteSegmentPrivate::QGeoRouteSegmentPrivate()
- : valid(false),
- travelTime(0),
- distance(0.0) {}
+QGeoRouteSegmentPrivate::QGeoRouteSegmentPrivate() {}
QGeoRouteSegmentPrivate::QGeoRouteSegmentPrivate(const QGeoRouteSegmentPrivate &other)
- : QSharedData(other),
- valid(other.valid),
- travelTime(other.travelTime),
- distance(other.distance),
- path(other.path),
- maneuver(other.maneuver),
- nextSegment(other.nextSegment) {}
+ : QSharedData(other), m_nextSegment(other.m_nextSegment) {}
QGeoRouteSegmentPrivate::~QGeoRouteSegmentPrivate()
{
- nextSegment.reset();
+ m_nextSegment.reset();
}
bool QGeoRouteSegmentPrivate::operator ==(const QGeoRouteSegmentPrivate &other) const
{
- return ((valid == other.valid)
- && (travelTime == other.travelTime)
- && (distance == other.distance)
- && (path == other.path)
- && (maneuver == other.maneuver));
+ return ((valid() == other.valid())
+ && (travelTime() == other.travelTime())
+ && (distance() == other.distance())
+ && (path() == other.path())
+ && (maneuver() == other.maneuver()));
+}
+
+bool QGeoRouteSegmentPrivate::valid() const
+{
+ return false;
+}
+
+void QGeoRouteSegmentPrivate::setValid(bool valid)
+{
+ Q_UNUSED(valid)
+}
+
+int QGeoRouteSegmentPrivate::travelTime() const
+{
+ return 0;
+}
+
+void QGeoRouteSegmentPrivate::setTravelTime(int travelTime)
+{
+ Q_UNUSED(travelTime)
+}
+
+qreal QGeoRouteSegmentPrivate::distance() const
+{
+ return 0;
+}
+
+void QGeoRouteSegmentPrivate::setDistance(qreal distance)
+{
+ Q_UNUSED(distance)
+}
+
+QList<QGeoCoordinate> QGeoRouteSegmentPrivate::path() const
+{
+ return QList<QGeoCoordinate>();
+}
+
+void QGeoRouteSegmentPrivate::setPath(const QList<QGeoCoordinate> &path)
+{
+ Q_UNUSED(path)
+}
+
+QGeoManeuver QGeoRouteSegmentPrivate::maneuver() const
+{
+ return QGeoManeuver();
+}
+
+void QGeoRouteSegmentPrivate::setManeuver(const QGeoManeuver &maneuver)
+{
+ Q_UNUSED(maneuver)
+}
+
+QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> QGeoRouteSegmentPrivate::nextRouteSegment() const
+{
+ return m_nextSegment;
+}
+
+void QGeoRouteSegmentPrivate::setNextRouteSegment(const QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> &next)
+{
+ m_nextSegment = next;
}
/*******************************************************************************
*******************************************************************************/
-QT_END_NAMESPACE
+QGeoRouteSegmentPrivateDefault::QGeoRouteSegmentPrivateDefault()
+ : m_valid(false),
+ m_travelTime(0),
+ m_distance(0.0)
+{
+}
+
+QGeoRouteSegmentPrivateDefault::QGeoRouteSegmentPrivateDefault(const QGeoRouteSegmentPrivateDefault &other)
+ : QGeoRouteSegmentPrivate(other),
+ m_valid(other.m_valid),
+ m_travelTime(other.m_travelTime),
+ m_distance(other.m_distance),
+ m_path(other.m_path),
+ m_maneuver(other.m_maneuver)
+{
+
+}
+
+QGeoRouteSegmentPrivateDefault::~QGeoRouteSegmentPrivateDefault()
+{
+
+}
+
+bool QGeoRouteSegmentPrivateDefault::operator ==(const QGeoRouteSegmentPrivateDefault &other) const
+{
+ return QGeoRouteSegmentPrivateDefault::operator ==(other);
+}
+
+bool QGeoRouteSegmentPrivateDefault::valid() const
+{
+ return m_valid;
+}
+
+void QGeoRouteSegmentPrivateDefault::setValid(bool valid)
+{
+ m_valid = valid;
+}
+
+int QGeoRouteSegmentPrivateDefault::travelTime() const
+{
+ return m_travelTime;
+}
+
+void QGeoRouteSegmentPrivateDefault::setTravelTime(int travelTime)
+{
+ m_travelTime = travelTime;
+}
+
+qreal QGeoRouteSegmentPrivateDefault::distance() const
+{
+ return m_distance;
+}
+
+void QGeoRouteSegmentPrivateDefault::setDistance(qreal distance)
+{
+ m_distance = distance;
+}
+
+QList<QGeoCoordinate> QGeoRouteSegmentPrivateDefault::path() const
+{
+ return m_path;
+}
+
+void QGeoRouteSegmentPrivateDefault::setPath(const QList<QGeoCoordinate> &path)
+{
+ m_path = path;
+}
+
+QGeoManeuver QGeoRouteSegmentPrivateDefault::maneuver() const
+{
+ return m_maneuver;
+}
+
+void QGeoRouteSegmentPrivateDefault::setManeuver(const QGeoManeuver &maneuver)
+{
+ m_maneuver = maneuver;
+}
+
+/*******************************************************************************
+*******************************************************************************/
+
+QT_END_NAMESPACE
diff --git a/src/location/maps/qgeoroutesegment.h b/src/location/maps/qgeoroutesegment.h
index bddc172c..a90399be 100644
--- a/src/location/maps/qgeoroutesegment.h
+++ b/src/location/maps/qgeoroutesegment.h
@@ -78,9 +78,8 @@ public:
QGeoManeuver maneuver() const;
protected:
- QGeoRouteSegment(QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> &d_ptr);
+ QGeoRouteSegment(const QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> &dd);
-private:
QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> d_ptr;
};
diff --git a/src/location/maps/qgeoroutesegment_p.h b/src/location/maps/qgeoroutesegment_p.h
index 1751266a..8f452896 100644
--- a/src/location/maps/qgeoroutesegment_p.h
+++ b/src/location/maps/qgeoroutesegment_p.h
@@ -48,7 +48,10 @@
// We mean it.
//
-#include "qgeomaneuver.h"
+#include <QtLocation/private/qlocationglobal_p.h>
+#include <QtLocation/qgeomaneuver.h>
+#include <QtLocation/qgeoroutesegment.h>
+
#include <QSharedData>
#include <QList>
@@ -58,23 +61,68 @@ QT_BEGIN_NAMESPACE
class QGeoCoordinate;
-class QGeoRouteSegmentPrivate : public QSharedData
+class Q_LOCATION_PRIVATE_EXPORT QGeoRouteSegmentPrivate : public QSharedData
{
public:
QGeoRouteSegmentPrivate();
QGeoRouteSegmentPrivate(const QGeoRouteSegmentPrivate &other);
- ~QGeoRouteSegmentPrivate();
+ virtual ~QGeoRouteSegmentPrivate();
bool operator ==(const QGeoRouteSegmentPrivate &other) const;
- bool valid;
+ virtual bool valid() const;
+ virtual void setValid(bool valid);
+
+ virtual int travelTime() const;
+ virtual void setTravelTime(int travelTime);
+
+ virtual qreal distance() const;
+ virtual void setDistance(qreal distance);
+
+ virtual QList<QGeoCoordinate> path() const;
+ virtual void setPath(const QList<QGeoCoordinate> &path);
+
+ virtual QGeoManeuver maneuver() const;
+ virtual void setManeuver(const QGeoManeuver &maneuver);
+
+ virtual QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> nextRouteSegment() const;
+ virtual void setNextRouteSegment(const QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> &next);
+
+ QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> m_nextSegment;
+};
+
+
+
+class Q_LOCATION_PRIVATE_EXPORT QGeoRouteSegmentPrivateDefault : public QGeoRouteSegmentPrivate
+{
+public:
+ QGeoRouteSegmentPrivateDefault();
+ QGeoRouteSegmentPrivateDefault(const QGeoRouteSegmentPrivateDefault &other);
+ ~QGeoRouteSegmentPrivateDefault();
+
+ bool operator ==(const QGeoRouteSegmentPrivateDefault &other) const;
+
+ virtual bool valid() const override;
+ virtual void setValid(bool valid) override;
+
+ virtual int travelTime() const override;
+ virtual void setTravelTime(int travelTime) override;
+
+ virtual qreal distance() const override;
+ virtual void setDistance(qreal distance) override;
+
+ virtual QList<QGeoCoordinate> path() const override;
+ virtual void setPath(const QList<QGeoCoordinate> &path) override;
+
+ virtual QGeoManeuver maneuver() const override;
+ virtual void setManeuver(const QGeoManeuver &maneuver) override;
- int travelTime;
- qreal distance;
- QList<QGeoCoordinate> path;
- QGeoManeuver maneuver;
- QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> nextSegment;
+ bool m_valid;
+ int m_travelTime;
+ qreal m_distance;
+ QList<QGeoCoordinate> m_path;
+ QGeoManeuver m_maneuver;
};
QT_END_NAMESPACE
diff --git a/tests/auto/declarative_core/tst_routing.qml b/tests/auto/declarative_core/tst_routing.qml
index fdbfe7b6..c090a5ea 100644
--- a/tests/auto/declarative_core/tst_routing.qml
+++ b/tests/auto/declarative_core/tst_routing.qml
@@ -503,6 +503,14 @@ Item {
}
Plugin {
+ id: testPlugin_slacker_alt
+ name: "qmlgeo.test.plugin"
+ allowExperimental: true
+ PluginParameter { name: "gc_finishRequestImmediately"; value: false}
+ PluginParameter { name: "gc_alternateGeoRoute"; value: true}
+ }
+
+ Plugin {
id: bacicRoutingPlugin_slacker;
name: "qmlgeo.test.plugin"
allowExperimental: true
@@ -529,24 +537,27 @@ Item {
property variant f2coordinate3: QtPositioning.coordinate(63, 64)
RouteQuery {id: routeQuery}
+ property var routeQueryDefaultWaypoints: [
+ { latitude: 60, longitude: 60 },
+ { latitude: 61, longitude: 62 },
+ { latitude: 63, longitude: 64 },
+ { latitude: 65, longitude: 66 },
+ { latitude: 67, longitude: 68 }
+ ]
+ property var routeQuery2DefaultWaypoints: [
+ f2coordinate1,
+ f2coordinate2,
+ f2coordinate3
+ ]
RouteQuery {
id: filledRouteQuery
numberAlternativeRoutes: 0
- waypoints: [
- { latitude: 60, longitude: 60 },
- { latitude: 61, longitude: 62 },
- { latitude: 63, longitude: 64 },
- { latitude: 65, longitude: 66 },
- { latitude: 67, longitude: 68 }
- ]
+ waypoints: routeQueryDefaultWaypoints
}
RouteQuery {
id: filledRouteQuery2
- waypoints: [
- f2coordinate1,
- f2coordinate2,
- f2coordinate3
- ]
+ numberAlternativeRoutes: 0
+ waypoints: routeQuery2DefaultWaypoints
}
RouteModel {
id: routeModelAutomatic;
@@ -554,8 +565,15 @@ Item {
query: filledRouteQuery;
autoUpdate: true
}
+ RouteModel {
+ id: routeModelAutomaticAltImpl;
+ plugin: testPlugin_slacker_alt;
+ query: filledRouteQuery;
+ autoUpdate: true
+ }
SignalSpy {id: automaticRoutesSpy; target: routeModelAutomatic; signalName: "routesChanged" }
+ SignalSpy {id: automaticRoutesSpyAlt; target: routeModelAutomaticAltImpl; signalName: "routesChanged" }
RouteModel {id: routeModel; plugin: testPlugin_immediate; query: routeQuery }
SignalSpy {id: testRoutesSpy; target: routeModel; signalName: "routesChanged"}
@@ -740,26 +758,34 @@ Item {
compare(testCountSlackSpy.count, 1)
compare(routeModelSlack.count, 1)
+ test_basic_routing_automatic(routeModelAutomatic, automaticRoutesSpy, "routeModelAutomatic")
+ test_basic_routing_automatic(routeModelAutomaticAltImpl, automaticRoutesSpyAlt, "routeModelAutomaticAltImpl")
+ }
+
+ function test_basic_routing_automatic(model, spy, label) {
+ if (label === undefined)
+ return
+ console.log("testing",label)
// Autoupdate
- automaticRoutesSpy.clear();
+ spy.clear();
filledRouteQuery.numberAlternativeRoutes = 1 // 'altroutes - 70' is the echoed errorcode
- tryCompare (automaticRoutesSpy, "count", 1) // 5 sec
- 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)
+ tryCompare (spy, "count", 1) // 5 sec
+ compare(model.count, 1) // There should be a route already
+ compare (model.get(0).path.length, 5)
+ compare (model.get(0).path[0].latitude, filledRouteQuery.waypoints[0].latitude)
// Remove a waypoint and check that autoupdate works
filledRouteQuery.removeWaypoint(fcoordinate2)
- tryCompare (automaticRoutesSpy, "count", 2)
- compare (routeModelAutomatic.get(0).path.length, 4)
- compare (routeModelAutomatic.get(0).path[0].latitude, fcoordinate1.latitude)
+ tryCompare (spy, "count", 2)
+ compare (model.get(0).path.length, 4)
+ compare (model.get(0).path[0].latitude, fcoordinate1.latitude)
// Add a waypoint and check that autoupdate works
filledRouteQuery.addWaypoint(fcoordinate2);
- tryCompare (automaticRoutesSpy, "count", 3)
- compare(routeModelAutomatic.count, 1);
- compare(routeModelAutomatic.get(0).path.length, 5);
- compare(routeModelAutomatic.get(0).path[0].latitude, filledRouteQuery.waypoints[0].latitude);
+ tryCompare (spy, "count", 3)
+ compare(model.count, 1);
+ compare(model.get(0).path.length, 5);
+ compare(model.get(0).path[0].latitude, filledRouteQuery.waypoints[0].latitude);
// Change contents of a coordinate and check that autoupdate works
filledRouteQuery.waypoints = [
@@ -769,14 +795,14 @@ Item {
{ latitude: 65, longitude: 66 },
{ latitude: 67, longitude: 68 }
];
- tryCompare (automaticRoutesSpy, "count", 4)
- compare(routeModelAutomatic.get(0).path[0].latitude, fcoordinate1.latitude + 1) // new value should be echoed
+ tryCompare (spy, "count", 4)
+ compare(model.get(0).path[0].latitude, fcoordinate1.latitude + 1) // new value should be echoed
// Change query
- routeModelAutomatic.query = filledRouteQuery2
+ model.query = filledRouteQuery2
filledRouteQuery2.numberAlternativeRoutes = 3
- tryCompare (automaticRoutesSpy, "count", 5)
- compare (routeModelAutomatic.get(0).path.length, 3)
+ tryCompare (spy, "count", 5)
+ compare (model.get(0).path.length, 3)
// Verify that the old query is disconnected internally ie. does not trigger update
filledRouteQuery.waypoints = [
@@ -787,10 +813,18 @@ Item {
{ latitude: 67, longitude: 68 }
];
wait(800) // wait to hope no further updates comes through
- compare (automaticRoutesSpy.count, 5)
- compare(routeModelAutomatic.get(0).path.length, 3);
+ compare (spy.count, 5)
+ compare(model.get(0).path.length, 3);
+
+ // ReSetting
+ filledRouteQuery.numberAlternativeRoutes = 0
+ filledRouteQuery2.numberAlternativeRoutes = 0
+ filledRouteQuery.waypoints = routeQueryDefaultWaypoints
+ filledRouteQuery2.waypoints = routeQuery2DefaultWaypoints
}
+
+
function test_route_query_handles_destroyed_qml_objects() {
var coordinate = QtPositioning.coordinate(11, 52);
routeQuery.addWaypoint(coordinate);
diff --git a/tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h b/tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h
index 0a1e7ce6..c77cb0a5 100644
--- a/tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h
+++ b/tests/auto/geotestplugin/qgeoroutingmanagerengine_test.h
@@ -34,6 +34,7 @@
#include <QLocale>
#include <qgeoaddress.h>
#include <qgeoroutereply.h>
+#include <QtLocation/private/qgeoroute_p.h>
#include <QDebug>
#include <QTimer>
@@ -42,6 +43,24 @@
QT_USE_NAMESPACE
+class QGeoRoutePrivateDefaultAlt : public QGeoRoutePrivateDefault
+{
+public:
+ QGeoRoutePrivateDefaultAlt() {}
+ QGeoRoutePrivateDefaultAlt(const QGeoRoutePrivateDefaultAlt &other)
+ : QGeoRoutePrivateDefault(other) {}
+ ~QGeoRoutePrivateDefaultAlt() {}
+};
+
+class QGeoRouteAlt : public QGeoRoute
+{
+public:
+ QGeoRouteAlt()
+ : QGeoRoute(QExplicitlySharedDataPointer<QGeoRoutePrivate>(new QGeoRoutePrivateDefaultAlt()))
+ {
+ }
+};
+
class RouteReplyTest :public QGeoRouteReply
{
Q_OBJECT
@@ -62,6 +81,7 @@ class QGeoRoutingManagerEngineTest: public QGeoRoutingManagerEngine
int timerId_;
QGeoRouteReply::Error errorCode_;
QString errorString_;
+ bool alternateGeoRouteImplementation_;
public:
QGeoRoutingManagerEngineTest(const QVariantMap &parameters,
@@ -70,7 +90,8 @@ public:
routeReply_(0),
finishRequestImmediately_(true),
timerId_(0),
- errorCode_(QGeoRouteReply::NoError)
+ errorCode_(QGeoRouteReply::NoError),
+ alternateGeoRouteImplementation_(false)
{
Q_UNUSED(error)
Q_UNUSED(errorString)
@@ -79,6 +100,10 @@ public:
finishRequestImmediately_ = qvariant_cast<bool>(parameters.value("gc_finishRequestImmediately"));
}
+ if (parameters.contains("gc_alternateGeoRoute")) {
+ alternateGeoRouteImplementation_ = qvariant_cast<bool>(parameters.value("gc_alternateGeoRoute"));
+ }
+
setLocale(QLocale (QLocale::German, QLocale::Germany));
setSupportedFeatureTypes (
QGeoRouteRequest::NoFeature | QGeoRouteRequest::TollFeature |
@@ -136,6 +161,8 @@ public:
QList<QGeoRoute> routes;
for (int i = 0; i < request.numberAlternativeRoutes(); ++i) {
QGeoRoute route;
+ if (alternateGeoRouteImplementation_)
+ route = QGeoRouteAlt();
route.setPath(request.waypoints());
routes.append(route);
}