1 //
2 // C++ Implementation: Global
3 //
4 // Description:
5 //
6 //
7 // Author: cbro <cbro@semperpax.com>, (C) 2010
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #include "Global.h"
14 #include "MainWindow.h"
15 #include "SlippyMapWidget.h"
16
17 #ifdef PORTABLE_BUILD
18 bool g_Merk_Portable = true;
19 #else
20 bool g_Merk_Portable = false;
21 #endif
22 bool g_Merk_Frisius = true;
23 bool g_Merk_NoGuardedTagsImport = false;
24 bool g_Merk_Segment_Mode = false;
25 bool g_Merk_Ignore_Preferences = false;
26 bool g_Merk_Reset_Preferences = false;
27 bool g_Merk_IgnoreStartupTemplate = false;
28 #if QT_VERSION < 0x040700 || defined(FORCE_46)
29 bool g_Merk_SelfClip = true;
30 #else
31 bool g_Merk_SelfClip = false;
32 #endif
33
34 MainWindow* g_Merk_MainWindow = NULL;
35 MemoryBackend g_backend;
36 SlippyMapCache* SlippyMapWidget::theSlippyCache = 0;
37
38 QStringList tagKeys;
39 QHash<QString, quint32> tagKeysHash;
40 QStringList tagValues;
41 QHash<QString, quint32> tagValuesHash;
42 QHash< quint32, QList<quint32> > tagList;
43 QStringList userList;
44 QString noUser;
45
g_addToTagList(QString k,QString v)46 QPair<quint32, quint32> g_addToTagList(QString k, QString v)
47 {
48 qint32 ik, iv;
49
50 if (!tagKeysHash.contains(k)) {
51 tagKeys.append(k);
52 ik = tagKeys.size()-1;
53 tagKeysHash[k] = ik;
54 } else
55 ik = tagKeysHash.value(k);
56
57 if (!tagValuesHash.contains(v)) {
58 tagValues.append(v);
59 iv = tagValues.size()-1;
60 tagValuesHash[v] = iv;
61 } else
62 iv = tagValuesHash.value(v);
63
64 if (!k.isEmpty() && !v.isEmpty())
65 tagList[ik].append(iv);
66
67 return qMakePair((quint32)ik, (quint32)iv);
68 }
69
g_removeFromTagList(quint32 k,quint32 v)70 void g_removeFromTagList(quint32 k, quint32 v)
71 {
72 tagList[k].removeOne(v);
73 if (tagList[k].isEmpty())
74 tagList.remove(k);
75 }
76
g_getTagKeys()77 QStringList g_getTagKeys()
78 {
79 return tagKeys;
80 }
81
g_getTagValues()82 QStringList g_getTagValues()
83 {
84 return tagValues;
85 }
86
g_getTagValueList(QString k)87 QStringList g_getTagValueList(QString k)
88 {
89 QSet<quint32> retList;
90 if (k == "*") {
91 foreach (QList<quint32> list, tagList)
92 retList.unite(list.toSet());
93 } else
94 retList = tagList[tagKeys.indexOf(k)].toSet();
95
96 QStringList res;
97 foreach (quint32 i, retList)
98 res << g_getTagValue(i);
99
100 return res;
101 }
102
g_getTagKey(int idx)103 const QString& g_getTagKey(int idx)
104 {
105 return tagKeys.at(idx);
106 }
107
g_getTagKeyIndex(const QString & s)108 quint32 g_getTagKeyIndex(const QString& s)
109 {
110 return tagKeys.indexOf(s);
111 }
112
g_getTagKeyList()113 QStringList g_getTagKeyList()
114 {
115 return tagKeys.toSet().toList();
116 }
117
g_getTagValue(int idx)118 QString g_getTagValue(int idx)
119 {
120 return tagValues.at(idx);
121 }
122
g_getTagValueIndex(const QString & s)123 quint32 g_getTagValueIndex(const QString& s)
124 {
125 return tagValues.indexOf(s);
126 }
127
g_setUser(const QString & u)128 quint32 g_setUser(const QString& u)
129 {
130 if (u.isEmpty())
131 return 0xffffffff;
132
133 qint32 ret = userList.indexOf(u);
134 if (ret == -1) {
135 userList.append(u);
136 return userList.size()-1;
137 }
138 return ret;
139 }
140
g_getUser(quint32 idx)141 const QString& g_getUser(quint32 idx)
142 {
143 if (idx != 0xffffffff)
144 return userList[idx];
145 else
146 return noUser;
147 }
148