summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2019-05-09 20:18:20 +0200
committerpaolo <paolo.angelelli@qt.io>2019-07-09 11:40:00 +0200
commit93fcae54d5f8cebf2e8988a5bc50ecb7a4f6b60c (patch)
treead0709a15cf1ded0aba780bdb6a1cbde9e40cedb
parenteefb728271ac436221a7a81aff8d7a29ac6ed936 (diff)
downloadqtlocation-93fcae54d5f8cebf2e8988a5bc50ecb7a4f6b60c.tar.gz
Expose alternativeRoutes in QDeclarativeNavigationBasicDirections
So that they can be also visualized in list views or details can be presented. Change-Id: Ib8bb48e73624d8bb50073312e7834c3c609c561b Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/location/labs/qdeclarativenavigator.cpp21
-rw-r--r--src/location/labs/qdeclarativenavigator_p_p.h49
-rw-r--r--src/location/maps/qnavigationmanagerengine.cpp5
-rw-r--r--src/location/maps/qnavigationmanagerengine_p.h2
4 files changed, 76 insertions, 1 deletions
diff --git a/src/location/labs/qdeclarativenavigator.cpp b/src/location/labs/qdeclarativenavigator.cpp
index 71e01ccb..ae273774 100644
--- a/src/location/labs/qdeclarativenavigator.cpp
+++ b/src/location/labs/qdeclarativenavigator.cpp
@@ -516,6 +516,8 @@ bool QDeclarativeNavigator::ensureEngine()
&d_ptr->m_basicDirections, &QDeclarativeNavigationBasicDirections::progressInformationChanged);
connect(d_ptr->m_navigator.get(), &QAbstractNavigator::isOnRouteChanged,
this, &QDeclarativeNavigator::isOnRouteChanged);
+ connect(d_ptr->m_navigator.get(), &QAbstractNavigator::alternativeRoutesChanged,
+ &d_ptr->m_basicDirections, &QDeclarativeNavigationBasicDirections::onAlternativeRoutesChanged);
emit navigatorReadyChanged(true);
return true;
@@ -540,7 +542,7 @@ void QDeclarativeNavigator::setError(QDeclarativeNavigator::NavigationError erro
}
QDeclarativeNavigationBasicDirections::QDeclarativeNavigationBasicDirections(QDeclarativeNavigator *parent)
-: QObject(parent), m_navigator(parent)
+: QObject(parent), m_navigator(parent), m_routes(QByteArrayLiteral("routeData"), this)
{
if (m_navigator)
m_navigatorPrivate = m_navigator->d_ptr.data();
@@ -710,6 +712,11 @@ int QDeclarativeNavigationBasicDirections::currentSegment() const
return m_navigatorPrivate->m_navigator->currentSegment();
}
+QAbstractItemModel *QDeclarativeNavigationBasicDirections::alternativeRoutes()
+{
+ return &m_routes;
+}
+
void QDeclarativeNavigationBasicDirections::onCurrentRouteChanged()
{
if (m_currentRoute)
@@ -726,5 +733,17 @@ void QDeclarativeNavigationBasicDirections::onCurrentRouteLegChanged()
emit currentRouteLegChanged();
}
+void QDeclarativeNavigationBasicDirections::onAlternativeRoutesChanged()
+{
+ const QList<QGeoRoute> &routes = m_navigatorPrivate->m_navigator->alternativeRoutes();
+ QList<QDeclarativeGeoRoute *> declarativeRoutes;
+ for (int i = 0; i < routes.size(); ++i) {
+ QDeclarativeGeoRoute *route = new QDeclarativeGeoRoute(routes.at(i), &m_routes);
+ QQmlEngine::setContextForObject(route, QQmlEngine::contextForObject(this));
+ declarativeRoutes.append(route);
+ }
+ m_routes.updateData(declarativeRoutes);
+}
+
QT_END_NAMESPACE
diff --git a/src/location/labs/qdeclarativenavigator_p_p.h b/src/location/labs/qdeclarativenavigator_p_p.h
index 04b8b1ef..5bf1bd12 100644
--- a/src/location/labs/qdeclarativenavigator_p_p.h
+++ b/src/location/labs/qdeclarativenavigator_p_p.h
@@ -53,6 +53,9 @@
#include <QtCore/qpointer.h>
#include <QtLocation/qgeoroute.h>
#include <QtLocation/private/qdeclarativenavigator_p.h>
+#include <QAbstractListModel>
+#include <QtLocation/private/qdeclarativegeoroute_p.h>
+#include <QtLocation/private/qdeclarativegeoroutemodel_p.h>
QT_BEGIN_NAMESPACE
@@ -67,6 +70,48 @@ class QDeclarativeGeoRouteSegment;
class QParameterizableObject;
class QAbstractNavigator;
+template<typename T, int Role>
+class ReadOnlyListModel : public QAbstractListModel
+{
+public:
+ explicit ReadOnlyListModel(const QByteArray &dataRoleName, QObject *parent = nullptr)
+ : QAbstractListModel(parent)
+ {
+ m_roleNames.insert(Role, dataRoleName);
+ }
+
+ int rowCount(const QModelIndex &) const override
+ {
+ return m_data.size();
+ }
+
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
+ {
+ const int row = index.row();
+ if (!index.isValid() || row < 0 || row >= m_data.size() || role != Role)
+ return QVariant();
+
+ return QVariant::fromValue(m_data.at(row));
+ }
+
+ QHash<int, QByteArray> roleNames() const override
+ {
+ return m_roleNames;
+ }
+
+ void updateData(const QList<T*> &data)
+ {
+ beginResetModel();
+ qDeleteAll(m_data);
+ m_data = data;
+ endResetModel();
+ }
+
+protected:
+ QHash<int, QByteArray> m_roleNames;
+ QList<T*> m_data;
+};
+
class Q_LOCATION_PRIVATE_EXPORT QDeclarativeNavigationBasicDirections : public QObject
{
Q_OBJECT
@@ -83,6 +128,7 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeNavigationBasicDirections : public Q
Q_PROPERTY(QDeclarativeGeoRoute *currentRoute READ currentRoute NOTIFY currentRouteChanged)
Q_PROPERTY(QDeclarativeGeoRouteLeg *currentRouteLeg READ currentRouteLeg NOTIFY currentRouteChanged)
Q_PROPERTY(int currentSegment READ currentSegment NOTIFY currentSegmentChanged)
+ Q_PROPERTY(QAbstractItemModel *alternativeRoutes READ alternativeRoutes CONSTANT)
public:
explicit QDeclarativeNavigationBasicDirections(QDeclarativeNavigator *parent);
@@ -100,6 +146,7 @@ public:
QDeclarativeGeoRoute *currentRoute() const;
QDeclarativeGeoRouteLeg *currentRouteLeg() const;
int currentSegment() const;
+ QAbstractItemModel *alternativeRoutes();
Q_SIGNALS:
void progressInformationChanged();
@@ -113,12 +160,14 @@ Q_SIGNALS:
protected slots:
void onCurrentRouteChanged();
void onCurrentRouteLegChanged();
+ void onAlternativeRoutesChanged();
protected:
QDeclarativeNavigator *m_navigator;
QDeclarativeNavigatorPrivate *m_navigatorPrivate;
QPointer<QDeclarativeGeoRoute> m_currentRoute;
QPointer<QDeclarativeGeoRouteLeg> m_currentRouteLeg;
+ ReadOnlyListModel<QDeclarativeGeoRoute, QDeclarativeGeoRouteModel::RouteRole> m_routes;
friend class QDeclarativeNavigator;
};
diff --git a/src/location/maps/qnavigationmanagerengine.cpp b/src/location/maps/qnavigationmanagerengine.cpp
index 8837e5c6..aa5a980b 100644
--- a/src/location/maps/qnavigationmanagerengine.cpp
+++ b/src/location/maps/qnavigationmanagerengine.cpp
@@ -141,6 +141,11 @@ QGeoRouteLeg QAbstractNavigator::currentRouteLeg() const
return QGeoRouteLeg();
}
+QList<QGeoRoute> QAbstractNavigator::alternativeRoutes() const
+{
+ return QList<QGeoRoute>();
+}
+
int QAbstractNavigator::currentSegment() const
{
return 0;
diff --git a/src/location/maps/qnavigationmanagerengine_p.h b/src/location/maps/qnavigationmanagerengine_p.h
index 658f4a9a..8d2c9a99 100644
--- a/src/location/maps/qnavigationmanagerengine_p.h
+++ b/src/location/maps/qnavigationmanagerengine_p.h
@@ -98,6 +98,7 @@ public:
virtual int traveledTime() const;
virtual QGeoRoute currentRoute() const;
virtual QGeoRouteLeg currentRouteLeg() const;
+ virtual QList<QGeoRoute> alternativeRoutes() const = 0;
virtual int currentSegment() const;
virtual void setAutomaticReroutingEnabled(bool autoRerouting) = 0;
virtual bool automaticReroutingEnabled() const = 0; // configured via navigation params at construction time
@@ -121,6 +122,7 @@ signals:
void nextManeuverIconChanged();
void progressInformationChanged();
void isOnRouteChanged();
+ void alternativeRoutesChanged();
private:
QScopedPointer<QAbstractNavigatorPrivate> d;