From 1c190bfef95d9c48e10bd8e2168692c84b4b4558 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 30 Jun 2008 11:47:05 +0000 Subject: Added setValue and cleaned up the code in general. --- client/widgets/radiobutton.cc | 12 ++++-------- client/widgets/radiobutton.h | 4 ++-- client/widgets/radiobuttons.cc | 24 +++++++++++++++++------- client/widgets/radiobuttons.h | 1 + 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/client/widgets/radiobutton.cc b/client/widgets/radiobutton.cc index 6de030d..b757828 100644 --- a/client/widgets/radiobutton.cc +++ b/client/widgets/radiobutton.cc @@ -27,7 +27,7 @@ #include "radiobutton.h" #include -RadioButton::RadioButton(QDomNode &node, bool radio_bool) +RadioButton::RadioButton(QDomNode &node) : QRadioButton() { QDomElement elem = node.toElement(); @@ -46,19 +46,15 @@ RadioButton::RadioButton(QDomNode &node, bool radio_bool) setText(""); } - if(radio_bool) { - setChecked(true); - } else setChecked(false); - if(elem.hasAttribute("value")) { - radio_value = elem.attribute("value"); + value = elem.attribute("value"); } else { printf("XML ERROR!!! Radiobutton item has no value\n"); - radio_value = "none"; + value = "none"; } } QString RadioButton::getValue() { - return radio_value; + return value; } diff --git a/client/widgets/radiobutton.h b/client/widgets/radiobutton.h index 66c971e..d0cf149 100644 --- a/client/widgets/radiobutton.h +++ b/client/widgets/radiobutton.h @@ -36,13 +36,13 @@ class RadioButton : public QRadioButton { public: - RadioButton(QDomNode &node, bool radio_bool); + RadioButton(QDomNode &node); public slots: QString getValue(); private: - QString radio_value; + QString value; }; diff --git a/client/widgets/radiobuttons.cc b/client/widgets/radiobuttons.cc index 7508974..bd88601 100644 --- a/client/widgets/radiobuttons.cc +++ b/client/widgets/radiobuttons.cc @@ -60,19 +60,16 @@ RadioButtons::RadioButtons(QDomNode &node, MacroWindow *macrowindow) for (int i=0; iaddWidget(radiobutton); radiobutton_list.push_back(radiobutton); } + if(elem.hasAttribute("value")) { + setValue(elem.attribute("value")); + } } bool RadioButtons::isValid() @@ -100,3 +97,16 @@ QString RadioButtons::getValue() } return value; } + +void RadioButtons::setValue(QString value) +{ + QVector< RadioButton* >::iterator i; + for (i = radiobutton_list.begin(); i != radiobutton_list.end(); ++i) { + RadioButton *widget = *i; + if(value == widget->getValue()) { + widget->setChecked(true); + } else { + widget->setChecked(false); + } + } +} diff --git a/client/widgets/radiobuttons.h b/client/widgets/radiobuttons.h index 67c1cd0..f1c89c4 100644 --- a/client/widgets/radiobuttons.h +++ b/client/widgets/radiobuttons.h @@ -42,6 +42,7 @@ public: public slots: bool isValid(); QString getValue(); + void setValue(QString value); private: QVector < RadioButton* > radiobutton_list; -- cgit v1.2.3