-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathCollectionModel.h
197 lines (160 loc) · 6.81 KB
/
CollectionModel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
OSMScout for SFOS
Copyright (C) 2018 Lukas Karas
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#pragma once
#include "Storage.h"
#include <QObject>
#include <QtCore/QAbstractItemModel>
#include <QtCore/QSet>
#include <variant>
class CollectionModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged)
Q_PROPERTY(bool exporting READ isExporting NOTIFY exportingChanged)
Q_PROPERTY(bool collectionVisible READ isVisible NOTIFY loadingChanged)
Q_PROPERTY(QString collectionId READ getCollectionId WRITE setCollectionId)
Q_PROPERTY(QString name READ getCollectionName NOTIFY loadingChanged)
Q_PROPERTY(QString filesystemName READ getCollectionFilesystemName NOTIFY loadingChanged)
Q_PROPERTY(QString description READ getCollectionDescription NOTIFY loadingChanged)
// visibility
Q_PROPERTY(bool showTracks READ getShowTracks WRITE setShowTracks)
Q_PROPERTY(bool showWaypoints READ getShowWaypoints WRITE setShowWaypoints)
// ordering
Q_PROPERTY(bool waypointFirst READ getWaypointFirst WRITE setWaypointFirst NOTIFY orderingChanged)
Q_PROPERTY(Ordering ordering READ getOrdering WRITE setOrdering NOTIFY orderingChanged)
signals:
void loadingChanged();
void exportingChanged();
void collectionDetailRequest(Collection);
void deleteWaypointRequest(qint64 collectionId, qint64 id);
void deleteTrackRequest(qint64 collectionId, qint64 id);
void createWaypointRequest(qint64 collectionId, double lat, double lon, QString name, QString description, QString symbol);
void editWaypointRequest(qint64 collectionId, qint64 id, QString name, QString description, QString symbol);
void editTrackRequest(qint64 collectionId, qint64 id, QString name, QString description, QString type);
void exportCollectionRequest(qint64 collectionId, QString file, bool includeWaypoints, std::optional<double> accuracyFilter);
void exportTrackRequest(qint64 collectionId, qint64 trackId, QString file, bool includeWaypoints, std::optional<double> accuracyFilter);
void error(QString message);
void moveWaypointRequest(qint64 waypointId, qint64 collectionId);
void moveTrackRequest(qint64 trackId, qint64 collectionId);
void orderingChanged();
void exported(qint64 collectionId, QString file);
void trackExported(qint64 trackId, QString file);
void waypointVisibilityRequest(qint64 wptId, bool visible);
void trackVisibilityRequest(qint64 trackId, bool visible);
public slots:
void storageInitialised();
void storageInitialisationError(QString);
void onCollectionDetailsLoaded(Collection collection, bool ok);
void createWaypoint(double lat, double lon, QString name, QString description, QString symbol);
void deleteWaypoint(QString id);
void deleteTrack(QString id);
void editWaypoint(QString id, QString name, QString description, QString symbol);
void editTrack(QString id, QString name, QString description, QString type);
void exportToFile(QString fileName, QString directory, bool includeWaypoints, int accuracyFilter);
void exportTrackToFile(QString id, QString name, QString directory, bool includeWaypoints, int accuracyFilter);
void onCollectionExported(qint64 collectionId, QString file, bool);
void onTrackExported(qint64 trackId, QString file, bool success);
void moveWaypoint(QString waypointId, QString collectionId);
void moveTrack(QString trackId, QString collectionId);
void setWaypointVisibility(QString id, bool visible);
void setTrackVisibility(QString id, bool visible);
void setShowTracks(bool b);
void setShowWaypoints(bool b);
public:
CollectionModel();
~CollectionModel() override = default;
enum Ordering {
DateAscent = 0, // older first
DateDescent = 1, // newer first
NameAscent = 2, // A-Z
NameDescent = 3 // Z-A
};
Q_ENUM(Ordering)
enum Roles {
NameRole = Qt::UserRole,
FilesystemNameRole = Qt::UserRole+1,
DescriptionRole = Qt::UserRole+2,
TypeRole = Qt::UserRole+3,
IdRole = Qt::UserRole+4,
TimeRole = Qt::UserRole+5,
LastModificationRole = Qt::UserRole+6,
VisibleRole = Qt::UserRole+7,
ColorRole = Qt::UserRole+8,
// type == waypoint
SymbolRole = Qt::UserRole+9,
LatitudeRole = Qt::UserRole+10,
LongitudeRole = Qt::UserRole+11,
ElevationRole = Qt::UserRole+12,
WaypointTypeRole = Qt::UserRole+13,
LocationObjectRole = Qt::UserRole+14,
// type == track
DistanceRole = Qt::UserRole+15,
TrackTypeRole = Qt::UserRole+16,
};
Q_ENUM(Roles)
using Item = std::variant<Track, Waypoint>;
Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role) const;
virtual QHash<int, QByteArray> roleNames() const;
Q_INVOKABLE virtual Qt::ItemFlags flags(const QModelIndex &index) const;
QString getCollectionId() const
{
return QString::number(collection.id);
}
void setCollectionId(QString id);
bool isLoading() const;
QString getCollectionName() const;
QString getCollectionFilesystemName() const;
QString getCollectionDescription() const;
bool isVisible() const;
bool isExporting();
Q_INVOKABLE QStringList getExportSuggestedDirectories();
bool getWaypointFirst() const
{
return waypointFirst;
}
void setWaypointFirst(bool b);
inline Ordering getOrdering() const
{
return ordering;
}
void setOrdering(Ordering ordering);
static QString waypointType(const std::optional<std::string> &symbol, const QString &defaultType = "_waypoint");
static QString waypointColor(const std::optional<std::string> &symbol, const QString &defaultColor = "");
bool getShowTracks() const
{
return showTracks;
}
bool getShowWaypoints() const
{
return showWaypoints;
}
private:
/**
* Updates model entries without resetting whole model.
* Both vectors have to use the same sorting.
*/
void handleChanges(std::vector<Item> ¤t, const std::vector<Item> &newItems);
void sort(std::vector<Item> &items) const;
private:
Collection collection;
std::vector<Item> items;
bool collectionLoaded{false};
bool collectionExporting{false};
bool showTracks{true};
bool showWaypoints{true};
bool waypointFirst{true};
Ordering ordering{DateAscent};
};