libosmscout 1.1.1
Loading...
Searching...
No Matches
NearPOIModel.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_CLIENT_QT_NEARPOIMODEL_H
2#define OSMSCOUT_CLIENT_QT_NEARPOIMODEL_H
3
4/*
5 OSMScout - a Qt backend for libosmscout and libosmscout-map
6 Copyright (C) 2018 Lukas Karas
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <osmscoutclient/POILookupModule.h>
24
26
28
29#include <QObject>
30#include <QAbstractListModel>
31
32#include <functional>
33#include <optional>
34
35namespace osmscout {
36
37#define INVALID_COORD -1000.0
38
42class OSMSCOUT_CLIENT_QT_API NearPOIModel: public QAbstractListModel
43{
44Q_OBJECT
48 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
49
50
53 Q_PROPERTY(bool searching READ isSearching NOTIFY SearchingChanged)
54
61 Q_PROPERTY(double lat READ GetLat WRITE SetLat)
62
66 Q_PROPERTY(double lon READ GetLon WRITE SetLon)
67
71 Q_PROPERTY(double maxDistance READ GetMaxDistance WRITE SetMaxDistance)
72
76 Q_PROPERTY(int resultLimit READ GetResultLimit WRITE SetResultLimit)
77
81 Q_PROPERTY(QStringList types READ GetTypes WRITE SetTypes)
82
83public:
84 enum Roles {
85 LabelRole = Qt::UserRole,
86 TypeRole = Qt::UserRole +1,
87 RegionRole = Qt::UserRole +2,
88 LatRole = Qt::UserRole +3,
89 LonRole = Qt::UserRole +4,
90 DistanceRole = Qt::UserRole +5,
91 BearingRole = Qt::UserRole +6,
92 LocationObjectRole = Qt::UserRole +7,
93 AltLangName = Qt::UserRole +8
94 };
95 Q_ENUM(Roles)
96
97signals:
98 void countChanged(int);
99
101
102 void lookupFinished(int requestId);
103 void lookupResult(int requestId, QList<LocationEntry> locations);
104
105public slots:
106 void onLookupFinished(int requestId);
107 void onLookupResult(int requestId, QList<LocationEntry> locations);
108
109private:
110 int currentRequest{0};
111 QList<LocationEntryRef> locations;
112 osmscout::GeoCoord searchCenter{INVALID_COORD,INVALID_COORD};
113 int resultLimit{100};
114 std::optional<POILookupModule::LookupFuture> future;
115 Distance maxDistance{Distance::Of<Kilometer>(1)};
116 QStringList types;
117
118 POILookupModule *poiModule{nullptr};
119 SettingsRef settings;
120
121 Slot<int> lookupFinishedSlot{ std::bind(&NearPOIModel::lookupFinished, this, std::placeholders::_1) };
122
123 Slot<int, POILookupModule::LookupResult> lookupResultSlot {
124 [this](int requestId, const POILookupModule::LookupResult &locationsVector) {
125 QList<LocationEntry> locations;
126 for (const auto &info: locationsVector) {
127 locations << LocationEntry(info);
128 }
129 emit lookupResult(requestId, locations);
130 }
131 };
132
133public:
135 ~NearPOIModel() override;
136
137 Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override;
138
139 Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const override;
140
141 Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const override;
142
143 Q_INVOKABLE QObject* get(int row) const;
144
145 QHash<int, QByteArray> roleNames() const override;
146
147 inline bool isSearching() const
148 {
149 return future.has_value();
150 }
151
152 inline double GetLat() const
153 {
154 return searchCenter.GetLat();
155 }
156
157 void SetLat(double lat)
158 {
159 if (lat!=searchCenter.GetLat()) {
160 searchCenter.Set(lat, searchCenter.GetLon());
161 lookupPOI();
162 }
163 }
164
165 inline double GetLon() const
166 {
167 return searchCenter.GetLon();
168 }
169
170 void SetLon(double lon)
171 {
172 if (lon!=searchCenter.GetLon()){
173 searchCenter.Set(searchCenter.GetLat(), lon);
174 lookupPOI();
175 }
176 }
177
178 inline double GetMaxDistance() const
179 {
180 return maxDistance.AsMeter();
181 }
182
183 void SetMaxDistance(double d)
184 {
185 if (maxDistance.AsMeter()!=d){
186 maxDistance=Distance::Of<Meter>(d);
187 lookupPOI();
188 }
189 }
190
191 inline int GetResultLimit() const
192 {
193 return resultLimit;
194 }
195
196 inline void SetResultLimit(int limit)
197 {
198 if (resultLimit!=limit){
199 resultLimit=limit;
200 lookupPOI();
201 }
202 }
203
204 inline QStringList GetTypes() const
205 {
206 return types;
207 }
208
209 inline void SetTypes(QStringList t)
210 {
211 if (types!=t){
212 types=t;
213 lookupPOI();
214 }
215 }
216
217private:
218 void lookupPOI();
219};
220
221}
222
223#endif //OSMSCOUT_CLIENT_QT_NEARPOIMODEL_H
#define OSMSCOUT_CLIENT_QT_API
Definition ClientQtImportExport.h:45
#define INVALID_COORD
Definition NearPOIModel.h:37
double maxDistance
Definition NearPOIModel.h:71
void SetLon(double lon)
Definition NearPOIModel.h:170
void onLookupResult(int requestId, QList< LocationEntry > locations)
void SetMaxDistance(double d)
Definition NearPOIModel.h:183
Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const override
void SearchingChanged(bool)
void onLookupFinished(int requestId)
Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override
double lat
Definition NearPOIModel.h:61
QStringList GetTypes() const
Definition NearPOIModel.h:204
int GetResultLimit() const
Definition NearPOIModel.h:191
Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const override
Q_INVOKABLE QObject * get(int row) const
void SetLat(double lat)
Definition NearPOIModel.h:157
QHash< int, QByteArray > roleNames() const override
bool isSearching() const
Definition NearPOIModel.h:147
double GetMaxDistance() const
Definition NearPOIModel.h:178
double GetLat() const
Definition NearPOIModel.h:152
double GetLon() const
Definition NearPOIModel.h:165
Roles
Definition NearPOIModel.h:84
@ TypeRole
Definition NearPOIModel.h:86
@ LocationObjectRole
Definition NearPOIModel.h:92
@ LonRole
Definition NearPOIModel.h:89
@ LatRole
Definition NearPOIModel.h:88
@ LabelRole
Definition NearPOIModel.h:85
@ DistanceRole
Definition NearPOIModel.h:90
@ AltLangName
Definition NearPOIModel.h:93
@ BearingRole
Definition NearPOIModel.h:91
@ RegionRole
Definition NearPOIModel.h:87
int resultLimit
Definition NearPOIModel.h:76
bool searching
Definition NearPOIModel.h:53
void lookupResult(int requestId, QList< LocationEntry > locations)
int count
Definition NearPOIModel.h:48
void SetResultLimit(int limit)
Definition NearPOIModel.h:196
void SetTypes(QStringList t)
Definition NearPOIModel.h:209
QStringList types
Definition NearPOIModel.h:81
void lookupFinished(int requestId)
double lon
Definition NearPOIModel.h:66
Definition Area.h:39