Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qdeclarativesearchmodelbase.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
// Qt-Security score:significant reason:default
4
5
#
include
"qdeclarativesearchmodelbase_p.h"
6
#
include
"qdeclarativeplace_p.h"
7
#
include
"error_messages_p.h"
8
9
#
include
<
QtCore
/
QCoreApplication
>
10
#
include
<
QtQml
/
QQmlInfo
>
11
#
include
<
QtLocation
/
QGeoServiceProvider
>
12
#
include
<
QtLocation
/
QPlaceIcon
>
13
#
include
<
QtLocation
/
QPlaceManager
>
14
#
include
<
QtLocation
/
QPlaceSearchRequest
>
15
#
include
<
QtLocation
/
QPlaceSearchReply
>
16
#
include
<
QtPositioning
/
QGeoCircle
>
17
#
include
<
QtPositioning
/
QGeoPolygon
>
18
#
include
<
QtLocation
/
private
/
qplacesearchrequest_p
.
h
>
19
20
QT_BEGIN_NAMESPACE
21
22
QDeclarativeSearchModelBase::QDeclarativeSearchModelBase(QObject *parent)
23
: QAbstractListModel(parent)
24
{
25
}
26
27
QDeclarativeSearchModelBase::~QDeclarativeSearchModelBase()
28
{
29
}
30
31
/*!
32
\internal
33
*/
34
QDeclarativeGeoServiceProvider *QDeclarativeSearchModelBase::plugin()
const
35
{
36
return
m_plugin;
37
}
38
39
/*!
40
\internal
41
*/
42
void
QDeclarativeSearchModelBase::setPlugin(QDeclarativeGeoServiceProvider *plugin)
43
{
44
if
(m_plugin == plugin)
45
return
;
46
47
initializePlugin(plugin);
48
49
if
(m_complete)
50
emit pluginChanged();
51
}
52
53
/*!
54
\internal
55
*/
56
QVariant QDeclarativeSearchModelBase::searchArea()
const
57
{
58
QGeoShape s = m_request.searchArea();
59
if
(s.type() == QGeoShape::RectangleType)
60
return
QVariant::fromValue(QGeoRectangle(s));
61
else
if
(s.type() == QGeoShape::CircleType)
62
return
QVariant::fromValue(QGeoCircle(s));
63
else
if
(s.type() == QGeoShape::PolygonType)
64
return
QVariant::fromValue(QGeoPolygon(s));
65
else
66
return
QVariant::fromValue(s);
67
}
68
69
/*!
70
\internal
71
*/
72
void
QDeclarativeSearchModelBase::setSearchArea(
const
QVariant &searchArea)
73
{
74
QGeoShape s;
75
QGeoRoute route;
76
bool
routeSearchArea =
false
;
77
if
(searchArea.userType() == qMetaTypeId<QGeoRectangle>()) {
78
s = searchArea.value<QGeoRectangle>();
79
}
else
if
(searchArea.userType() == qMetaTypeId<QGeoCircle>()) {
80
s = searchArea.value<QGeoCircle>();
81
}
else
if
(searchArea.userType() == qMetaTypeId<QGeoShape>()) {
82
s = searchArea.value<QGeoShape>();
83
}
else
if
(searchArea.typeId() == qMetaTypeId<QGeoRoute>()) {
84
route = searchArea.value<QGeoRoute>();
85
if
(route == QGeoRoute())
86
return
;
87
routeSearchArea =
true
;
88
}
89
90
QPlaceSearchRequestPrivate *rp = QPlaceSearchRequestPrivate::get(m_request);
91
// Invalidating the other thing
92
if
(routeSearchArea)
93
m_request.setSearchArea(QGeoShape());
94
else
95
rp->routeSearchArea = QGeoRoute();
96
97
if
(m_request.searchArea() == s
98
&& (route == QGeoRoute() || rp->routeSearchArea == route)) {
99
return
;
100
}
101
102
if
(routeSearchArea)
103
rp->routeSearchArea = route;
104
else
105
m_request.setSearchArea(s);
106
emit searchAreaChanged();
107
}
108
109
/*!
110
\internal
111
*/
112
int
QDeclarativeSearchModelBase::limit()
const
113
{
114
return
m_request.limit();
115
}
116
117
/*!
118
\internal
119
*/
120
void
QDeclarativeSearchModelBase::setLimit(
int
limit)
121
{
122
if
(m_request.limit() == limit)
123
return
;
124
125
m_request.setLimit(limit);
126
emit limitChanged();
127
}
128
129
/*!
130
\internal
131
*/
132
bool
QDeclarativeSearchModelBase::previousPagesAvailable()
const
133
{
134
return
m_previousPageRequest != QPlaceSearchRequest();
135
}
136
137
/*!
138
\internal
139
*/
140
bool
QDeclarativeSearchModelBase::nextPagesAvailable()
const
141
{
142
return
m_nextPageRequest != QPlaceSearchRequest();
143
}
144
145
/*!
146
\internal
147
*/
148
QDeclarativeSearchModelBase::Status QDeclarativeSearchModelBase::status()
const
149
{
150
return
m_status;
151
}
152
153
/*!
154
\internal
155
*/
156
void
QDeclarativeSearchModelBase::setStatus(Status status,
const
QString &errorString)
157
{
158
Status prevStatus = m_status;
159
160
m_status = status;
161
m_errorString = errorString;
162
163
if
(prevStatus != m_status)
164
emit statusChanged();
165
}
166
167
/*!
168
\internal
169
*/
170
void
QDeclarativeSearchModelBase::update()
171
{
172
if
(m_reply)
173
return
;
174
175
setStatus(Loading);
176
177
if
(!m_plugin) {
178
clearData();
179
setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_PROPERTY_NOT_SET));
180
return
;
181
}
182
183
QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
184
if
(!serviceProvider) {
185
clearData();
186
setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_PROVIDER_ERROR)
187
.arg(m_plugin->name()));
188
return
;
189
}
190
191
QPlaceManager *placeManager = serviceProvider->placeManager();
192
if
(!placeManager) {
193
clearData();
194
setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_ERROR)
195
.arg(m_plugin->name()).arg(serviceProvider->errorString()));
196
return
;
197
}
198
199
m_reply = sendQuery(placeManager, m_request);
200
if
(!m_reply) {
201
clearData();
202
setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, UNABLE_TO_MAKE_REQUEST));
203
return
;
204
}
205
206
m_reply->setParent(
this
);
207
connect(m_reply, &QPlaceReply::finished,
208
this
, &QDeclarativeSearchModelBase::queryFinished);
209
connect(m_reply, &QPlaceReply::contentUpdated,
210
this
, &QDeclarativeSearchModelBase::onContentUpdated);
211
}
212
213
/*!
214
\internal
215
*/
216
void
QDeclarativeSearchModelBase::cancel()
217
{
218
if
(!m_reply)
219
return
;
220
221
if
(!m_reply->isFinished())
222
m_reply->abort();
223
224
if
(m_reply) {
225
m_reply->deleteLater();
226
m_reply =
nullptr
;
227
}
228
229
setStatus(Ready);
230
}
231
232
/*!
233
\internal
234
*/
235
void
QDeclarativeSearchModelBase::reset()
236
{
237
beginResetModel();
238
clearData();
239
setStatus(Null);
240
endResetModel();
241
}
242
243
/*!
244
\internal
245
*/
246
QString QDeclarativeSearchModelBase::errorString()
const
247
{
248
return
m_errorString;
249
}
250
251
/*!
252
\internal
253
*/
254
void
QDeclarativeSearchModelBase::previousPage()
255
{
256
if
(m_previousPageRequest == QPlaceSearchRequest())
257
return
;
258
259
m_request = m_previousPageRequest;
260
update();
261
}
262
263
/*!
264
\internal
265
*/
266
void
QDeclarativeSearchModelBase::nextPage()
267
{
268
if
(m_nextPageRequest == QPlaceSearchRequest())
269
return
;
270
271
m_request = m_nextPageRequest;
272
update();
273
}
274
275
/*!
276
\internal
277
*/
278
void
QDeclarativeSearchModelBase::clearData(
bool
suppressSignal)
279
{
280
Q_UNUSED(suppressSignal);
281
}
282
283
/*!
284
\internal
285
*/
286
void
QDeclarativeSearchModelBase::classBegin()
287
{
288
}
289
290
/*!
291
\internal
292
*/
293
void
QDeclarativeSearchModelBase::componentComplete()
294
{
295
m_complete =
true
;
296
}
297
298
/*!
299
\internal
300
*/
301
void
QDeclarativeSearchModelBase::initializePlugin(QDeclarativeGeoServiceProvider *plugin)
302
{
303
beginResetModel();
304
if
(plugin != m_plugin) {
305
if
(m_plugin) {
306
disconnect(m_plugin, &QDeclarativeGeoServiceProvider::nameChanged,
307
this
, &QDeclarativeSearchModelBase::pluginNameChanged);
308
}
309
if
(plugin) {
310
connect(plugin, &QDeclarativeGeoServiceProvider::nameChanged,
311
this
, &QDeclarativeSearchModelBase::pluginNameChanged);
312
}
313
m_plugin = plugin;
314
}
315
316
if
(m_plugin) {
317
QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
318
if
(serviceProvider) {
319
QPlaceManager *placeManager = serviceProvider->placeManager();
320
if
(placeManager) {
321
if
(placeManager->childCategoryIds().isEmpty()) {
322
QPlaceReply *reply = placeManager->initializeCategories();
323
connect(reply, &QPlaceReply::finished, reply, &QObject::deleteLater);
324
}
325
}
326
}
327
}
328
329
endResetModel();
330
}
331
332
void
QDeclarativeSearchModelBase::onContentUpdated()
333
{
334
335
}
336
337
/*!
338
\internal
339
*/
340
void
QDeclarativeSearchModelBase::pluginNameChanged()
341
{
342
initializePlugin(m_plugin);
343
}
344
345
/*!
346
\internal
347
*/
348
void
QDeclarativeSearchModelBase::setPreviousPageRequest(
const
QPlaceSearchRequest &previous)
349
{
350
if
(m_previousPageRequest == previous)
351
return
;
352
353
m_previousPageRequest = previous;
354
emit previousPagesAvailableChanged();
355
}
356
357
void
QDeclarativeSearchModelBase::setNextPageRequest(
const
QPlaceSearchRequest &next)
358
{
359
if
(m_nextPageRequest == next)
360
return
;
361
362
m_nextPageRequest = next;
363
emit nextPagesAvailableChanged();
364
}
365
366
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtlocation
src
location
declarativeplaces
qdeclarativesearchmodelbase.cpp
Generated on
for Qt by
1.18.0