Merge lp:~oopsdude/stellarium/stellarium into lp:stellarium

Proposed by Mike Storm
Status: Merged
Merged at revision: 5705
Proposed branch: lp:~oopsdude/stellarium/stellarium
Merge into: lp:stellarium
Diff against target: 58 lines (+19/-13)
2 files modified
plugins/TextUserInterface/src/TuiNodeEnum.cpp (+17/-12)
plugins/TextUserInterface/src/TuiNodeEnum.hpp (+2/-1)
To merge this branch: bzr merge lp:~oopsdude/stellarium/stellarium
Reviewer Review Type Date Requested Status
Alexander Wolf Approve
Review via email: mp+136074@code.launchpad.net

Description of the change

These commits fix a crash in the TUI plugin that happened when the user tried to display a TuiNodeEnum that had been created with an empty list of elements.

To reproduce it, rename your "locale" directory to something else. Then activate the TUI plugin, press "m", and navigate to "3. General -> 3.2. Language: XXX". Stellarium should crash with a SIGABRT triggered at TuiNodeEnum.cpp:71, since the stringList field is empty. I only noticed this because my dev build doesn't have a "locale" directory.

Anyway, this patch detects when the list of elements is empty, and displays the default value instead. Maybe it should display something like "(none)" instead; it's up to you.

Best,
Mike

To post a comment you must log in.
Revision history for this message
Alexander Wolf (alexwolf) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/TextUserInterface/src/TuiNodeEnum.cpp'
2--- plugins/TextUserInterface/src/TuiNodeEnum.cpp 2012-04-01 21:12:29 +0000
3+++ plugins/TextUserInterface/src/TuiNodeEnum.cpp 2012-11-26 00:28:20 +0000
4@@ -22,7 +22,7 @@
5
6 TuiNodeEnum::TuiNodeEnum(const QString& text, QObject* receiver, const char* method, QStringList items,
7 QString defValue, TuiNode* parent, TuiNode* prev)
8- : TuiNodeEditable(text, parent, prev), stringList(items)
9+ : TuiNodeEditable(text, parent, prev), stringList(items), defValue(defValue)
10 {
11 this->connect(this, SIGNAL(setValue(QString)), receiver, method);
12
13@@ -68,15 +68,20 @@
14
15 QString TuiNodeEnum::getDisplayText()
16 {
17- QString value = q_(stringList.at(currentIdx));
18- if (!editing)
19- {
20- return prefixText + q_(displayText) + QString(": %1").arg(value);
21- }
22- else
23- {
24- return prefixText + q_(displayText) + QString(": >%1<").arg(value);
25- }
26+ if (!stringList.isEmpty())
27+ {
28+ QString value = q_(stringList.at(currentIdx));
29+ if (!editing)
30+ {
31+ return prefixText + q_(displayText) + QString(": %1").arg(value);
32+ }
33+ else
34+ {
35+ return prefixText + q_(displayText) + QString(": >%1<").arg(value);
36+ }
37+ }
38+ else
39+ {
40+ return prefixText + q_(displayText) + QString(": %1").arg(defValue);
41+ }
42 }
43-
44-
45
46=== modified file 'plugins/TextUserInterface/src/TuiNodeEnum.hpp'
47--- plugins/TextUserInterface/src/TuiNodeEnum.hpp 2012-01-11 10:50:37 +0000
48+++ plugins/TextUserInterface/src/TuiNodeEnum.hpp 2012-11-26 00:28:20 +0000
49@@ -50,7 +50,8 @@
50 private:
51 int currentIdx;
52 QStringList stringList;
53-
54+ QString defValue;
55+
56 };
57
58 #endif /*_TUINODEENUM*/