~ubuntu-branches/ubuntu/saucy/merkaartor/saucy

« back to all changes in this revision

Viewing changes to src/Preferences/MerkaartorPreferences.h

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2009-09-13 00:52:12 UTC
  • mto: (1.2.7 upstream) (0.1.3 upstream) (3.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090913005212-pjecal8zxm07x0fj
ImportĀ upstreamĀ versionĀ 0.14+svnfixes~20090912

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Interface: MerkaartorPreferences
 
3
//
 
4
// Description:
 
5
//
 
6
//
 
7
// Author: cbro <cbro@semperpax.com>, bvh, (C) 2008
 
8
//
 
9
// Copyright: See COPYING file that comes with this distribution
 
10
//
 
11
//
 
12
#ifndef MERKAARTORPREFERENCES_H
 
13
#define MERKAARTORPREFERENCES_H
 
14
 
 
15
#include <QtCore>
 
16
#include <QtCore/QSettings>
 
17
#include <QColor>
 
18
#include <QHttp>
 
19
#include <QBuffer>
 
20
#include <QUuid>
 
21
#include <QNetworkProxy>
 
22
 
 
23
#include "Maps/Coord.h"
 
24
#include "Preferences/WmsServersList.h"
 
25
#include "Preferences/TmsServersList.h"
 
26
#include "Preferences/ProjectionsList.h"
 
27
#include "Preferences/BookmarksList.h"
 
28
 
 
29
class MainWindow;
 
30
class MapView;
 
31
class IMapAdapter;
 
32
 
 
33
//#define WORLD_COORDBOX CoordBox(Coord(1.3, -1.3), Coord(-1.3, 1.3))
 
34
#define WORLD_COORDBOX CoordBox(Coord(INT_MAX/4, -INT_MAX/4), Coord(-INT_MAX/4, INT_MAX/4))
 
35
#define BUILTIN_STYLES_DIR ":/Styles"
 
36
#define BUILTIN_TEMPLATES_DIR ":/Templates"
 
37
#define M_PREFS MerkaartorPreferences::instance()
 
38
 
 
39
#define NONE_ADAPTER_UUID QUuid("{8F5D3625-F987-45c5-A50B-17D88384F97D}")
 
40
#define SHAPE_ADAPTER_UUID QUuid("{AFB0324E-34D0-4267-BB8A-CF56CD2D7012}")
 
41
#define WMS_ADAPTER_UUID QUuid("{E238750A-AC27-429e-995C-A60C17B9A1E0}")
 
42
#define TMS_ADAPTER_UUID QUuid("{CA8A07EC-A466-462b-929F-3805BC9DEC95}")
 
43
 
 
44
#define HOMEDIR QDir::homePath() + "/.merkaartor"
 
45
 
 
46
#define M_PARAM_DECLARE_BOOL(Param) \
 
47
        private: \
 
48
                bool m_##Param; \
 
49
        public: \
 
50
                void set##Param(bool theValue); \
 
51
                bool get##Param(); 
 
52
#define M_PARAM_DECLARE_STRING(Param) \
 
53
        private: \
 
54
                QString m_##Param; \
 
55
        public: \
 
56
                void set##Param(QString theValue); \
 
57
                QString get##Param(); 
 
58
#define M_PARAM_DECLARE_INT(Param) \
 
59
        private: \
 
60
                int m_##Param; \
 
61
        public: \
 
62
                void set##Param(int theValue); \
 
63
                int get##Param(); 
 
64
#define M_PARAM_DECLARE_DOUBLE(Param) \
 
65
        private: \
 
66
                double m_##Param; \
 
67
        public: \
 
68
                void set##Param(double theValue); \
 
69
                double get##Param(); 
 
70
 
 
71
#define SAFE_DELETE(x) {delete (x); x = NULL;}
 
72
#define STRINGIFY(x) XSTRINGIFY(x)
 
73
#define XSTRINGIFY(x) #x
 
74
 
 
75
/**
 
76
        @author cbro <cbro@semperpax.com>
 
77
*/
 
78
 
 
79
#ifndef _MOBILE
 
80
typedef QString ProjectionType;
 
81
#endif
 
82
 
 
83
enum ExportType {
 
84
        Export_All,
 
85
        Export_Viewport,
 
86
        Export_Selected
 
87
};
 
88
 
 
89
enum DirectionalArrowsShow {
 
90
        DirectionalArrows_Never,
 
91
        DirectionalArrows_Oneway,
 
92
        DirectionalArrows_Always
 
93
};
 
94
 
 
95
#define TOOL_FIELD_SIZE 2
 
96
class Tool
 
97
{
 
98
        public:
 
99
                Tool();
 
100
                Tool(QString Name, QString Path);
 
101
 
 
102
        public:
 
103
                QString ToolName;
 
104
                QString ToolPath;
 
105
};
 
106
typedef QMap<QString, Tool> ToolList;
 
107
typedef QMapIterator<QString, Tool> ToolListIterator;
 
108
 
 
109
 
 
110
// Outside of merkaartorpreferences, because initializing it will need translations
 
111
// Classic chicken & egg problem.
 
112
QString getDefaultLanguage();
 
113
void setDefaultLanguage(const QString& L);
 
114
 
 
115
class MerkaartorPreferences : public QObject
 
116
{
 
117
Q_OBJECT
 
118
public:
 
119
        MerkaartorPreferences();
 
120
        ~MerkaartorPreferences();
 
121
 
 
122
        static MerkaartorPreferences* instance() {
 
123
                if (!m_prefInstance) {
 
124
                        m_prefInstance = new MerkaartorPreferences;
 
125
                }
 
126
 
 
127
                return m_prefInstance;
 
128
        }
 
129
 
 
130
        void save(bool UserPwdChanged = false);
 
131
 
 
132
        void toOsmPref();
 
133
        void fromOsmPref();
 
134
        void putOsmPref(const QString& k, const QString& v);
 
135
        void deleteOsmPref(const QString& k);
 
136
 
 
137
        const QVector<qreal> getParentDashes() const;
 
138
 
 
139
        //bool use06Api() const;
 
140
        void setUse06Api(bool b);
 
141
        const QString apiVersion() const;
 
142
        double apiVersionNum() const;
 
143
 
 
144
        void setRightSideDriving(bool theValue);
 
145
        bool getRightSideDriving() const;
 
146
 
 
147
        void setDoubleRoadDistance(double theValue);
 
148
        double getDoubleRoadDistance() const;
 
149
 
 
150
        void setWorkingDir(const QString & theValue);
 
151
        QString getWorkingDir() const;
 
152
 
 
153
        BookmarkList*  getBookmarks();
 
154
 
 
155
        WmsServerList* getWmsServers();
 
156
        TmsServerList* getTmsServers();
 
157
        void setSelectedServer(const QString & theValue);
 
158
        QString getSelectedServer() const;
 
159
 
 
160
        void setBgVisible(bool theValue);
 
161
        bool getBgVisible() const;
 
162
 
 
163
        /* Tile Cache */
 
164
        void setCacheDir(const QString & theValue);
 
165
        QString getCacheDir() const;
 
166
        void setCacheSize(int theValue);
 
167
        int getCacheSize() const;
 
168
 
 
169
        /* Search */
 
170
        void setLastMaxSearchResults(int theValue);
 
171
        int getLastMaxSearchResults() const;
 
172
        void setLastSearchName(const QString & theValue);
 
173
        QString getLastSearchName() const;
 
174
        void setLastSearchKey(const QString & theValue);
 
175
        QString getLastSearchKey() const;
 
176
        void setLastSearchValue(const QString & theValue);
 
177
        QString getLastSearchValue() const;
 
178
 
 
179
        /* Visual */
 
180
        void setZoomInPerc(int theValue);
 
181
        int getZoomInPerc() const;
 
182
        void setZoomOutPerc(int theValue);
 
183
        int getZoomOutPerc() const;
 
184
 
 
185
        QStringList getAlphaList() const;
 
186
        void setAlphaList();
 
187
        qreal getAlpha(QString lvl);
 
188
        QHash<QString, qreal>* getAlphaPtr();
 
189
 
 
190
        QColor getBgColor() const;
 
191
        void setBgColor(const QColor theValue);
 
192
        QColor getWaterColor() const;
 
193
        void setWaterColor(const QColor theValue);
 
194
        QColor getFocusColor() const;
 
195
        int getFocusWidth() const;
 
196
        void setFocusColor(const QColor theValue, int width);
 
197
        QColor getHoverColor() const;
 
198
        int getHoverWidth() const;
 
199
        void setHoverColor(const QColor theValue, int width);
 
200
        QColor getHighlightColor() const;
 
201
        int getHighlightWidth() const;
 
202
        void setHighlightColor(const QColor theValue, int width);
 
203
        QColor getRelationsColor() const;
 
204
        int getRelationsWidth() const;
 
205
        void setRelationsColor(const QColor theValue, int width);
 
206
        QColor getGpxTrackColor() const;
 
207
        int getGpxTrackWidth() const;
 
208
        void setGpxTrackColor(const QColor theValue, int width);
 
209
 
 
210
        void setDownloadedVisible(bool theValue);
 
211
        bool getDownloadedVisible() const;
 
212
 
 
213
        void setScaleVisible(bool theValue);
 
214
        bool getScaleVisible() const;
 
215
 
 
216
        bool getStyleBackgroundVisible() const;
 
217
        void setStyleBackgroundVisible(bool theValue);
 
218
        bool getStyleForegroundVisible() const;
 
219
        void setStyleForegroundVisible(bool theValue);
 
220
        bool getStyleTouchupVisible() const;
 
221
        void setStyleTouchupVisible(bool theValue);
 
222
        void setNamesVisible(bool theValue);
 
223
        bool getNamesVisible() const;
 
224
 
 
225
        DirectionalArrowsShow getDirectionalArrowsVisible();
 
226
        void setDirectionalArrowsVisible(DirectionalArrowsShow theValue);
 
227
 
 
228
        void setTrackPointsVisible(bool theValue);
 
229
        bool getTrackPointsVisible() const;
 
230
 
 
231
        void setTrackSegmentsVisible(bool theValue);
 
232
        bool getTrackSegmentsVisible() const;
 
233
 
 
234
        void setRelationsVisible(bool theValue);
 
235
        bool getRelationsVisible() const;
 
236
 
 
237
    M_PARAM_DECLARE_INT(TagListFirstColumnWidth)
 
238
 
 
239
        /* MainWindow state */
 
240
        void saveMainWindowState(const class MainWindow * mainWindow);
 
241
        void restoreMainWindowState(class MainWindow * mainWindow) const;
 
242
 
 
243
        void setInitialPosition(MapView* vw);
 
244
        void initialPosition(MapView* vw);
 
245
 
 
246
        bool getDrawTileBoundary();
 
247
 
 
248
        /* Data */
 
249
        void setOsmWebsite(const QString & theValue);
 
250
        QString getOsmWebsite() const;
 
251
 
 
252
        M_PARAM_DECLARE_STRING(XapiWebSite)
 
253
        M_PARAM_DECLARE_BOOL(AutoHistoryCleanup)
 
254
 
 
255
        void setOsmUser(const QString & theValue);
 
256
        QString getOsmUser() const;
 
257
 
 
258
        void setOsmPassword(const QString & theValue);
 
259
        QString getOsmPassword() const;
 
260
 
 
261
        void setGpsPort(const QString & theValue);
 
262
        QString getGpsPort() const;
 
263
 
 
264
        M_PARAM_DECLARE_DOUBLE(MaxDistNodes)
 
265
 
 
266
        void setAutoSaveDoc(bool theValue);
 
267
        bool getAutoSaveDoc() const;
 
268
 
 
269
        void setAutoExtractTracks(bool theValue);
 
270
        bool getAutoExtractTracks() const;
 
271
 
 
272
        /* Export Type */
 
273
        void setExportType(ExportType theValue);
 
274
        ExportType getExportType() const;
 
275
 
 
276
        /* Tools */
 
277
        ToolList* getTools() const;
 
278
        Tool getTool(QString toolName) const;
 
279
 
 
280
        QStringList getShortcuts() const;
 
281
        void setShortcuts(const QStringList & theValue);
 
282
 
 
283
        /* Recent */
 
284
        void setRecentOpen(const QStringList & theValue);
 
285
        QStringList getRecentOpen() const;
 
286
        void addRecentOpen(const QString & theValue);
 
287
 
 
288
        void setRecentImport(const QStringList & theValue);
 
289
        QStringList getRecentImport() const;
 
290
        void addRecentImport(const QString & theValue);
 
291
 
 
292
        /* Styles */
 
293
        M_PARAM_DECLARE_STRING(DefaultStyle)
 
294
        M_PARAM_DECLARE_STRING(CustomStyle)
 
295
        M_PARAM_DECLARE_BOOL(DisableStyleForTracks)
 
296
 
 
297
        /* Visual */
 
298
        M_PARAM_DECLARE_BOOL(BackgroundOverwriteStyle)
 
299
        M_PARAM_DECLARE_INT(AreaOpacity)
 
300
        M_PARAM_DECLARE_BOOL(UseShapefileForBackground)
 
301
        M_PARAM_DECLARE_BOOL(DrawingHack)
 
302
        M_PARAM_DECLARE_BOOL(SimpleGpxTrack)
 
303
 
 
304
        /* Templates */
 
305
        M_PARAM_DECLARE_STRING(DefaultTemplate)
 
306
        M_PARAM_DECLARE_STRING(CustomTemplate)
 
307
 
 
308
        M_PARAM_DECLARE_BOOL(GpsSaveLog)
 
309
        M_PARAM_DECLARE_BOOL(GpsMapCenter)
 
310
        M_PARAM_DECLARE_STRING(GpsLogDir)
 
311
        M_PARAM_DECLARE_BOOL(GpsSyncTime)
 
312
 
 
313
        M_PARAM_DECLARE_BOOL(ResolveRelations)
 
314
        M_PARAM_DECLARE_BOOL(DeleteIncompleteRelations)
 
315
 
 
316
        M_PARAM_DECLARE_BOOL(TranslateTags)
 
317
 
 
318
        M_PARAM_DECLARE_BOOL(MapTooltip)
 
319
        M_PARAM_DECLARE_BOOL(InfoOnHover)
 
320
        M_PARAM_DECLARE_BOOL(ShowParents)
 
321
 
 
322
        /* World OSB manager */
 
323
        M_PARAM_DECLARE_DOUBLE(TileToRegionThreshold)
 
324
 
 
325
        M_PARAM_DECLARE_STRING(WorldOsbUri)
 
326
        M_PARAM_DECLARE_BOOL(WorldOsbAutoload)
 
327
        M_PARAM_DECLARE_BOOL(WorldOsbAutoshow)
 
328
 
 
329
        /* Mouse bevaviour */
 
330
        M_PARAM_DECLARE_BOOL(MouseSingleButton)
 
331
        M_PARAM_DECLARE_BOOL(SeparateMoveMode)
 
332
                
 
333
        /* Custom Style */
 
334
        M_PARAM_DECLARE_BOOL(MerkaartorStyle)
 
335
        M_PARAM_DECLARE_STRING(MerkaartorStyleString)
 
336
 
 
337
        /* Network */
 
338
        M_PARAM_DECLARE_BOOL(OfflineMode)
 
339
 
 
340
        /* Proxy */
 
341
        QNetworkProxy getProxy(const QUrl & requestUrl);
 
342
 
 
343
        M_PARAM_DECLARE_BOOL(ProxyUse)
 
344
        M_PARAM_DECLARE_STRING(ProxyHost)
 
345
        M_PARAM_DECLARE_INT(ProxyPort)
 
346
        M_PARAM_DECLARE_STRING(ProxyUser)
 
347
        M_PARAM_DECLARE_STRING(ProxyPassword)
 
348
 
 
349
        /* Track */
 
350
        M_PARAM_DECLARE_BOOL(ReadonlyTracksDefault)
 
351
 
 
352
        /* FeaturesDock */
 
353
        M_PARAM_DECLARE_BOOL(FeaturesWithin)
 
354
 
 
355
        /* Plugins */
 
356
        void addBackgroundPlugin(IMapAdapter* aPlugin);
 
357
        void setBackgroundPlugin(const QUuid& theValue);
 
358
        QUuid getBackgroundPlugin() const;
 
359
        IMapAdapter* getBackgroundPlugin(const QUuid& anAdapterUid);
 
360
        QMap<QUuid, IMapAdapter *> getBackgroundPlugins();
 
361
 
 
362
        /* Projections */
 
363
        void loadProjection(QString fn);
 
364
        void loadProjections();
 
365
        void saveProjections();
 
366
 
 
367
        /* WMSes */
 
368
        void loadWMS(QString fn);
 
369
        void loadWMSes();
 
370
        void saveWMSes();
 
371
 
 
372
        /* TMSes */
 
373
        void loadTMS(QString fn);
 
374
        void loadTMSes();
 
375
        void saveTMSes();
 
376
 
 
377
        /* Bookmarks */
 
378
        void loadBookmark(QString fn);
 
379
        void loadBookmarks();
 
380
        void saveBookmarks();
 
381
 
 
382
#ifndef _MOBILE
 
383
        void setProjectionType(ProjectionType theValue);
 
384
        ProjectionType getProjectionType() const;
 
385
        ProjectionsList getProjectionsList();
 
386
        ProjectionItem getProjection(QString aProj);
 
387
#endif
 
388
 
 
389
 
 
390
 
 
391
protected:
 
392
        QVector<qreal> parentDashes;
 
393
 
 
394
        bool Use06Api;
 
395
        QString version;
 
396
        bool RightSideDriving;
 
397
        double DoubleRoadDistance;
 
398
        QString WorkingDir;
 
399
        QString OsmWebsite;
 
400
        QString OsmUser;
 
401
        QString OsmPassword;
 
402
 
 
403
        QHttp httpRequest;
 
404
        int OsmPrefLoadId;
 
405
        int OsmPrefSaveId;
 
406
        int OsmPrefDeleteId;
 
407
        QBuffer OsmPrefContent;
 
408
        QMap<QString, int> OsmPrefListsCount;
 
409
 
 
410
        void setWmsServers();
 
411
        void setTmsServers();
 
412
        void setTools();
 
413
        void initialize();
 
414
 
 
415
private:
 
416
        QHash<QString, qreal> alpha;
 
417
        ToolList* theToolList;
 
418
        QSettings * Sets;
 
419
        QStringList projTypes;
 
420
        QMap<QUuid, IMapAdapter *> mBackgroundPlugins;
 
421
        ProjectionsList theProjectionsList;
 
422
        WmsServersList theWmsServerList;
 
423
        TmsServersList theTmsServerList;
 
424
        BookmarksList theBookmarkList;
 
425
 
 
426
        static MerkaartorPreferences* m_prefInstance;
 
427
 
 
428
private slots:
 
429
        void on_responseHeaderReceived(const QHttpResponseHeader & hdr);
 
430
        void on_requestFinished ( int id, bool error );
 
431
 
 
432
signals:
 
433
        void bookmarkChanged();
 
434
};
 
435
 
 
436
#endif