libosmscout  1.1.1
MapObjectInfoModel.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_MAPOBJECTINFOMODEL_H
2 #define OSMSCOUT_CLIENT_QT_MAPOBJECTINFOMODEL_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 <osmscout/OverlayObject.h>
24 
25 #include <osmscout/GeoCoord.h>
26 #include <osmscout/util/GeoBox.h>
27 
28 #include <osmscout/DBThread.h>
29 #include <osmscout/LookupModule.h>
30 
33 
34 #include <QObject>
35 #include <QAbstractListModel>
36 #include <iostream>
37 
38 namespace osmscout {
39 
43 class OSMSCOUT_CLIENT_QT_API MapObjectInfoModel: public QAbstractListModel
44 {
45  Q_OBJECT
46  Q_PROPERTY(bool ready READ isReady NOTIFY readyChange)
47 
48 
49 public:
50  enum Roles {
51  LabelRole = Qt::UserRole,
52  TypeRole = Qt::UserRole+1,
53  IdRole = Qt::UserRole+2,
54  NameRole = Qt::UserRole+3,
55  ObjectRole = Qt::UserRole+4,
56  PhoneRole = Qt::UserRole+5,
57  WebsiteRole = Qt::UserRole+6,
58  AddressLocationRole = Qt::UserRole+7,
59  AddressNumberRole = Qt::UserRole+8,
60  PostalCodeRole = Qt::UserRole+9,
61  RegionRole = Qt::UserRole+10,
62  LatRole = Qt::UserRole+11,
63  LonRole = Qt::UserRole+12
64  };
65  Q_ENUM(Roles)
66 
67 signals:
68  void readyChange(bool ready);
69  void objectsOnViewRequested(const MapViewStruct &view, const QRectF &filterRectangle);
70  void objectsRequested(const LocationEntry &entry, bool reverseLookupAddresses);
71 
72 public slots:
73  void dbInitialized(const DatabaseLoadedResponse&);
74  void setPosition(QObject *mapView,
75  const int width, const int height,
76  const int screenX, const int screenY);
77 
78  void onViewObjectsLoaded(const MapViewStruct&,
79  const QList<LookupModule::ObjectInfo> &objects);
80 
81  void setLocationEntry(QObject *o);
82 
83  void onObjectsLoaded(const LocationEntry &entry,
84  const QList<LookupModule::ObjectInfo> &objects);
85 
86 private:
87  void addToModel(const QList<LookupModule::ObjectInfo> &objects);
88 
89 public:
91  virtual ~MapObjectInfoModel();
92 
93  Q_INVOKABLE virtual int inline rowCount(const QModelIndex &/*parent = QModelIndex()*/) const
94  {
95  return model.size();
96  };
97 
98  bool inline isReady() const
99  {
100  return ready;
101  };
102 
103  Q_INVOKABLE QObject* createOverlayObject(int row) const;
104 
105  Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role) const;
106  virtual QHash<int, QByteArray> roleNames() const;
107  Q_INVOKABLE virtual Qt::ItemFlags flags(const QModelIndex &index) const;
108 
109 private:
110  bool ready;
111  bool setup;
112  QList<ObjectKey> objectSet; // set of objects already inserted to model
113  QList<LookupModule::ObjectInfo> model;
114  MapViewStruct view;
115  QRectF filterRectangle;
116  LocationEntry locationEntry;
117 
118  QList<osmscout::MapData> mapData;
119  double mapDpi;
120  LookupModule* lookupModule;
121 };
122 
123 }
124 
125 #endif /* OSMSCOUT_CLIENT_QT_MAPOBJECTINFOMODEL_H */
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
virtual Q_INVOKABLE int rowCount(const QModelIndex &) const
Definition: MapObjectInfoModel.h:93
Definition: Area.h:38
Definition: DBThread.h:51
Definition: LocationEntry.h:42
Definition: MapObjectInfoModel.h:43
bool isReady() const
Definition: MapObjectInfoModel.h:98
Roles
Definition: MapObjectInfoModel.h:50
Definition: DBThread.h:74
Definition: LookupModule.h:48