| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtLocation module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or later as published by the Free |
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
| 29 | ** the packaging of this file. Please review the following information to |
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be |
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
| 32 | ** |
| 33 | ** $QT_END_LICENSE$ |
| 34 | ** |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | |
| 38 | #include "qdeclarativeroutemapitem_p.h" |
| 39 | #include "qdeclarativepolylinemapitem_p.h" |
| 40 | #include "qdeclarativegeoroute_p.h" |
| 41 | |
| 42 | #include <QtQml/QQmlInfo> |
| 43 | #include <QtGui/QPainter> |
| 44 | |
| 45 | QT_BEGIN_NAMESPACE |
| 46 | |
| 47 | /*! |
| 48 | \qmltype MapRoute |
| 49 | \instantiates QDeclarativeRouteMapItem |
| 50 | \inqmlmodule QtLocation |
| 51 | \ingroup qml-QtLocation5-maps |
| 52 | \since QtLocation 5.0 |
| 53 | |
| 54 | \brief The MapRoute type displays a Route on a Map. |
| 55 | |
| 56 | The MapRoute type displays a Route obtained through a RouteModel or |
| 57 | other means, on the Map as a Polyline following the path of the Route. |
| 58 | |
| 59 | MapRoute is really a \l MapPolyline, but with the path specified using the |
| 60 | \l route property instead of directly in \l {coordinate}{coordinates}. |
| 61 | |
| 62 | By default, the route is displayed as a 1-pixel thick black line. This can |
| 63 | be changed using the \l line.width and \l line.color properties. |
| 64 | |
| 65 | \section2 Performance |
| 66 | |
| 67 | For notes about the performance on MapRoute, refer to the documentation for |
| 68 | \l MapPolyline. |
| 69 | |
| 70 | \section2 Example Usage |
| 71 | |
| 72 | Here is how to draw a \l{Route}{route} on a \l{Map}{map}: |
| 73 | |
| 74 | \snippet declarative/maps.qml QtQuick import |
| 75 | \snippet declarative/maps.qml QtLocation import |
| 76 | \codeline |
| 77 | \snippet declarative/maps.qml MapRoute |
| 78 | */ |
| 79 | |
| 80 | /*! |
| 81 | \qmlpropertygroup Location::MapRoute::line |
| 82 | \qmlproperty int MapRoute::line.width |
| 83 | \qmlproperty color MapRoute::line.color |
| 84 | |
| 85 | This property is part of the line property group. The line |
| 86 | property group holds the width and color used to draw the line. |
| 87 | |
| 88 | The width is in pixels and is independent of the zoom level of the map. |
| 89 | The default values correspond to a black border with a width of 1 pixel. |
| 90 | |
| 91 | For no line, use a width of 0 or a transparent color. |
| 92 | */ |
| 93 | |
| 94 | |
| 95 | QDeclarativeRouteMapItem::QDeclarativeRouteMapItem(QQuickItem *parent) |
| 96 | : QDeclarativePolylineMapItem(parent), route_(0) |
| 97 | { |
| 98 | setFlag(flag: ItemHasContents, enabled: true); |
| 99 | } |
| 100 | |
| 101 | QDeclarativeRouteMapItem::~QDeclarativeRouteMapItem() |
| 102 | { |
| 103 | } |
| 104 | |
| 105 | /*! |
| 106 | \qmlproperty Route MapRoute::route |
| 107 | |
| 108 | This property holds the route to be drawn which can be used |
| 109 | to represent one geographical route. |
| 110 | */ |
| 111 | QDeclarativeGeoRoute *QDeclarativeRouteMapItem::route() const |
| 112 | { |
| 113 | return route_; |
| 114 | } |
| 115 | |
| 116 | void QDeclarativeRouteMapItem::setRoute(QDeclarativeGeoRoute *route) |
| 117 | { |
| 118 | if (route_ == route) |
| 119 | return; |
| 120 | |
| 121 | route_ = route; |
| 122 | |
| 123 | connect(sender: route_, SIGNAL(pathChanged()), receiver: this, SLOT(updateRoutePath())); |
| 124 | |
| 125 | if (route_) |
| 126 | setPathFromGeoList(route_->routePath()); |
| 127 | |
| 128 | emit routeChanged(route: route_); |
| 129 | } |
| 130 | |
| 131 | void QDeclarativeRouteMapItem::updateRoutePath() |
| 132 | { |
| 133 | setPathFromGeoList(route_->routePath()); |
| 134 | } |
| 135 | |
| 136 | /*! |
| 137 | \internal void QDeclarativeRouteMapItem::setPath(const QJSValue &value) |
| 138 | |
| 139 | Used to disable path property on the RouteMapItem |
| 140 | */ |
| 141 | void QDeclarativeRouteMapItem::setPath(const QJSValue &value) |
| 142 | { |
| 143 | Q_UNUSED(value); |
| 144 | qWarning() << "Can not set the path on QDeclarativeRouteMapItem." |
| 145 | << "Please use the route property instead." ; |
| 146 | } |
| 147 | |
| 148 | QT_END_NAMESPACE |
| 149 | |