libosmscout 1.1.1
Loading...
Searching...
No Matches
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>
28
30
31namespace osmscout {
32
36struct ObjectKey{
37 QString database;
38 osmscout::ObjectFileRef ref;
39};
40
44class OSMSCOUT_CLIENT_QT_API LocationInfoModel : public QAbstractListModel
45{
46 Q_OBJECT
47 Q_PROPERTY(bool ready READ isReady NOTIFY readyChange)
48
49signals:
50 void locationDescriptionRequested(const osmscout::GeoCoord location);
51 void readyChange(bool ready);
52 void regionLookupRequested(osmscout::GeoCoord);
53
54public slots:
55 void setLocation(const double lat, const double lon);
56 void dbInitialized(const osmscout::GeoBox&);
57 void onLocationDescription(const osmscout::GeoCoord location,
58 const QString database,
59 const osmscout::LocationDescription description,
60 const QList<AdminRegionInfoRef> regions);
61 void onLocationDescriptionFinished(const osmscout::GeoCoord);
62
63 void onLocationAdminRegions(const osmscout::GeoCoord,QList<AdminRegionInfoRef>);
64 void onLocationAdminRegionFinished(const osmscout::GeoCoord);
65
66public:
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 IndexedAdminRegionRole = Qt::UserRole+13,
82 AltLangName = Qt::UserRole+14,
83 OpeningHours = Qt::UserRole+15
84 };
85 Q_ENUM(Roles)
86
87public:
90
91 Q_INVOKABLE int inline rowCount(const QModelIndex &parent = QModelIndex()) const override
92 {
93 Q_UNUSED(parent);
94 return model.size();
95 };
96
97 Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override;
98 QHash<int, QByteArray> roleNames() const override;
99 Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const override;
100
101 bool inline isReady() const
102 {
103 return ready;
104 };
105
106 Q_INVOKABLE double distance(double lat1, double lon1,
107 double lat2, double lon2);
108 Q_INVOKABLE QString bearing(double lat1, double lon1,
109 double lat2, double lon2);
110
111 static bool distanceComparator(const QMap<int, QVariant> &obj1,
112 const QMap<int, QVariant> &obj2);
113
114 static bool adminRegionComparator(const AdminRegionInfoRef& reg1,
115 const AdminRegionInfoRef& reg2);
116private:
117 void addToModel(const QString database,
119 const QList<AdminRegionInfoRef> regions);
120
121private:
122 bool ready;
123 bool setup;
124 osmscout::GeoCoord location;
125
126 QList<ObjectKey> objectSet; // set of objects already inserted to model
127 QList<QMap<int, QVariant>> model;
128 LookupModule* lookupModule;
129 SettingsRef settings;
130};
131
132}
133
134Q_DECLARE_METATYPE(osmscout::ObjectKey)
135
136#endif /* OSMSCOUT_CLIENT_QT_LOCATIONINFOMODEL_H */
#define OSMSCOUT_CLIENT_QT_API
Definition ClientQtImportExport.h:45
bool isReady() const
Definition LocationInfoModel.h:101
bool ready
Definition LocationInfoModel.h:47
QHash< int, QByteArray > roleNames() const override
void onLocationAdminRegions(const osmscout::GeoCoord, QList< AdminRegionInfoRef >)
Roles
Definition LocationInfoModel.h:67
@ DistanceRole
Definition LocationInfoModel.h:72
@ IndexedAdminRegionRole
Definition LocationInfoModel.h:81
@ WebsiteRole
Definition LocationInfoModel.h:77
@ PostalCodeRole
Definition LocationInfoModel.h:76
@ TypeRole
Definition LocationInfoModel.h:75
@ PoiRole
Definition LocationInfoModel.h:74
@ AddressNumberRole
Definition LocationInfoModel.h:80
@ LabelRole
Definition LocationInfoModel.h:68
@ OpeningHours
Definition LocationInfoModel.h:83
@ RegionRole
Definition LocationInfoModel.h:69
@ PhoneRole
Definition LocationInfoModel.h:78
@ AddressRole
Definition LocationInfoModel.h:70
@ BearingRole
Definition LocationInfoModel.h:73
@ AddressLocationRole
Definition LocationInfoModel.h:79
@ AltLangName
Definition LocationInfoModel.h:82
@ InPlaceRole
Definition LocationInfoModel.h:71
void regionLookupRequested(osmscout::GeoCoord)
void readyChange(bool ready)
static bool distanceComparator(const QMap< int, QVariant > &obj1, const QMap< int, QVariant > &obj2)
void onLocationDescriptionFinished(const osmscout::GeoCoord)
void setLocation(const double lat, const double lon)
Q_INVOKABLE QString bearing(double lat1, double lon1, double lat2, double lon2)
Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition LocationInfoModel.h:91
void onLocationDescription(const osmscout::GeoCoord location, const QString database, const osmscout::LocationDescription description, const QList< AdminRegionInfoRef > regions)
void onLocationAdminRegionFinished(const osmscout::GeoCoord)
void dbInitialized(const osmscout::GeoBox &)
Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const override
static bool adminRegionComparator(const AdminRegionInfoRef &reg1, const AdminRegionInfoRef &reg2)
Q_INVOKABLE double distance(double lat1, double lon1, double lat2, double lon2)
Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override
void locationDescriptionRequested(const osmscout::GeoCoord location)
Definition LookupModule.h:47
std::shared_ptr< LocationAtPlaceDescription > LocationAtPlaceDescriptionRef
Definition LocationDescriptionService.h:168
Definition Area.h:39
Definition LocationInfoModel.h:36
osmscout::ObjectFileRef ref
Definition LocationInfoModel.h:38
QString database
Definition LocationInfoModel.h:37