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#ifndef QDECLARATIVESEARCHMODELBASE_H
38#define QDECLARATIVESEARCHMODELBASE_H
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49//
50
51#include <QtLocation/private/qlocationglobal_p.h>
52#include <QtLocation/private/qdeclarativegeoserviceprovider_p.h>
53#include <QtCore/QAbstractListModel>
54#include <QtQml/QQmlParserStatus>
55#include <QtLocation/QPlaceSearchRequest>
56#include <QtLocation/QPlaceSearchResult>
57#include <QtLocation/QPlaceReply>
58
59QT_BEGIN_NAMESPACE
60
61class QPlaceManager;
62class QPlaceSearchRequest;
63class QPlaceSearchReply;
64class QDeclarativePlace;
65
66class Q_LOCATION_PRIVATE_EXPORT QDeclarativeSearchModelBase : public QAbstractListModel, public QQmlParserStatus
67{
68 Q_OBJECT
69
70 Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
71 Q_PROPERTY(QVariant searchArea READ searchArea WRITE setSearchArea NOTIFY searchAreaChanged)
72 Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged)
73 Q_PROPERTY(bool previousPagesAvailable READ previousPagesAvailable NOTIFY previousPagesAvailableChanged)
74 Q_PROPERTY(bool nextPagesAvailable READ nextPagesAvailable NOTIFY nextPagesAvailableChanged)
75 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
76
77 Q_ENUMS(Status)
78
79 Q_INTERFACES(QQmlParserStatus)
80
81public:
82 enum Status {
83 Null,
84 Ready,
85 Loading,
86 Error
87 };
88
89 explicit QDeclarativeSearchModelBase(QObject *parent = 0);
90 ~QDeclarativeSearchModelBase();
91
92 QDeclarativeGeoServiceProvider *plugin() const;
93 void setPlugin(QDeclarativeGeoServiceProvider *plugin);
94
95 QVariant searchArea() const;
96 void setSearchArea(const QVariant &searchArea);
97
98 int limit() const;
99 void setLimit(int limit);
100
101 bool previousPagesAvailable() const;
102 bool nextPagesAvailable() const;
103
104 Status status() const;
105 void setStatus(Status status, const QString &errorString = QString());
106
107 Q_INVOKABLE void update();
108
109 Q_INVOKABLE void cancel();
110 Q_INVOKABLE void reset();
111
112 Q_INVOKABLE QString errorString() const;
113
114 Q_INVOKABLE void previousPage();
115 Q_INVOKABLE void nextPage();
116
117 virtual void clearData(bool suppressSignal = false);
118
119 // From QQmlParserStatus
120 virtual void classBegin();
121 virtual void componentComplete();
122
123Q_SIGNALS:
124 void pluginChanged();
125 void searchAreaChanged();
126 void limitChanged();
127 void previousPagesAvailableChanged();
128 void nextPagesAvailableChanged();
129 void statusChanged();
130
131protected:
132 virtual void initializePlugin(QDeclarativeGeoServiceProvider *plugin);
133
134protected Q_SLOTS:
135 virtual void queryFinished() = 0;
136 virtual void onContentUpdated();
137
138private Q_SLOTS:
139 void pluginNameChanged();
140
141protected:
142 virtual QPlaceReply *sendQuery(QPlaceManager *manager, const QPlaceSearchRequest &request) = 0;
143 void setPreviousPageRequest(const QPlaceSearchRequest &previous);
144 void setNextPageRequest(const QPlaceSearchRequest &next);
145
146 QPlaceSearchRequest m_request;
147 QDeclarativeGeoServiceProvider *m_plugin;
148 QPlaceReply *m_reply;
149
150private:
151 bool m_complete;
152 Status m_status;
153 QString m_errorString;
154 QPlaceSearchRequest m_previousPageRequest;
155 QPlaceSearchRequest m_nextPageRequest;
156};
157
158QT_END_NAMESPACE
159
160#endif // QDECLARATIVESEARCHMODELBASE_H
161

source code of qtlocation/src/location/declarativeplaces/qdeclarativesearchmodelbase_p.h