11/*
2- * Copyright (c) 2015 Nicola Corna (nicola@corna.info)
2+ * Copyright (c) 2015-2016 Nicola Corna (nicola@corna.info)
33 *
44 * This file is part of pcb2gcodeGUI.
55 *
1919
2020#include " argaction.h"
2121
22- bool argDoubleSpinBox::setValue (const QString value)
22+ template <>
23+ bool argBase<QDoubleSpinBox>::setValue(const QString value)
2324{
2425 bool ok;
2526 const double numericalValue = value.toDouble (&ok);
@@ -30,12 +31,14 @@ bool argDoubleSpinBox::setValue(const QString value)
3031 return ok;
3132}
3233
33- QString argDoubleSpinBox::getValue ()
34+ template <>
35+ QString argBase<QDoubleSpinBox>::getValue()
3436{
3537 return QString::number (object->value (), ' f' , 4 );
3638}
3739
38- bool argSpinBox::setValue (const QString value)
40+ template <>
41+ bool argBase<QSpinBox>::setValue(const QString value)
3942{
4043 bool ok;
4144 double numericalValue = value.toInt (&ok);
@@ -46,12 +49,14 @@ bool argSpinBox::setValue(const QString value)
4649 return ok;
4750}
4851
49- QString argSpinBox::getValue ()
52+ template <>
53+ QString argBase<QSpinBox>::getValue()
5054{
5155 return QString::number (object->value ());
5256}
5357
54- bool argCheckBox::setValue (const QString value)
58+ template <>
59+ bool argBase<QCheckBox>::setValue(const QString value)
5560{
5661 if (value == " 1" || value.compare (" true" , Qt::CaseInsensitive) == 0 )
5762 {
@@ -67,26 +72,30 @@ bool argCheckBox::setValue(const QString value)
6772 return false ;
6873}
6974
70- QString argCheckBox::getValue ()
75+ template <>
76+ QString argBase<QCheckBox>::getValue()
7177{
7278 if (object->isChecked ())
7379 return " true" ;
7480 else
7581 return " false" ;
7682}
7783
78- bool argLineEdit::setValue (const QString value)
84+ template <>
85+ bool argBase<QLineEdit>::setValue(const QString value)
7986{
8087 object->setText (value);
8188 return true ;
8289}
8390
84- QString argLineEdit::getValue ()
91+ template <>
92+ QString argBase<QLineEdit>::getValue()
8593{
8694 return object->text ();
8795}
8896
89- bool argComboBox::setValue (const QString value)
97+ template <>
98+ bool argBase<QComboBox>::setValue(const QString value)
9099{
91100 const int index = object->findText (value, Qt::MatchFixedString);
92101
@@ -99,56 +108,61 @@ bool argComboBox::setValue(const QString value)
99108 return false ;
100109}
101110
102- QString argComboBox::getValue ()
111+ template <>
112+ QString argBase<QComboBox>::getValue()
103113{
104114 return object->currentText ();
105115}
106116
107- bool argRadioButtonPair::setValue (const QString value)
117+ template <>
118+ bool argBase<QButtonGroup>::setValue(const QString value)
108119{
109120 if (value == " 1" || value.compare (" true" , Qt::CaseInsensitive) == 0 )
110121 {
111- object.first ->setChecked (true );
112- object.second ->setChecked (false );
122+ object->button (0 )->setChecked (true );
113123 return true ;
114124 }
115125 else if (value == " 0" || value.compare (" false" , Qt::CaseInsensitive) == 0 )
116126 {
117- object.first ->setChecked (false );
118- object.second ->setChecked (true );
127+ object->button (1 )->setChecked (true );
119128 return true ;
120129 }
121130 else
122131 return false ;
123132}
124133
125- QString argRadioButtonPair::getValue ()
134+ template <>
135+ QString argBase<QButtonGroup>::getValue()
126136{
127- if (object. first -> isChecked () )
137+ if (object-> checkedId () == 0 )
128138 return " true" ;
129139 else
130140 return " false" ;
131141}
132142
133- bool argRadioButtonPair::setEnabled (bool enabled)
143+ template <>
144+ void argBase<QButtonGroup>::setEnabled(bool enabled)
134145{
135- object.first ->setEnabled (enabled);
136- object.second ->setEnabled (enabled);
146+ QList<QAbstractButton *> buttons = object->buttons ();
137147
138- return true ;
148+ for (QAbstractButton *button : buttons)
149+ {
150+ button->setEnabled (enabled);
151+ }
139152}
140153
141- bool argRadioButtonPair::getEnabled ()
154+ template <>
155+ bool argBase<QButtonGroup>::getEnabled()
142156{
143- return object. first ->isEnabled ();
157+ return object-> button ( 0 ) ->isEnabled ();
144158}
145159
146160QStringList argAction::getAllArgs (const QString prepend, bool getCommentedOptions)
147161{
148162 QStringList output;
149163 QString value;
150164
151- for (QMap<QString, argBase *>::const_iterator i = objects.constBegin (); i != objects.constEnd (); i++)
165+ for ( auto i = objects.constBegin (); i != objects.constEnd (); i++)
152166 {
153167 value = i.value ()->getValue ();
154168 if ( !value.isEmpty () )
0 commit comments