Skip to content

Commit 6c1b85d

Browse files
committed
Changed argAction structure
Created virtual class argBase and specific implementations for each QWidget
1 parent d0f58c4 commit 6c1b85d

File tree

5 files changed

+237
-149
lines changed

5 files changed

+237
-149
lines changed

argaction.cpp

Lines changed: 59 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -19,150 +19,141 @@
1919

2020
#include "argaction.h"
2121

22-
argAction::argAction()
22+
bool argDoubleSpinBox::setValue(const QString value)
2323
{
24+
bool ok;
25+
const double numericalValue = value.toDouble(&ok);
26+
27+
if (ok)
28+
object->setValue(numericalValue);
2429

30+
return ok;
2531
}
2632

27-
argAction::~argAction()
33+
QString argDoubleSpinBox::getValue()
2834
{
29-
35+
return QString::number(object->value(), 'f', 4);
3036
}
3137

32-
bool argAction::setDoubleSpinBox(void *doubleSpinBox, const QString argValue)
38+
bool argSpinBox::setValue(const QString value)
3339
{
3440
bool ok;
35-
double value = argValue.toDouble(&ok);
41+
double numericalValue = value.toInt(&ok);
3642

3743
if (ok)
38-
static_cast<QDoubleSpinBox *>(doubleSpinBox)->setValue(value);
44+
object->setValue(numericalValue);
3945

4046
return ok;
4147
}
4248

43-
bool argAction::setSpinBox(void *spinBox, const QString argValue)
49+
QString argSpinBox::getValue()
4450
{
45-
bool ok;
46-
int value = argValue.toInt(&ok, 10);
47-
48-
if (ok)
49-
static_cast<QSpinBox *>(spinBox)->setValue(value);
50-
51-
return ok;
51+
return QString::number(object->value());
5252
}
5353

54-
bool argAction::setCheckBox(void *checkBox, const QString argValue)
54+
bool argCheckBox::setValue(const QString value)
5555
{
56-
if(argValue == "1" || argValue.compare("true", Qt::CaseInsensitive) == 0)
56+
if(value == "1" || value.compare("true", Qt::CaseInsensitive) == 0)
5757
{
58-
static_cast<QCheckBox *>(checkBox)->setChecked(true);
58+
object->setChecked(true);
5959
return true;
6060
}
61-
else if (argValue == "0" || argValue.compare("false", Qt::CaseInsensitive) == 0)
61+
else if (value == "0" || value.compare("false", Qt::CaseInsensitive) == 0)
6262
{
63-
static_cast<QCheckBox *>(checkBox)->setChecked(false);
63+
object->setChecked(false);
6464
return true;
6565
}
6666
else
6767
return false;
6868
}
6969

70-
bool argAction::setLineEdit(void *lineEdit, const QString argValue)
70+
QString argCheckBox::getValue()
7171
{
72-
static_cast<QLineEdit *>(lineEdit)->setText(argValue);
72+
if(object->isChecked())
73+
return "true";
74+
else
75+
return "false";
76+
}
7377

78+
bool argLineEdit::setValue(const QString value)
79+
{
80+
object->setText(value);
7481
return true;
7582
}
7683

77-
bool argAction::setComboBox(void *comboBox, const QString argValue)
84+
QString argLineEdit::getValue()
85+
{
86+
return object->text();
87+
}
88+
89+
bool argComboBox::setValue(const QString value)
7890
{
79-
int index = static_cast<QComboBox *>(comboBox)->findText(argValue, Qt::MatchFixedString);
91+
const int index = object->findText(value, Qt::MatchFixedString);
8092

8193
if( index >= 0 )
8294
{
83-
static_cast<QComboBox *>(comboBox)->setCurrentIndex(index);
95+
object->setCurrentIndex(index);
8496
return true;
8597
}
8698
else
8799
return false;
88100
}
89101

