Mon, 30 Jan 2017 02:33:17 +0200
Removed the status bar, since it's not used for anything
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1072 | 3 | * Copyright (C) 2013 - 2017 Teemu Piippo |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
946 | 19 | #include <QFile> |
998 | 20 | #include <QMessageBox> |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include "main.h" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include "colors.h" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "ldDocument.h" |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "miscallenous.h" |
962
a4b463a7ee82
Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
25 | #include "mainwindow.h" |
998 | 26 | #include "documentmanager.h" |
1012 | 27 | #include "ldpaths.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
998 | 29 | static ColorData* colorData = nullptr; |
946 | 30 | |
1044 | 31 | /* |
32 | * initColors | |
33 | * | |
34 | * Initializes the color information module. | |
35 | */ | |
998 | 36 | void initColors() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | { |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | print ("Initializing color information.\n"); |
998 | 39 | static ColorData colors; |
40 | colorData = &colors; | |
946 | 41 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | |
1044 | 43 | /* |
44 | * LDColor :: LDColor | |
45 | * | |
46 | * Default-constructs an LDColor to 0 (black). | |
47 | */ | |
48 | LDColor::LDColor() : | |
49 | m_index (0) {} | |
50 | ||
51 | /* | |
52 | * LDColor :: LDColor | |
53 | * | |
54 | * Constructs an LDColor by index. | |
55 | */ | |
56 | LDColor::LDColor (qint32 index) | |
57 | : m_index (index) {} | |
58 | ||
59 | /* | |
60 | * LDColor :: isValid | |
61 | * | |
62 | * Returns whether or not the color is valid. | |
63 | */ | |
946 | 64 | bool LDColor::isValid() const |
65 | { | |
998 | 66 | if (isLDConfigColor() and data().name.isEmpty()) |
946 | 67 | return false; // Unknown LDConfig color |
1044 | 68 | else |
69 | return m_index != -1; | |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
70 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
1044 | 72 | /* |
73 | * LDColor :: isLDConfigColor | |
74 | * | |
75 | * Returns whether or not this color is defined in LDConfig.ldr. | |
76 | * This is false for e.g. direct colors. | |
77 | */ | |
946 | 78 | bool LDColor::isLDConfigColor() const |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
79 | { |
1044 | 80 | return colorData->contains(index()); |
998 | 81 | } |
82 | ||
1044 | 83 | /* |
84 | * LDColor :: data | |
85 | * | |
86 | * Returns the ColorData entry for this color. | |
87 | */ | |
998 | 88 | const ColorData::Entry& LDColor::data() const |
89 | { | |
1044 | 90 | return colorData->get(index()); |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
91 | } |
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
92 | |
1044 | 93 | /* |
94 | * LDColor :: name | |
95 | * | |
96 | * Returns the name of this color. | |
97 | */ | |
946 | 98 | QString LDColor::name() const |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
99 | { |
946 | 100 | if (isDirect()) |
101 | return "0x" + QString::number (index(), 16).toUpper(); | |
102 | else if (isLDConfigColor()) | |
998 | 103 | return data().name; |
946 | 104 | else if (index() == -1) |
105 | return "null color"; | |
106 | else | |
1044 | 107 | return "unknown"; |
946 | 108 | } |
109 | ||
1044 | 110 | /* |
111 | * LDColor :: hexcode | |
112 | * | |
113 | * Returns the hexadecimal code of this color. | |
114 | */ | |
946 | 115 | QString LDColor::hexcode() const |
116 | { | |
117 | return faceColor().name(); | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | |
1044 | 120 | /* |
121 | * LDColor :: faceColor | |
122 | * | |
123 | * Returns the color used for surfaces. | |
124 | */ | |
946 | 125 | QColor LDColor::faceColor() const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | { |
946 | 127 | if (isDirect()) |
128 | { | |
1044 | 129 | // Direct color -- compute from the index. |
946 | 130 | QColor color; |
1044 | 131 | color.setRed((index() & 0x0FF0000) >> 16); |
132 | color.setGreen((index() & 0x000FF00) >> 8); | |
133 | color.setBlue(index() & 0x00000FF); | |
946 | 134 | |
135 | if (index() >= 0x3000000) | |
1044 | 136 | color.setAlpha(128); |
946 | 137 | |
138 | return color; | |
139 | } | |
140 | else if (isLDConfigColor()) | |
141 | { | |
998 | 142 | return data().faceColor; |
946 | 143 | } |
144 | else | |
145 | { | |
146 | return Qt::black; | |
147 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | |
1044 | 150 | /* |
151 | * LDColor :: edgeColor | |
152 | * | |
153 | * Returns the color used for edge lines. | |
154 | */ | |
946 | 155 | QColor LDColor::edgeColor() const |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | { |
946 | 157 | if (isDirect()) |
1044 | 158 | return luma(faceColor()) < 48 ? Qt::white : Qt::black; |
946 | 159 | else if (isLDConfigColor()) |
998 | 160 | return data().edgeColor; |
946 | 161 | else |
162 | return Qt::black; | |
163 | } | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | |
1044 | 165 | /* |
166 | * LDColor :: index | |
167 | * | |
168 | * Returns the index number of this color. | |
169 | */ | |
946 | 170 | qint32 LDColor::index() const |
171 | { | |
172 | return m_index; | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | |
1044 | 175 | /* |
176 | * LDColor :: indexString | |
177 | * | |
178 | * Returns a string containing the preferred representation of the index. | |
179 | */ | |
806
4240f47aa2d4
- moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
797
diff
changeset
|
180 | QString LDColor::indexString() const |
4240f47aa2d4
- moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
797
diff
changeset
|
181 | { |
4240f47aa2d4
- moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
797
diff
changeset
|
182 | if (isDirect()) |
1044 | 183 | { |
184 | // Use hexadecimal notation for direct colors. | |
185 | return "0x" + QString::number(index(), 16).toUpper(); | |
186 | } | |
187 | else | |
188 | { | |
189 | return QString::number(index()); | |
190 | } | |
806
4240f47aa2d4
- moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
797
diff
changeset
|
191 | } |
4240f47aa2d4
- moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
797
diff
changeset
|
192 | |
1044 | 193 | /* |
194 | * LDColor :: isDirect | |
195 | * | |
196 | * Returns whether or not this color is a direct color. | |
197 | * Direct colors are picked by RGB value and are not defined in LDConfig.ldr. | |
198 | */ | |
806
4240f47aa2d4
- moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
797
diff
changeset
|
199 | bool LDColor::isDirect() const |
4240f47aa2d4
- moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
797
diff
changeset
|
200 | { |
4240f47aa2d4
- moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
797
diff
changeset
|
201 | return index() >= 0x02000000; |
4240f47aa2d4
- moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
797
diff
changeset
|
202 | } |
4240f47aa2d4
- moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
797
diff
changeset
|
203 | |
1044 | 204 | /* |
205 | * LDColor :: nullColor | |
206 | * | |
207 | * Returns a color that is guaranteed to be invalid. | |
208 | */ | |
209 | LDColor LDColor::nullColor() | |
210 | { | |
211 | return LDColor {-1}; | |
212 | } | |
213 | ||
214 | /* | |
215 | * qHash | |
216 | * | |
217 | * LDColors are hashed by their index. | |
218 | */ | |
1031
55c0d3beea0d
removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
219 | uint qHash(LDColor color) |
55c0d3beea0d
removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
220 | { |
55c0d3beea0d
removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
221 | return color.index(); |
55c0d3beea0d
removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
222 | } |
55c0d3beea0d
removed removeDuplicates in favor of QSet, and the unused ObjectList class
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
223 | |
1044 | 224 | /* |
225 | * luma | |
226 | * | |
227 | * Calculates the luma-value for the given color. | |
228 | * c.f. https://en.wikipedia.org/wiki/Luma_(video) | |
229 | */ | |
230 | int luma (const QColor& color) | |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
231 | { |
1044 | 232 | return round((0.2126 * color.red()) + (0.7152 * color.green()) + (0.0722 * color.blue())); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | } |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
234 | |
1044 | 235 | /* |
236 | * ColorData :: ColorData | |
237 | * | |
238 | * Constructs the color data array. | |
239 | */ | |
998 | 240 | ColorData::ColorData() |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
241 | { |
998 | 242 | if (colorData == nullptr) |
243 | colorData = this; | |
244 | ||
245 | // Initialize main and edge colors, they're special like that. | |
1044 | 246 | m_data[MainColor].faceColor = "#AAAAAA"; |
998 | 247 | m_data[MainColor].edgeColor = Qt::black; |
248 | m_data[MainColor].name = "Main color"; | |
249 | m_data[EdgeColor].faceColor = | |
1044 | 250 | m_data[EdgeColor].edgeColor = "#000000"; |
998 | 251 | m_data[EdgeColor].name = "Edge color"; |
1044 | 252 | |
253 | // Load the rest from LDConfig.ldr. | |
998 | 254 | loadFromLdconfig(); |
255 | } | |
256 | ||
1044 | 257 | /* |
258 | * ColorData :: ~ColorData | |
259 | * | |
260 | * Cleanup the colorData pointer after the array is deleted. | |
261 | */ | |
998 | 262 | ColorData::~ColorData() |
263 | { | |
264 | if (colorData == this) | |
265 | colorData = nullptr; | |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
266 | } |
946 | 267 | |
1044 | 268 | /* |
269 | * ColorData :: contains | |
270 | * | |
271 | * Returns whether or not the given color index is present in the array. | |
272 | */ | |
273 | bool ColorData::contains(int code) const | |
946 | 274 | { |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
275 | return code >= 0 and code < countof(m_data); |
998 | 276 | } |
277 | ||
1044 | 278 | /* |
279 | * ColorData :: get | |
280 | * | |
281 | * Returns an entry in the color array. | |
282 | */ | |
283 | const ColorData::Entry& ColorData::get(int code) const | |
998 | 284 | { |
1044 | 285 | if (not contains(code)) |
286 | throw std::runtime_error {"Attempted to get non-existant color information"}; | |
946 | 287 | |
998 | 288 | return m_data[code]; |
289 | } | |
290 | ||
1044 | 291 | /* |
292 | * ColorData :: loadFromLdconfig | |
293 | * | |
294 | * Loads color information from LDConfig.ldr. | |
295 | */ | |
998 | 296 | void ColorData::loadFromLdconfig() |
297 | { | |
1012 | 298 | QString path = LDPaths::ldConfigPath(); |
1044 | 299 | QFile file {path}; |
998 | 300 | |
1044 | 301 | if (not file.open (QIODevice::ReadOnly)) |
946 | 302 | { |
1044 | 303 | QMessageBox::critical(nullptr, "Error", "Unable to open LDConfig.ldr for parsing: " + file.errorString()); |
946 | 304 | return; |
305 | } | |
306 | ||
998 | 307 | // TODO: maybe LDConfig can be loaded as a Document? Or would that be overkill? |
1044 | 308 | while (not file.atEnd()) |
946 | 309 | { |
1044 | 310 | QString line = QString::fromUtf8 (file.readLine()); |
946 | 311 | |
312 | if (line.isEmpty() or line[0] != '0') | |
313 | continue; // empty or illogical | |
314 | ||
1044 | 315 | line.remove('\r'); |
316 | line.remove('\n'); | |
946 | 317 | |
318 | // Parse the line | |
1044 | 319 | LDConfigParser parser = {line}; |
998 | 320 | QString name; |
321 | QString facename; | |
322 | QString edgename; | |
323 | QString codestring; | |
946 | 324 | |
325 | // Check 0 !COLOUR, parse the name | |
1044 | 326 | if (not parser.compareToken(0, "0") or not parser.compareToken(1, "!COLOUR") or not parser.getToken(name, 2)) |
946 | 327 | continue; |
328 | ||
329 | // Replace underscores in the name with spaces for readability | |
1044 | 330 | name.replace("_", " "); |
946 | 331 | |
998 | 332 | if (not parser.parseTag ("CODE", codestring)) |
946 | 333 | continue; |
334 | ||
335 | bool ok; | |
1044 | 336 | int code = codestring.toShort(&ok); |
946 | 337 | |
1044 | 338 | if (not ok or not contains(code)) |
946 | 339 | continue; |
340 | ||
1044 | 341 | if (not parser.parseTag("VALUE", facename) or not parser.parseTag("EDGE", edgename)) |
946 | 342 | continue; |
343 | ||
344 | // Ensure that our colors are correct | |
1044 | 345 | QColor faceColor = {facename}; |
346 | QColor edgeColor = {edgename}; | |
946 | 347 | |
348 | if (not faceColor.isValid() or not edgeColor.isValid()) | |
349 | continue; | |
350 | ||
1044 | 351 | // Fill in the entry now. |
998 | 352 | Entry& entry = m_data[code]; |
946 | 353 | entry.name = name; |
354 | entry.faceColor = faceColor; | |
355 | entry.edgeColor = edgeColor; | |
998 | 356 | |
1044 | 357 | // If the alpha tag is present, fill in that too. |
358 | if (parser.parseTag("ALPHA", codestring)) | |
359 | entry.faceColor.setAlpha(qBound(0, codestring.toInt(), 255)); | |
946 | 360 | } |
361 | } | |
362 | ||
1044 | 363 | /* |
364 | * LDConfigParser :: LDConfigParser | |
365 | * | |
366 | * Constructs the LDConfig.ldr parser. | |
367 | */ | |
368 | LDConfigParser::LDConfigParser(QString inputText) | |
946 | 369 | { |
1044 | 370 | m_tokens = inputText.split (' ', QString::SkipEmptyParts); |
946 | 371 | } |
372 | ||
1044 | 373 | /* |
374 | * LDConfigParser :: getToken | |
375 | * | |
376 | * Returns whether or not there is a token at the given position. | |
377 | * If there is, fills in the value parameter with it. | |
378 | */ | |
379 | bool LDConfigParser::getToken(QString& tokenText, int position) | |
946 | 380 | { |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
381 | if (position >= countof(m_tokens)) |
1044 | 382 | { |
946 | 383 | return false; |
1044 | 384 | } |
385 | else | |
386 | { | |
387 | tokenText = m_tokens[position]; | |
388 | return true; | |
389 | } | |
946 | 390 | } |
391 | ||
1044 | 392 | /* |
393 | * LDConfigParser :: findToken | |
394 | * | |
395 | * Attempts to find the provided token in the parsed LDConfig.ldr line. | |
396 | * If found, fills in the first parameter with the position of the token. | |
397 | * | |
398 | * The args parameter specifies how many arguments (i.e. following tokens) the token needs to have. | |
399 | */ | |
400 | bool LDConfigParser::findToken(int& tokenPosition, QString needle, int args) | |
946 | 401 | { |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
402 | for (int i = 0; i < (countof(m_tokens) - args); ++i) |
946 | 403 | { |
404 | if (m_tokens[i] == needle) | |
405 | { | |
1044 | 406 | tokenPosition = i; |
946 | 407 | return true; |
408 | } | |
409 | } | |
410 | ||
411 | return false; | |
412 | } | |
413 | ||
1044 | 414 | /* |
415 | * LDConfigParser :: compareToken | |
416 | * | |
417 | * Returns whether or not the token at the given position has the given text value. | |
418 | */ | |
419 | bool LDConfigParser::compareToken (int position, QString text) | |
946 | 420 | { |
1044 | 421 | QString token; |
946 | 422 | |
1044 | 423 | if (not getToken(token, position)) |
946 | 424 | return false; |
1044 | 425 | else |
426 | return (token == text); | |
946 | 427 | } |
428 | ||
1044 | 429 | /* |
430 | * LDConfig :: parseTag | |
431 | * | |
432 | * Finds an attribute in the line, and fills in its value. | |
433 | * For instance, if the line contains "ALPHA 128", this function can find the "128" for "ALPHA". | |
434 | * Returns whether or not the attribute was found. | |
435 | */ | |
436 | bool LDConfigParser::parseTag (QString key, QString& value) | |
946 | 437 | { |
1044 | 438 | int position; |
946 | 439 | |
440 | // Try find the token and get its position | |
1044 | 441 | if (not findToken (position, key, 1)) |
442 | { | |
946 | 443 | return false; |
1044 | 444 | } |
445 | else | |
446 | { | |
447 | // Get the token after it and store it in. | |
448 | return getToken (value, position + 1); | |
449 | } | |
450 | } |