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 QDECLARATIVESEARCHRESULTMODEL_P_H
38#define QDECLARATIVESEARCHRESULTMODEL_P_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/qdeclarativesearchmodelbase_p.h>
53#include <QtLocation/private/qdeclarativecategory_p.h>
54#include <QtLocation/private/qdeclarativeplace_p.h>
55#include <QtLocation/private/qdeclarativeplaceicon_p.h>
56
57QT_BEGIN_NAMESPACE
58
59class QDeclarativeGeoServiceProvider;
60
61class Q_LOCATION_PRIVATE_EXPORT QDeclarativeSearchResultModel : public QDeclarativeSearchModelBase
62{
63 Q_OBJECT
64
65 Q_PROPERTY(QString searchTerm READ searchTerm WRITE setSearchTerm NOTIFY searchTermChanged)
66 Q_PROPERTY(QQmlListProperty<QDeclarativeCategory> categories READ categories NOTIFY categoriesChanged)
67 Q_PROPERTY(QString recommendationId READ recommendationId WRITE setRecommendationId NOTIFY recommendationIdChanged)
68 Q_PROPERTY(RelevanceHint relevanceHint READ relevanceHint WRITE setRelevanceHint NOTIFY relevanceHintChanged)
69 Q_PROPERTY(QDeclarativePlace::Visibility visibilityScope READ visibilityScope WRITE setVisibilityScope NOTIFY visibilityScopeChanged)
70
71 Q_PROPERTY(int count READ rowCount NOTIFY rowCountChanged)
72 Q_PROPERTY(QDeclarativeGeoServiceProvider *favoritesPlugin READ favoritesPlugin WRITE setFavoritesPlugin NOTIFY favoritesPluginChanged)
73 Q_PROPERTY(QVariantMap favoritesMatchParameters READ favoritesMatchParameters WRITE setFavoritesMatchParameters NOTIFY favoritesMatchParametersChanged)
74
75 Q_PROPERTY(bool incremental MEMBER m_incremental NOTIFY incrementalChanged REVISION 12)
76
77 Q_ENUMS(SearchResultType RelevanceHint)
78
79public:
80 enum SearchResultType {
81 UnknownSearchResult = QPlaceSearchResult::UnknownSearchResult,
82 PlaceResult = QPlaceSearchResult::PlaceResult,
83 ProposedSearchResult = QPlaceSearchResult::ProposedSearchResult
84 };
85
86 enum RelevanceHint {
87 UnspecifiedHint = QPlaceSearchRequest::UnspecifiedHint,
88 DistanceHint = QPlaceSearchRequest::DistanceHint,
89 LexicalPlaceNameHint = QPlaceSearchRequest::LexicalPlaceNameHint
90 };
91
92 explicit QDeclarativeSearchResultModel(QObject *parent = 0);
93 ~QDeclarativeSearchResultModel();
94
95 QString searchTerm() const;
96 void setSearchTerm(const QString &searchTerm);
97
98 QQmlListProperty<QDeclarativeCategory> categories();
99 static void categories_append(QQmlListProperty<QDeclarativeCategory> *list,
100 QDeclarativeCategory *category);
101 static int categories_count(QQmlListProperty<QDeclarativeCategory> *list);
102 static QDeclarativeCategory *category_at(QQmlListProperty<QDeclarativeCategory> *list, int index);
103 static void categories_clear(QQmlListProperty<QDeclarativeCategory> *list);
104
105 QString recommendationId() const;
106 void setRecommendationId(const QString &recommendationId);
107
108 QDeclarativeSearchResultModel::RelevanceHint relevanceHint() const;
109 void setRelevanceHint(QDeclarativeSearchResultModel::RelevanceHint hint);
110
111 QDeclarativePlace::Visibility visibilityScope() const;
112 void setVisibilityScope(QDeclarativePlace::Visibility visibilityScope);
113
114 QDeclarativeGeoServiceProvider *favoritesPlugin() const;
115 void setFavoritesPlugin(QDeclarativeGeoServiceProvider *plugin);
116
117 QVariantMap favoritesMatchParameters() const;
118 void setFavoritesMatchParameters(const QVariantMap &parameters);
119
120 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
121
122 virtual void clearData(bool suppressSignal = false) override;
123 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
124 Q_INVOKABLE QVariant data(int index, const QString &roleName) const;
125 QHash<int, QByteArray> roleNames() const override;
126
127 Q_INVOKABLE void updateWith(int proposedSearchIndex);
128
129 void updateSearchRequest();
130
131Q_SIGNALS:
132 void searchTermChanged();
133 void categoriesChanged();
134 void recommendationIdChanged();
135 void relevanceHintChanged();
136 void visibilityScopeChanged();
137
138 void rowCountChanged();
139 void favoritesPluginChanged();
140 void favoritesMatchParametersChanged();
141 void dataChanged();
142 void incrementalChanged();
143
144protected:
145 QPlaceReply *sendQuery(QPlaceManager *manager, const QPlaceSearchRequest &request) override;
146 virtual void initializePlugin(QDeclarativeGeoServiceProvider *plugin) override;
147
148protected Q_SLOTS:
149 virtual void queryFinished() override;
150 virtual void onContentUpdated() override;
151
152private Q_SLOTS:
153 void updateLayout(const QList<QPlace> &favoritePlaces = QList<QPlace>());
154
155 void placeUpdated(const QString &placeId);
156 void placeRemoved(const QString &placeId);
157
158private:
159 enum Roles {
160 SearchResultTypeRole = Qt::UserRole,
161 TitleRole,
162 IconRole,
163 DistanceRole,
164 PlaceRole,
165 SponsoredRole
166 };
167
168 int getRow(const QString &placeId) const;
169 QList<QPlaceSearchResult> resultsFromPages() const;
170 void removePageRow(int row);
171
172 QList<QDeclarativeCategory *> m_categories;
173 QLocation::VisibilityScope m_visibilityScope;
174
175 QMap<int, QList<QPlaceSearchResult>> m_pages;
176 QList<QPlaceSearchResult> m_results;
177 QList<QPlaceSearchResult> m_resultsBuffer;
178 QList<QDeclarativePlace *> m_places;
179 QList<QDeclarativePlaceIcon *> m_icons;
180
181 QDeclarativeGeoServiceProvider *m_favoritesPlugin;
182 QVariantMap m_matchParameters;
183 bool m_incremental = false;
184};
185
186QT_END_NAMESPACE
187
188#endif // QDECLARATIVESEARCHRESULTMODEL_P_H
189

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