Skip to content

Commit 797fb58

Browse files
committed
Multiple fixes
1 parent 643bfa1 commit 797fb58

File tree

5 files changed

+254
-187
lines changed

5 files changed

+254
-187
lines changed

argaction.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ bool argAction::setComboBox(void *comboBox, const QString argValue)
8787
return false;
8888
}
8989

90-
bool argAction::setButtonGroup(void *buttonGroup, const QString argValue)
90+
bool argAction::setRadioButtonPair(void *radioButtonPair, const QString argValue)
9191
{
9292
if(argValue == "1" || argValue.compare("true", Qt::CaseInsensitive) == 0)
9393
{
94-
static_cast<QButtonGroup *>(buttonGroup)->button(0)->setChecked(true);
94+
static_cast<QWidgetPair<QRadioButton, QRadioButton> *>(radioButtonPair)->object1->setChecked(true);
9595
return true;
9696
}
9797
else if(argValue == "0" || argValue.compare("false", Qt::CaseInsensitive) == 0)
9898
{
99-
static_cast<QButtonGroup *>(buttonGroup)->button(1)->setChecked(true);
99+
static_cast<QWidgetPair<QRadioButton, QRadioButton> *>(radioButtonPair)->object2->setChecked(true);
100100
return true;
101101
}
102102
else
@@ -131,9 +131,9 @@ QString argAction::getComboBox(void *comboBox)
131131
return static_cast<QComboBox *>(comboBox)->currentText();
132132
}
133133

134-
QString argAction::getButtonGroup(void *buttonGroup)
134+
QString argAction::getRadioButtonPair(void *radioButtonPair)
135135
{
136-
if(static_cast<QButtonGroup *>(buttonGroup)->button(0)->isChecked())
136+
if(static_cast<QWidgetPair<QRadioButton, QRadioButton> *>(radioButtonPair)->object1->isChecked())
137137
return "true";
138138
else
139139
return "false";
@@ -152,28 +152,34 @@ bool argAction::setValue(const QString key, const QString value)
152152
return false;
153153
}
154154

155-
QStringList argAction::getAllArgs(const bool getCommentedOptions, const bool getDisabledObjects)
155+
QStringList argAction::getAllArgs(bool getCommentedOptions)
156156
{
157157
QStringList output;
158158
QString value;
159159

160-
for(QHash<QString, argElement>::const_iterator i = argList.constBegin(); i != argList.constEnd(); i++)
160+
for(QMap<QString, argElement>::const_iterator i = argList.constBegin(); i != argList.constEnd(); i++)
161161
{
162-
if( getDisabledObjects || static_cast<QWidget *>(i.value().object)->isEnabled() )
162+
value = i.value().getFunction( i.value().object );
163+
if ( !value.isEmpty() )
163164
{
164-
value = i.value().getFunction( i.value().object );
165-
if ( !value.isEmpty() )
166-
{
167-
if(i.value().commentedOption)
168-
{
169-
if(getCommentedOptions)
170-
output << "#@!" + i.key() + '=' + value;
171-
}
172-
else
173-
output << i.key() + '=' + value;
174-
}
165+
if( static_cast<QWidget *>(i.value().object)->isEnabled() )
166+
output << i.key() + '=' + value;
167+
else
168+
if(getCommentedOptions)
169+
output << "#@#" + i.key() + '=' + value;
175170
}
176171
}
177172

178173
return output;
179174
}
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+
}

argaction.h

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,87 +20,96 @@
2020
#ifndef ARGACTION_H
2121
#define ARGACTION_H
2222

23-
#include <QHash>
23+
#include <QMap>
2424
#include <QString>
2525
#include <QStringList>
2626
#include <QDoubleSpinBox>
2727
#include <QSpinBox>
2828
#include <QCheckBox>
29-
#include <QButtonGroup>
29+
#include <QRadioButton>
3030
#include <QLineEdit>
3131
#include <QComboBox>
3232

