Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdeclarativeroutemapitem.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
7
8#include <QtQml/QQmlInfo>
9#include <QtGui/QPainter>
10
11QT_BEGIN_NAMESPACE
12
13/*!
14 \qmltype MapRoute
15 \nativetype QDeclarativeRouteMapItem
16 \inqmlmodule QtLocation
17 \ingroup qml-QtLocation5-maps
18 \since QtLocation 5.0
19
20 \brief The MapRoute type displays a Route on a Map.
21
22 The MapRoute type displays a Route obtained through a RouteModel or
23 other means, on the Map as a Polyline following the path of the Route.
24
25 MapRoute is really a \l MapPolyline, but with the path specified using the
26 \l route property instead of directly in \l {coordinate}{coordinates}.
27
28 By default, the route is displayed as a 1-pixel thick black line. This can
29 be changed using the \l line.width and \l line.color properties.
30
31 \section2 Example Usage
32
33 Here is how to draw a \l{route}{route} on a \l{Map}{map}:
34
35 \snippet declarative/maps.qml QtQuick import
36 \snippet declarative/maps.qml QtLocation import
37 \codeline
38 \snippet declarative/maps.qml MapRoute
39*/
40
41/*!
42 \qmlpropertygroup Location::MapRoute::line
43 \qmlproperty int MapRoute::line.width
44 \qmlproperty color MapRoute::line.color
45
46 This property is part of the line property group. The line
47 property group holds the width and color used to draw the line.
48
49 The width is in pixels and is independent of the zoom level of the map.
50 The default values correspond to a black border with a width of 1 pixel.
51
52 For no line, use a width of 0 or a transparent color.
53*/
54
55
56QDeclarativeRouteMapItem::QDeclarativeRouteMapItem(QQuickItem *parent)
57: QDeclarativePolylineMapItem(parent)
58{
59 setFlag(ItemHasContents, true);
60}
61
62QDeclarativeRouteMapItem::~QDeclarativeRouteMapItem()
63{
64}
65
66/*!
67 \qmlproperty Route MapRoute::route
68
69 This property holds the route to be drawn which can be used
70 to represent one geographical route.
71*/
72QGeoRoute QDeclarativeRouteMapItem::route() const
73{
74 return route_;
75}
76
77void QDeclarativeRouteMapItem::setRoute(const QGeoRoute &route)
78{
79 if (route_ == route)
80 return;
81
82 route_ = route;
83
84 setPathFromGeoList(route_.path());
85
86 emit routeChanged(route_);
87}
88
89void QDeclarativeRouteMapItem::updateRoutePath()
90{
91 setPathFromGeoList(route_.path());
92}
93
94/*!
95 \internal void QDeclarativeRouteMapItem::setPath(const QList<QGeoCoordinate> &value)
96
97 Used to disable path property on the RouteMapItem
98 */
99void QDeclarativeRouteMapItem::setPath(const QList<QGeoCoordinate> &value)
100{
101 Q_UNUSED(value);
102 qWarning() << "Can not set the path on QDeclarativeRouteMapItem."
103 << "Please use the route property instead.";
104}
105
106QT_END_NAMESPACE