libosmscout  1.1.1
LocationInfoModel.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_LOCATIONINFOMODEL_H
2 #define OSMSCOUT_CLIENT_QT_LOCATIONINFOMODEL_H
3 
4 /*
5  OSMScout - a Qt backend for libosmscout and libosmscout-map
6  Copyright (C) 2016 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 <QObject>
24 #include <QAbstractListModel>
25 
26 #include <osmscout/GeoCoord.h>
27 #include <osmscout/util/GeoBox.h>
28 
29 #include <osmscout/LookupModule.h>
30 
31 namespace osmscout {
32 
36 struct ObjectKey{
37  QString database;
38  osmscout::ObjectFileRef ref;
39 };
40 
44 class OSMSCOUT_CLIENT_QT_API LocationInfoModel : public QAbstractListModel
45 {
46  Q_OBJECT
47  Q_PROPERTY(bool ready READ isReady NOTIFY readyChange)
48 
49 signals:
50  void locationDescriptionRequested(const osmscout::GeoCoord location);
51  void readyChange(bool ready);
52  void regionLookupRequested(osmscout::GeoCoord);
53 
54 public slots:
55  void setLocation(const double lat, const double lon);
56  void dbInitialized(const DatabaseLoadedResponse&);
57  void onLocationDescription(const osmscout::GeoCoord location,
58  const QString database,
59  const osmscout::LocationDescription description,
60  const QStringList regions);
61  void onLocationDescriptionFinished(const osmscout::GeoCoord);
62 
63  void onLocationAdminRegions(const osmscout::GeoCoord,QList<AdminRegionInfoRef>);
64  void onLocationAdminRegionFinished(const osmscout::GeoCoord);
65 
66 public:
67  enum Roles {
68  LabelRole = Qt::UserRole,
69  RegionRole = Qt::UserRole+1,
70  AddressRole = Qt::UserRole+2,
71  InPlaceRole = Qt::UserRole+3,
72  DistanceRole = Qt::UserRole+4,
73  BearingRole = Qt::UserRole+5,
74  PoiRole = Qt::UserRole+6,
75  TypeRole = Qt::UserRole+7,
76  PostalCodeRole = Qt::UserRole+8,
77  WebsiteRole = Qt::UserRole+9,
78  PhoneRole = Qt::UserRole+10,
79  AddressLocationRole = Qt::UserRole+11,
80  AddressNumberRole = Qt::UserRole+12
81  };
82  Q_ENUM(Roles)
83 
84 public:
86  virtual ~LocationInfoModel();
87 
88  Q_INVOKABLE virtual int inline rowCount(const QModelIndex &/*parent = QModelIndex()*/) const
89  {
90  return model.size();
91  };
92 
93  Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role) const;
94  virtual QHash<int, QByteArray> roleNames() const;
95  Q_INVOKABLE virtual Qt::ItemFlags flags(const QModelIndex &index) const;
96 
97  bool inline isReady() const
98  {
99  return ready;
100  };
101 
102  Q_INVOKABLE double distance(double lat1, double lon1,
103  double lat2, double lon2);
104  Q_INVOKABLE QString bearing(double lat1, double lon1,
105  double lat2, double lon2);
106 
107  static bool distanceComparator(const QMap<int, QVariant> &obj1,
108  const QMap<int, QVariant> &obj2);
109 
110  static bool adminRegionComparator(const AdminRegionInfoRef& reg1,
111  const AdminRegionInfoRef& reg2);
112 private:
113  void addToModel(const QString database,
114  const osmscout::LocationAtPlaceDescriptionRef description,
115  const QStringList regions);
116 
117 private:
118  bool ready;
119  bool setup;
120  osmscout::GeoCoord location;
121 
122  QList<ObjectKey> objectSet; // set of objects already inserted to model
123  QList<QMap<int, QVariant>> model;
124  LookupModule* lookupModule;
125 
126 };
127 
128 }
129 
130 Q_DECLARE_METATYPE(osmscout::ObjectKey)
131 
132 #endif /* OSMSCOUT_CLIENT_QT_LOCATIONINFOMODEL_H */
bool isReady() const
Definition: LocationInfoModel.h:97
Definition: LocationInfoModel.h:36
std::shared_ptr< LocationAtPlaceDescription > LocationAtPlaceDescriptionRef
Definition: LocationDescriptionService.h:167
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
virtual Q_INVOKABLE int rowCount(const QModelIndex &) const
Definition: LocationInfoModel.h:88
Definition: Area.h:38
Definition: LocationInfoModel.h:44
osmscout::ObjectFileRef ref
Definition: LocationInfoModel.h:38
std::shared_ptr< AdminRegionInfo > AdminRegionInfoRef
Definition: LookupModule.h:43
Definition: DBThread.h:74
Definition: LookupModule.h:48
QString database
Definition: LocationInfoModel.h:37
Roles
Definition: LocationInfoModel.h:67