diff options
author | deva <deva> | 2008-07-02 09:42:38 +0000 |
---|---|---|
committer | deva <deva> | 2008-07-02 09:42:38 +0000 |
commit | fe81dbb0a0dfc9c3808df9576dfe9a8f0b7520be (patch) | |
tree | 33281ee07a3fef90dfca8fbe330cbd7f16b79967 /client | |
parent | 4d7617cbf20985b7cf2231675d8aadd01f77c3d2 (diff) |
Made all setValue calls in a second pass, to the construction of the widgets.
Diffstat (limited to 'client')
-rw-r--r-- | client/lua.cc | 15 | ||||
-rw-r--r-- | client/macrowindow.cc | 57 | ||||
-rw-r--r-- | client/macrowindow.h | 5 | ||||
-rw-r--r-- | client/widgetbuilder.cc | 17 | ||||
-rw-r--r-- | client/widgetbuilder.h | 1 | ||||
-rw-r--r-- | client/widgets/checkbox.cc | 2 | ||||
-rw-r--r-- | client/widgets/combobox.cc | 5 | ||||
-rw-r--r-- | client/widgets/lineedit.cc | 2 | ||||
-rw-r--r-- | client/widgets/listbox.cc | 4 | ||||
-rw-r--r-- | client/widgets/multilist.cc | 2 | ||||
-rw-r--r-- | client/widgets/radiobuttons.cc | 2 | ||||
-rw-r--r-- | client/widgets/textedit.cc | 2 | ||||
-rw-r--r-- | client/widgets/window.cc | 5 | ||||
-rw-r--r-- | client/widgets/window.h | 4 |
14 files changed, 56 insertions, 67 deletions
diff --git a/client/lua.cc b/client/lua.cc index 22249a4..65d0188 100644 --- a/client/lua.cc +++ b/client/lua.cc @@ -28,6 +28,8 @@ #include "macrowindow.h" +#include "widgets/widget.h" + #define GLOBAL_POINTER "_pracroGlobalLUAObjectPointerThisShouldBeANameThatIsNotAccidentallyOverwritten" static int _enable(lua_State *L) @@ -170,22 +172,27 @@ LUA::~LUA() QString LUA::getValue(QString name) { - return macrowindow->getValue(name); + Widget *widget = macrowindow->getWidget(name); + if(widget) return widget->getValue(); + return ""; } void LUA::setValue(QString name, QString value) { - macrowindow->setValue(name, value); + Widget *widget = macrowindow->getWidget(name); + if(widget) return widget->setValue(value); } void LUA::enable(QString name) { - return macrowindow->enable(name); + Widget *widget = macrowindow->getWidget(name); + if(widget) return widget->enable(); } void LUA::disable(QString name) { - return macrowindow->disable(name); + Widget *widget = macrowindow->getWidget(name); + if(widget) return widget->disable(); } bool LUA::run(QString program, QString name, QString value) diff --git a/client/macrowindow.cc b/client/macrowindow.cc index ad85c6f..764bf79 100644 --- a/client/macrowindow.cc +++ b/client/macrowindow.cc @@ -85,10 +85,18 @@ void MacroWindow::initMacro(QDomNode &node) QDomNodeList children = node.childNodes(); + // Build widgets for (int i=0; i<children.count();i++) { QDomNode child = children.at(i); widgets += widgetBuilder(child, mainwidget, this); } + + // Insert their values (this must be done last for lua progs to work properly) + for (int i=0; i<children.count();i++) { + QDomNode child = children.at(i); + setValues(child, this); + } + return; } @@ -98,7 +106,6 @@ void MacroWindow::initMacro(QDomNode &node) QDomNode child = children.at(i); initMacro(child); } - } bool MacroWindow::doCommit() @@ -221,55 +228,13 @@ bool MacroWindow::isClosed() return isclosed; } -QString MacroWindow::getValue(QString name) -{ - // Iterate the different entries, and append their results to the commit string - QVector< Widget* >::iterator i=widgets.begin(); - while (i != widgets.end()) { - Widget* w = *i; - if(name == w->getName()) return w->getValue(); - i++; - } - return name + " - No such field!"; -} - -void MacroWindow::setValue(QString name, QString value) -{ - // Iterate the different entries, and append their results to the commit string - QVector< Widget* >::iterator i = widgets.begin(); - while (i != widgets.end()) { - Widget* w = *i; - if(name == w->getName()) w->setValue(value); - i++; - } -} - -void MacroWindow::enable(QString name) -{ - // Iterate the different entries, and append their results to the commit string - QVector< Widget* >::iterator i=widgets.begin(); - while (i != widgets.end()) { - Widget* w = *i; - if(name == w->getName()) { - w->enable(); - return; - } - i++; - } - printf("widget not found!\n"); -} - -void MacroWindow::disable(QString name) +Widget *MacroWindow::getWidget(QString name) { - // Iterate the different entries, and append their results to the commit string QVector< Widget* >::iterator i=widgets.begin(); while (i != widgets.end()) { Widget* w = *i; - if(name == w->getName()) { - w->disable(); - return; - } + if(name == w->getName()) return w; i++; } - printf("widget not found!\n"); + return NULL; } diff --git a/client/macrowindow.h b/client/macrowindow.h index 050e59d..9386f35 100644 --- a/client/macrowindow.h +++ b/client/macrowindow.h @@ -50,10 +50,7 @@ public: LUA *lua; - QString getValue(QString name); - void setValue(QString name, QString value); - void enable(QString name); - void disable(QString name); + Widget *getWidget(QString name); public slots: void commit(); diff --git a/client/widgetbuilder.cc b/client/widgetbuilder.cc index d458379..f1011e5 100644 --- a/client/widgetbuilder.cc +++ b/client/widgetbuilder.cc @@ -112,3 +112,20 @@ QVector< Widget* > widgetBuilder(QDomNode xml_node, QWidget *parent, MacroWindow return widgets; } + +void setValues(QDomNode xml_node, MacroWindow *macrowindow) +{ + QDomElement xml_elem = xml_node.toElement(); + + if(xml_elem.hasAttribute("name") && xml_elem.hasAttribute("value")) { + Widget *widget = macrowindow->getWidget(xml_elem.attribute("name")); + if(widget) widget->setValue(xml_elem.attribute("value")); + } + + QDomNodeList children = xml_node.childNodes(); + + for (int i=0; i<children.count();i++) { + QDomNode child = children.at(i); + setValues(child, macrowindow); + } +} diff --git a/client/widgetbuilder.h b/client/widgetbuilder.h index f3b7369..21bf15e 100644 --- a/client/widgetbuilder.h +++ b/client/widgetbuilder.h @@ -34,5 +34,6 @@ #include "macrowindow.h" QVector< Widget* > widgetBuilder(QDomNode xml_node, QWidget *parent, MacroWindow *macrowindow); +void setValues(QDomNode xml_node, MacroWindow *macrowindow); #endif/*__PRACRO_WIDGETBUILDER_H__*/ diff --git a/client/widgets/checkbox.cc b/client/widgets/checkbox.cc index 8474e58..95f5a53 100644 --- a/client/widgets/checkbox.cc +++ b/client/widgets/checkbox.cc @@ -47,11 +47,13 @@ CheckBox::CheckBox(QDomNode &node, MacroWindow *macrowindow) connect(this, SIGNAL(stateChanged(int)), this, SLOT(state_change())); + /* // This is done later if(elem.hasAttribute("value")) { setValue(elem.attribute("value")); } else { setValue("false"); } + */ } QString CheckBox::getValue() diff --git a/client/widgets/combobox.cc b/client/widgets/combobox.cc index 3856bed..d6d6483 100644 --- a/client/widgets/combobox.cc +++ b/client/widgets/combobox.cc @@ -67,12 +67,11 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow) } } + /* // This is done later if(elem.hasAttribute("value")) { setValue(elem.attribute("value")); } - - - // addItems(itemlist); + */ types_t combotype = SELECT; if(elem.hasAttribute("type")) { diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc index 8694889..69073ce 100644 --- a/client/widgets/lineedit.cc +++ b/client/widgets/lineedit.cc @@ -42,6 +42,7 @@ LineEdit::LineEdit(QDomNode &node, MacroWindow *macrowindow) connect(this, SIGNAL(textChanged(QString)), this, SLOT(changed())); + /* // This is done later if(elem.hasAttribute("value")) { setText(elem.attribute("value")); } else { @@ -49,6 +50,7 @@ LineEdit::LineEdit(QDomNode &node, MacroWindow *macrowindow) setText(" "); setText(""); } + */ } void LineEdit::changed() diff --git a/client/widgets/listbox.cc b/client/widgets/listbox.cc index 4af7952..a47812a 100644 --- a/client/widgets/listbox.cc +++ b/client/widgets/listbox.cc @@ -87,10 +87,12 @@ ListBox::ListBox(QDomNode &node, MacroWindow *macrowindow) QDomElement list_elem = child.toElement(); addItem(createItem(list_elem)); } - + + /* // This is done later if(elem.hasAttribute("value")) { setValue(elem.attribute("value")); } + */ } bool ListBox::isValid() diff --git a/client/widgets/multilist.cc b/client/widgets/multilist.cc index a15d995..80addf7 100644 --- a/client/widgets/multilist.cc +++ b/client/widgets/multilist.cc @@ -80,9 +80,11 @@ MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow) rem->setText("-"); layout->addWidget(rem, 1, 1, Qt::AlignTop); + /* // This is done later if(elem.hasAttribute("value")) { setValue(elem.attribute("value")); } + */ if(elem.hasAttribute("format")) { format = elem.attribute("format"); diff --git a/client/widgets/radiobuttons.cc b/client/widgets/radiobuttons.cc index bd88601..a690f17 100644 --- a/client/widgets/radiobuttons.cc +++ b/client/widgets/radiobuttons.cc @@ -67,9 +67,11 @@ RadioButtons::RadioButtons(QDomNode &node, MacroWindow *macrowindow) radiobutton_list.push_back(radiobutton); } + /* // This is done later if(elem.hasAttribute("value")) { setValue(elem.attribute("value")); } + */ } bool RadioButtons::isValid() diff --git a/client/widgets/textedit.cc b/client/widgets/textedit.cc index 0c1a0e0..dbc9e25 100644 --- a/client/widgets/textedit.cc +++ b/client/widgets/textedit.cc @@ -46,12 +46,14 @@ TextEdit::TextEdit(QDomNode &node, MacroWindow *macrowindow) connect(this, SIGNAL(textChanged()), this, SLOT(changed())); + /* // This is done later if(elem.hasAttribute("value")) { setValue(elem.attribute("value")); } else { setValue(" "); setValue(""); } + */ } void TextEdit::changed() diff --git a/client/widgets/window.cc b/client/widgets/window.cc index c4d8d14..bda3667 100644 --- a/client/widgets/window.cc +++ b/client/widgets/window.cc @@ -67,8 +67,3 @@ Window::Window(QDomNode &node, MacroWindow *macrowindow) setContentsMargins(0,0,0,0); } - -QString Window::getValue() -{ - return "Window"; -} diff --git a/client/widgets/window.h b/client/widgets/window.h index bd4c77b..af1e3d7 100644 --- a/client/widgets/window.h +++ b/client/widgets/window.h @@ -35,10 +35,6 @@ class Window : public QWidget, public Widget { public: Window(QDomNode &node, MacroWindow *macrowindow); - -public slots: - QString getValue(); - }; #endif/*__PRACRO_WINDOW_H__*/ |