forked from GPSBabel/gpsbabel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat.h
343 lines (296 loc) · 6.65 KB
/
format.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
// -*- C++ -*-
// $Id: format.h,v 1.6 2010-02-15 02:57:00 robertl Exp $
//------------------------------------------------------------------------
//
// Copyright (C) 2009 S. Khai Mong <[email protected]>.
//
// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
//
//------------------------------------------------------------------------
#ifndef FORMAT_H
#define FORMAT_H
#include <QList> // for QList
#include <QSettings> // for QSettings
#include <QString> // for QString
#include <QStringList> // for QStringList
#include <QVariant> // for QVariant
class FormatOption
{
public:
/* Types */
enum optionType {
OPTstring,
OPTbool,
OPTint,
OPTboundedInt,
OPTfloat,
OPTinFile,
OPToutFile,
};
/* Special Member Functions */
FormatOption() = default;
FormatOption(const QString& name,
const QString& description,
optionType type,
const QVariant& defaultValue = QVariant(),
const QVariant& minValue = QVariant(),
const QVariant& maxValue = QVariant(),
const QString& html = QString()
):
name_(name),
description_(description),
type_(type),
defaultValue_(defaultValue),
minValue_(minValue),
maxValue_(maxValue),
html_(html)
{
// Boolean values pay more attention to 'selected' than value. Make
// them match here. For non-bools, just make them unchecked.
if ((type_ == OPTbool) && defaultValue_.toBool()) {
isSelected_ = true;
} else {
isSelected_ = false;
}
}
/* Member Functions */
QString getName() const
{
return name_;
}
QString getDescription() const
{
return description_;
}
optionType getType() const
{
return type_;
}
QVariant getValue() const
{
return value_;
}
bool getSelected() const
{
return isSelected_;
}
QVariant getMinValue() const
{
return minValue_;
}
QVariant getMaxValue() const
{
return maxValue_;
}
QVariant getDefaultValue() const
{
return defaultValue_;
}
void setValue(const QVariant& v)
{
value_ = v;
}
void setSelected(bool v)
{
isSelected_ = v;
}
QString getHtml() const
{
return html_;
}
private:
/* Data Members */
QString name_;
QString description_;
optionType type_{OPTbool};
QVariant defaultValue_;
QVariant minValue_;
QVariant maxValue_;
QString html_;
QVariant value_;
bool isSelected_{false};
};
//------------------------------------------------------------------------
class Format
{
public:
/* Special Member Functions */
Format() = default;
Format(const QString& name,
const QString& description,
bool readWaypoints,
bool readTracks,
bool readRoutes,
bool writeWaypoints,
bool writeTracks,
bool writeRoutes,
bool fileFormat,
bool deviceFormat,
const QStringList& extensions,
QList<FormatOption>& inputOptions,
QList<FormatOption>& outputOptions,
const QString& html):
name_(name),
description_(description),
readWaypoints_(readWaypoints),
readTracks_(readTracks),
readRoutes_(readRoutes),
writeWaypoints_(writeWaypoints),
writeTracks_(writeTracks),
writeRoutes_(writeRoutes),
fileFormat_(fileFormat),
deviceFormat_(deviceFormat),
extensions_(extensions),
inputOptions_(inputOptions),
outputOptions_(outputOptions)
{
(void)html; // suppress 'unused' warning.
}
/* Member Functions */
bool isReadWaypoints() const
{
return readWaypoints_;
}
bool isReadTracks() const
{
return readTracks_;
}
bool isReadRoutes() const
{
return readRoutes_;
}
bool isReadSomething() const
{
return isReadWaypoints() || isReadTracks() || isReadRoutes();
}
bool isWriteWaypoints() const
{
return writeWaypoints_;
}
bool isWriteTracks() const
{
return writeTracks_;
}
bool isWriteRoutes() const
{
return writeRoutes_;
}
bool isWriteSomething() const
{
return isWriteWaypoints() || isWriteTracks() || isWriteRoutes();
}
QString getName() const
{
return name_;
}
QString getDescription() const
{
return description_;
}
QString getHtml() const
{
return html_;
}
QStringList getExtensions() const
{
return extensions_;
}
const QList<FormatOption>& getInputOptions() const
{
return inputOptions_;
}
const QList<FormatOption>& getOutputOptions() const
{
return outputOptions_;
}
QList<FormatOption>* getInputOptionsRef()
{
return &inputOptions_;
}
QList<FormatOption>* getOutputOptionsRef()
{
return &outputOptions_;
}
bool isDeviceFormat() const
{
return deviceFormat_;
}
bool isFileFormat() const
{
return fileFormat_;
}
bool isHidden() const
{
return hidden_;
}
void setHidden(bool state)
{
hidden_ = state;
}
void saveSettings(QSettings& settings);
void restoreSettings(QSettings& settings);
void setToDefault();
static QString getHtmlBase()
{
return htmlBase_;
}
static void setHtmlBase(const QString& s)
{
htmlBase_ = s;
}
void bumpReadUseCount(int v)
{
readUseCount_ += v;
}
void bumpWriteUseCount(int v)
{
writeUseCount_ += v;
}
int getReadUseCount() const
{
return readUseCount_;
}
int getWriteUseCount() const
{
return writeUseCount_;
}
void zeroUseCounts()
{
readUseCount_ = 0;
writeUseCount_ = 0;
}
private:
/* Data Members */
QString name_;
QString description_;
bool readWaypoints_{false};
bool readTracks_{false};
bool readRoutes_{false};
bool writeWaypoints_{false};
bool writeTracks_{false};
bool writeRoutes_{false};
bool fileFormat_{false};
bool deviceFormat_{false};
bool hidden_{false};
QStringList extensions_;
QList<FormatOption>inputOptions_;
QList<FormatOption>outputOptions_;
QString html_;
static QString htmlBase_;
int readUseCount_{0};
int writeUseCount_{0};
};
#endif