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