libosmscout  1.1.1
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 <osmscout/LocationEntry.h>
25 
27 
28 #include <QObject>
29 #include <QAbstractListModel>
30 
31 namespace osmscout {
32 
33 #define INVALID_COORD -1000.0
34 
38 class OSMSCOUT_CLIENT_QT_API NearPOIModel: public QAbstractListModel
39 {
40 Q_OBJECT
44  Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
45 
46 
49  Q_PROPERTY(bool searching READ isSearching NOTIFY SearchingChanged)
50 
57  Q_PROPERTY(double lat READ GetLat WRITE SetLat)
58 
62  Q_PROPERTY(double lon READ GetLon WRITE SetLon)
63 
67  Q_PROPERTY(double maxDistance READ GetMaxDistance WRITE SetMaxDistance)
68 
72  Q_PROPERTY(int resultLimit READ GetResultLimit WRITE SetResultLimit)
73 
77  Q_PROPERTY(QStringList types READ GetTypes WRITE SetTypes)
78 
79 public:
80  enum Roles {
81  LabelRole = Qt::UserRole,
82  TypeRole = Qt::UserRole +1,
83  RegionRole = Qt::UserRole +2,
84  LatRole = Qt::UserRole +3,
85  LonRole = Qt::UserRole +4,
86  DistanceRole = Qt::UserRole +5,
87  BearingRole = Qt::UserRole +6,
88  LocationObjectRole = Qt::UserRole +7
89  };
90  Q_ENUM(Roles)
91 
92 signals:
93  void countChanged(int);
94 
95  void SearchingChanged(bool);
96 
97  void lookupPOIRequest(int requestId,
98  osmscout::BreakerRef breaker,
99  osmscout::GeoCoord searchCenter,
100  QStringList types,
101  double maxDistance);
102 
103 public slots:
104  void onLookupFinished(int requestId);
105  void onLookupResult(int requestId, QList<LocationEntry> locations);
106 
107 private:
108  bool searching{false};
109  int currentRequest{0};
110  QList<LocationEntryRef> locations;
111  osmscout::GeoCoord searchCenter{INVALID_COORD,INVALID_COORD};
112  int resultLimit{100};
113  osmscout::BreakerRef breaker;
114  Distance maxDistance{Distance::Of<Kilometer>(1)};
115  QStringList types;
116 
117  POILookupModule *poiModule{nullptr};
118 
119 public:
120  NearPOIModel();
121  virtual ~NearPOIModel();
122 
123  Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role) const;
124 
125  Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
126 
127  Q_INVOKABLE virtual Qt::ItemFlags flags(const QModelIndex &index) const;
128 
129  Q_INVOKABLE QObject* get(int row) const;
130 
131  virtual QHash<int, QByteArray> roleNames() const;
132 
133  inline bool isSearching() const
134  {
135  return searching;
136  }
137 
138  inline double GetLat() const
139  {
140  return searchCenter.GetLat();
141  }
142 
143  void SetLat(double lat)
144  {
145  if (lat!=searchCenter.GetLat()) {
146  searchCenter.Set(lat, searchCenter.GetLon());
147  lookupPOI();
148  }
149  }
150 
151  inline double GetLon() const
152  {
153  return searchCenter.GetLon();
154  }
155 
156  void SetLon(double lon)
157  {
158  if (lon!=searchCenter.GetLon()){
159  searchCenter.Set(searchCenter.GetLat(), lon);
160  lookupPOI();
161  }
162  }
163 
164  inline double GetMaxDistance() const
165  {
166  return maxDistance.AsMeter();
167  }
168 
169  void SetMaxDistance(double d)
170  {
171  if (maxDistance.AsMeter()!=d){
172  maxDistance=Distance::Of<Meter>(d);
173  lookupPOI();
174  }
175  }
176 
177  inline int GetResultLimit() const
178  {
179  return resultLimit;
180  }
181 
182  inline void SetResultLimit(int limit)
183  {
184  if (resultLimit!=limit){
185  resultLimit=limit;
186  lookupPOI();
187  }
188  }
189 
190  inline QStringList GetTypes() const
191  {
192  return types;
193  }
194 
195  inline void SetTypes(QStringList t)
196  {
197  if (types!=t){
198  types=t;
199  lookupPOI();
200  }
201  }
202 
203 private:
204  void lookupPOI();
205 };
206 
207 }
208 
209 #endif //OSMSCOUT_CLIENT_QT_NEARPOIMODEL_H
double GetLon() const
Definition: NearPOIModel.h:151
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
std::shared_ptr< Breaker > BreakerRef
Definition: Breaker.h:65
void SetLat(double lat)
Definition: NearPOIModel.h:143
int GetResultLimit() const
Definition: NearPOIModel.h:177
QStringList GetTypes() const
Definition: NearPOIModel.h:190
Definition: Area.h:38
double GetLat() const
Definition: NearPOIModel.h:138
#define INVALID_COORD
Definition: NearPOIModel.h:33
void SetLon(double lon)
Definition: NearPOIModel.h:156
Definition: NearPOIModel.h:38
double GetMaxDistance() const
Definition: NearPOIModel.h:164
void SetResultLimit(int limit)
Definition: NearPOIModel.h:182
bool isSearching() const
Definition: NearPOIModel.h:133
void SetTypes(QStringList t)
Definition: NearPOIModel.h:195
Roles
Definition: NearPOIModel.h:80
void SetMaxDistance(double d)
Definition: NearPOIModel.h:169