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
qdeclarativegeocodemodel_p.h
Go to the documentation of this file.
1// Copyright (C) 2015 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#ifndef QDECLARATIVEGEOCODEMODEL_H
5#define QDECLARATIVEGEOCODEMODEL_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtLocation/private/qlocationglobal_p.h>
19#include <QtLocation/private/qdeclarativegeoserviceprovider_p.h>
20
21#include <QtLocation/qgeocodereply.h>
22#include <QtPositioningQuick/private/qdeclarativegeoaddress_p.h>
23#include <QtPositioningQuick/private/qdeclarativegeolocation_p.h>
24
25#include <QtQml/qqml.h>
26#include <QtQml/QQmlParserStatus>
27#include <QAbstractListModel>
28#include <QPointer>
29
30
31QT_BEGIN_NAMESPACE
32
33class QGeoServiceProvider;
34class QGeoCodingManager;
35class QDeclarativeGeoLocation;
36
37class Q_LOCATION_EXPORT QDeclarativeGeocodeModel : public QAbstractListModel, public QQmlParserStatus
38{
39 Q_OBJECT
40 QML_NAMED_ELEMENT(GeocodeModel)
41 Q_ENUMS(Status)
42 Q_ENUMS(GeocodeError)
43
44 Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
45 Q_PROPERTY(bool autoUpdate READ autoUpdate WRITE setAutoUpdate NOTIFY autoUpdateChanged)
46 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
47 Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
48 Q_PROPERTY(int count READ count NOTIFY countChanged)
49 Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged)
50 Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged)
51 Q_PROPERTY(QVariant query READ query WRITE setQuery NOTIFY queryChanged)
52 Q_PROPERTY(QVariant bounds READ bounds WRITE setBounds NOTIFY boundsChanged)
53 Q_PROPERTY(GeocodeError error READ error NOTIFY errorChanged)
54 Q_INTERFACES(QQmlParserStatus)
55
56public:
57 enum Status {
58 Null,
59 Ready,
60 Loading,
61 Error
62 };
63
64 enum GeocodeError {
65 NoError = QGeoCodeReply::NoError,
66 EngineNotSetError = QGeoCodeReply::EngineNotSetError, //TODO Qt6 consider merge with NotSupportedError
67 CommunicationError = QGeoCodeReply::CommunicationError, //TODO Qt6 merge with Map's ConnectionError
68 ParseError = QGeoCodeReply::ParseError,
69 UnsupportedOptionError = QGeoCodeReply::UnsupportedOptionError, //TODO Qt6 consider rename UnsupportedOperationError
70 CombinationError = QGeoCodeReply::CombinationError,
71 UnknownError = QGeoCodeReply::UnknownError,
72 //we leave gap for future QGeoCodeReply errors
73
74 //QGeoServiceProvider related errors start here
75 UnknownParameterError = 100,
76 MissingRequiredParameterError
77 };
78
79 enum Roles {
80 LocationRole = Qt::UserRole + 1
81 };
82
83 explicit QDeclarativeGeocodeModel(QObject *parent = nullptr);
84 virtual ~QDeclarativeGeocodeModel();
85
86 // From QQmlParserStatus
87 void classBegin() override {}
88 void componentComplete() override;
89
90 // From QAbstractListModel
91 int rowCount(const QModelIndex &parent) const override;
92 QVariant data(const QModelIndex &index, int role) const override;
93 QHash<int,QByteArray> roleNames() const override;
94
95 void setPlugin(QDeclarativeGeoServiceProvider *plugin);
96 QDeclarativeGeoServiceProvider *plugin() const;
97
98 void setBounds(const QVariant &boundingArea);
99 QVariant bounds() const;
100
101 Status status() const;
102 QString errorString() const;
103 GeocodeError error() const;
104
105 bool autoUpdate() const;
106 void setAutoUpdate(bool update);
107
108 int count() const;
109 Q_INVOKABLE QDeclarativeGeoLocation *get(int index);
110
111 int limit() const;
112 void setLimit(int limit);
113 int offset() const;
114 void setOffset(int offset);
115
116 QVariant query() const;
117 void setQuery(const QVariant &query);
118 Q_INVOKABLE void reset();
119 Q_INVOKABLE void cancel();
120
121Q_SIGNALS:
122 void countChanged();
123 void pluginChanged();
124 void statusChanged();
125 void errorChanged(); //emitted also for errorString notification
126 void locationsChanged();
127 void autoUpdateChanged();
128 void boundsChanged();
129 void queryChanged();
130 void limitChanged();
131 void offsetChanged();
132
133public Q_SLOTS:
134 void update();
135
136protected Q_SLOTS:
137 void queryContentChanged();
138 void geocodeFinished(QGeoCodeReply *reply);
139 void geocodeError(QGeoCodeReply *reply,
140 QGeoCodeReply::Error error,
141 const QString &errorString);
142 void pluginReady();
143
144protected:
145 QGeoCodingManager *searchManager();
146 void setStatus(Status status);
147 void setError(GeocodeError error, const QString &errorString);
148 bool autoUpdate_ = false;
149 bool complete_ = false;
150
151private:
152 void setLocations(const QList<QGeoLocation> &locations);
153 void abortRequest();
154 QGeoCodeReply *reply_ = nullptr;
155
156 QDeclarativeGeoServiceProvider *plugin_ = nullptr;
157 QGeoShape boundingArea_;
158
159 QList<QDeclarativeGeoLocation *> declarativeLocations_;
160
161 Status status_ = QDeclarativeGeocodeModel::Null;
162 QString errorString_;
163 GeocodeError error_ = QDeclarativeGeocodeModel::NoError;
164 QVariant queryVariant_;
165 QGeoCoordinate coordinate_;
166 QDeclarativeGeoAddress *address_ = nullptr;
167 QString searchString_;
168
169 int limit_ = -1;
170 int offset_ = 0;
171};
172
173QT_END_NAMESPACE
174
175#endif