33+
template <class T1, class T2> class QWidgetPair : public QWidget
34+
{
35+
public:
36+
explicit QWidgetPair() {}
37+
explicit QWidgetPair(T1 *object1, T2 *object2) :
38+
object1(object1), object2(object2) {}
39+
40+
T1 *object1;
41+
T2 *object2;
42+
};
43+
3344
class argAction
3445
{
3546
protected:
36-
3747
static bool setDoubleSpinBox(void *doubleSpinBox, const QString argValue);
3848
static bool setSpinBox(void *spinBox, const QString argValue);
3949
static bool setCheckBox(void *checkBox, const QString argValue);
4050
static bool setLineEdit(void *lineEdit, const QString argValue);
4151
static bool setComboBox(void *comboBox, const QString argValue);
42-
static bool setButtonGroup(void *buttonGroup, const QString argValue);
52+
static bool setRadioButtonPair(void *radioButtonPair, const QString argValue);
53+
4354
static QString getDoubleSpinBox(void *doubleSpinBox);
4455
static QString getSpinBox(void *spinBox);
4556
static QString getCheckBox(void *checkBox);
4657
static QString getLineEdit(void *lineEdit);
4758
static QString getComboBox(void *comboBox);
48-
static QString getButtonGroup(void *buttonGroup);
59+
static QString getRadioButtonPair(void *radioButtonPair);
4960

5061
struct argElement
5162
{
5263
bool (*setFunction)(void *object, QString argValue);
5364
QString (*getFunction)(void *object);
5465
void *object;
55-
bool commentedOption;
5666
};
5767

58-
QHash<QString,argElement> argList;
68+
QMap<QString,argElement> argList;
5969

6070
public:
6171
explicit argAction();
6272
~argAction();
6373

6474
bool setValue(const QString key, const QString value);
75+
QStringList getAllArgs(bool getCommentedOptions);
76+
bool setEnabled(const QString key, const bool enabled);
6577

66-
QStringList getAllArgs(const bool getCommentedOptions = false, const bool getDisabledObjects = false);
67-
68-
inline void insert( const QString argName, QDoubleSpinBox *doubleSpinBox, const bool commentedOption = false )
78+
inline void insert( const QString argName, QDoubleSpinBox *doubleSpinBox)
6979
{
7080
argList.insert( argName, (argElement){ .setFunction = &setDoubleSpinBox, .getFunction = &getDoubleSpinBox,
71-
.object = doubleSpinBox, .commentedOption = commentedOption } );
81+
.object = doubleSpinBox } );
7282
}
7383

74-
inline void insert( const QString argName, QSpinBox *spinBox, const bool commentedOption = false )
84+
inline void insert( const QString argName, QSpinBox *spinBox)
7585
{
7686
argList.insert( argName, (argElement){ .setFunction = &setSpinBox, .getFunction = &getSpinBox,
77-
.object = spinBox, .commentedOption = commentedOption } );
87+
.object = spinBox } );
7888
}
7989

80-
inline void insert( const QString argName, QCheckBox *checkBox, const bool commentedOption = false )
90+
inline void insert( const QString argName, QCheckBox *checkBox)
8191
{
8292
argList.insert( argName, (argElement){ .setFunction = &setCheckBox, .getFunction = &getCheckBox,
83-
.object = checkBox, .commentedOption = commentedOption } );
93+
.object = checkBox } );
8494
}
8595

86-
inline void insert( const QString argName, QLineEdit *lineEdit, const bool commentedOption = false )
96+
inline void insert( const QString argName, QLineEdit *lineEdit)
8797
{
8898
argList.insert( argName, (argElement){ .setFunction = &setLineEdit, .getFunction = &getLineEdit,
89-
.object = lineEdit, .commentedOption = commentedOption } );
99+
.object = lineEdit } );
90100
}
91101

92-
inline void insert( const QString argName, QComboBox *comboBox, const bool commentedOption = false )
102+
inline void insert( const QString argName, QComboBox *comboBox)
93103
{
94104
argList.insert( argName, (argElement){ .setFunction = &setComboBox, .getFunction = &getComboBox,
95-
.object = comboBox, .commentedOption = commentedOption } );
105+
.object = comboBox } );
96106
}
97107

98-
inline void insert( const QString argName, QButtonGroup *buttonGroup, const bool commentedOption = false )
108+
inline void insert( const QString argName, QWidgetPair<QRadioButton, QRadioButton> *radioButtonPair)
99109
{
100-
argList.insert( argName, (argElement){ .setFunction = &setButtonGroup, .getFunction = &getButtonGroup,
101-
.object = buttonGroup, .commentedOption = commentedOption } );
110+
argList.insert( argName, (argElement){ .setFunction = &setRadioButtonPair, .getFunction = &getRadioButtonPair,
111+
.object = radioButtonPair } );
102112
}
103-
104113
};
105114

106115
#endif // ARGACTION_H

0 commit comments

Comments
 (0)