90-
bool argAction::setRadioButtonPair(void *radioButtonPair, const QString argValue)
102+
QString argComboBox::getValue()
91103
{
92-
if(argValue == "1" || argValue.compare("true", Qt::CaseInsensitive) == 0)
104+
return object->currentText();
105+
}
106+
107+
bool argRadioButtonPair::setValue(const QString value)
108+
{
109+
if(value == "1" || value.compare("true", Qt::CaseInsensitive) == 0)
93110
{
94-
static_cast<QWidgetPair<QRadioButton, QRadioButton> *>(radioButtonPair)->object1->setChecked(true);
111+
object.first->setChecked(true);
112+
object.second->setChecked(false);
95113
return true;
96114
}
97-
else if(argValue == "0" || argValue.compare("false", Qt::CaseInsensitive) == 0)
115+
else if(value == "0" || value.compare("false", Qt::CaseInsensitive) == 0)
98116
{
99-
static_cast<QWidgetPair<QRadioButton, QRadioButton> *>(radioButtonPair)->object2->setChecked(true);
117+
object.first->setChecked(false);
118+
object.second->setChecked(true);
100119
return true;
101120
}
102121
else
103122
return false;
104123
}
105124

106-
QString argAction::getDoubleSpinBox(void *doubleSpinBox)
107-
{
108-
return QString::number(static_cast<QDoubleSpinBox *>(doubleSpinBox)->value(), 'f', 4);
109-
}
110-
111-
QString argAction::getSpinBox(void *spinBox)
125+
QString argRadioButtonPair::getValue()
112126
{
113-
return QString::number(static_cast<QSpinBox *>(spinBox)->value(), 10);
114-
}
115-
116-
QString argAction::getCheckBox(void *checkBox)
117-
{
118-
if(static_cast<QCheckBox *>(checkBox)->isChecked())
127+
if(object.first->isChecked())
119128
return "true";
120129
else
121130
return "false";
122131
}
123132

124-
QString argAction::getLineEdit(void *lineEdit)
125-
{
126-
return static_cast<QLineEdit *>(lineEdit)->text();
127-
}
128-
129-
QString argAction::getComboBox(void *comboBox)
133+
bool argRadioButtonPair::setEnabled(bool enabled)
130134
{
131-
return static_cast<QComboBox *>(comboBox)->currentText();
132-
}
135+
object.first->setEnabled(enabled);
136+
object.second->setEnabled(enabled);
133137

134-
QString argAction::getRadioButtonPair(void *radioButtonPair)
135-
{
136-
if(static_cast<QWidgetPair<QRadioButton, QRadioButton> *>(radioButtonPair)->object1->isChecked())
137-
return "true";
138-
else
139-
return "false";
138+
return true;
140139
}
141140

142-
bool argAction::setValue(const QString key, const QString value)
141+
bool argRadioButtonPair::getEnabled()
143142
{
144-
argElement element;
145-
146-
if( argList.contains(key) )
147-
{
148-
element = argList.value(key);
149-
return element.setFunction( element.object, value );
150-
}
151-
152-
return false;
143+
return object.first->isEnabled();
153144
}
154145

155146
QStringList argAction::getAllArgs(const QString prepend, bool getCommentedOptions)
156147
{
157148
QStringList output;
158149
QString value;
159150

160-
for(QMap<QString, argElement>::const_iterator i = argList.constBegin(); i != argList.constEnd(); i++)
151+
for(QMap<QString, argBase *>::const_iterator i = objects.constBegin(); i != objects.constEnd(); i++)
161152
{
162-
value = i.value().getFunction( i.value().object );
153+
value = i.value()->getValue();
163154
if ( !value.isEmpty() )
164155
{
165-
if( static_cast<QWidget *>(i.value().object)->isEnabled() )
156+
if( i.value()->getEnabled() )
166157
output << prepend + i.key() + '=' + value;
167158
else
168159
if(getCommentedOptions)
@@ -172,14 +163,3 @@ QStringList argAction::getAllArgs(const QString prepend, bool getCommentedOption
172163

173164
return output;
174165
}
175-
176-
bool argAction::setEnabled(const QString key, const bool enabled)
177-
{
178-
if( argList.contains(key) )
179-
{
180-
static_cast<QWidget *>(argList.value(key).object)->setEnabled(enabled);
181-
return true;
182-
}
183-
else
184-
return false;
185-
}

0 commit comments

Comments
 (0)