diff options
author | deva <deva> | 2010-08-12 10:57:04 +0000 |
---|---|---|
committer | deva <deva> | 2010-08-12 10:57:04 +0000 |
commit | d9338083192084613e5530b02710b796252d342b (patch) | |
tree | e0ec2b36e0de62328e5fd5d3b597f6ee71d1b18f /client/widgetbuilder.cc | |
parent | dbab8458dcce186e7eb7a114a83f759d7db5445a (diff) |
New scripting system part2.
Diffstat (limited to 'client/widgetbuilder.cc')
-rw-r--r-- | client/widgetbuilder.cc | 169 |
1 files changed, 12 insertions, 157 deletions
diff --git a/client/widgetbuilder.cc b/client/widgetbuilder.cc index 0c9f3b3..e61ecd5 100644 --- a/client/widgetbuilder.cc +++ b/client/widgetbuilder.cc @@ -25,162 +25,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "widgetbuilder.h" -#include <QLayout> -#include "widgets.h" - -QVector< Widget* > widgetBuilder(QDomNode xml_node, QWidget *parent, - MacroWindow *macrowindow, bool watchChanges) -{ - QVector< Widget* > widgets; - - QDomElement xml_elem = xml_node.toElement(); - - if(xml_elem.hasAttribute("prefilled") && - xml_elem.attribute("prefilled") != "pracro") { - macrowindow->macroChanged(); - } - - QWidget *widget = NULL; - if(xml_elem.tagName() == "spacer") { - if(parent && parent->layout()) { - ((QBoxLayout*)parent->layout())->addStretch(); - } - } else if(xml_elem.tagName() == "frame") { - if(xml_elem.hasAttribute("caption")) { - GroupBox *frame = new GroupBox(xml_elem, macrowindow); - widgets.push_back(frame); - widget = frame; - } else { - Frame *frame = new Frame(xml_elem, macrowindow); - widgets.push_back(frame); - widget = frame; - } - - } else if(xml_elem.tagName() == "label") { - Label *label = new Label(xml_elem, macrowindow); - widget = label; - - } else if(xml_elem.tagName() == "lineedit") { - LineEdit *lineedit = new LineEdit(xml_elem, macrowindow); - widgets.push_back(lineedit); - widget = lineedit; - if(watchChanges) - lineedit->connectFrom(SIGNAL(wasChanged()), macrowindow, SLOT(macroChanged())); - - } else if(xml_elem.tagName() == "datetime") { - DateTime *datetime = new DateTime(xml_elem, macrowindow); - widgets.push_back(datetime); - widget = datetime; - if(watchChanges) - datetime->connectFrom(SIGNAL(wasChanged()), macrowindow, SLOT(macroChanged())); - - } else if(xml_elem.tagName() == "button") { - Button *button = new Button(xml_elem, macrowindow); - //macrowindow->connect(pushbutton, SIGNAL(act_continue()), main, SLOT(get_macro())); - QObject::connect(button, SIGNAL(act_commit()), macrowindow, SLOT(commit())); - QObject::connect(button, SIGNAL(act_reset()), macrowindow, SLOT(reset())); - QObject::connect(button, SIGNAL(act_cancel()), macrowindow, SLOT(cancel())); - QObject::connect(button, SIGNAL(act_continue(QString)), macrowindow, SLOT(cont(QString))); - QObject::connect(button, SIGNAL(act_continue_nocommit(QString)), - macrowindow, SLOT(cont_nocommit(QString))); - QObject::connect(macrowindow, SIGNAL(macroHasChanged()), button, SLOT(do_enable())); - widget = button; - - } else if(xml_elem.tagName() == "textedit") { - TextEdit *textedit = new TextEdit(xml_elem, macrowindow); - widgets.push_back(textedit); - widget = textedit; - if(watchChanges) - QObject::connect(textedit, SIGNAL(wasChanged()), macrowindow, SLOT(macroChanged())); - - } else if(xml_elem.tagName() == "checkbox") { - CheckBox *checkbox = new CheckBox(xml_elem, macrowindow); - widgets.push_back(checkbox); - widget = checkbox; - if(watchChanges) - QObject::connect(checkbox, SIGNAL(wasChanged()), macrowindow, SLOT(macroChanged())); - - } else if(xml_elem.tagName() == "radiobuttons") { - RadioButtons *radiobuttons = new RadioButtons(xml_elem, macrowindow); - widgets.push_back(radiobuttons); - widget = radiobuttons; - if(watchChanges) - QObject::connect(radiobuttons, SIGNAL(wasChanged()), macrowindow, SLOT(macroChanged())); - //return; // Don't iterate children - - } else if(xml_elem.tagName() == "combobox") { - ComboBox *combobox = new ComboBox(xml_elem, macrowindow); - widgets.push_back(combobox); - widget = combobox; - if(watchChanges) - QObject::connect(combobox, SIGNAL(wasChanged()), macrowindow, SLOT(macroChanged())); - //return; // Don't iterate children - } else if(xml_elem.tagName() == "dbwidget") { - DBWidget *dbwidget = new DBWidget(xml_elem, macrowindow); - widgets.push_back(dbwidget); - widget = dbwidget; - if(watchChanges) - QObject::connect(dbwidget, SIGNAL(wasChanged()), macrowindow, SLOT(macroChanged())); - - } else if(xml_elem.tagName() == "listbox") { - ListBox *listbox = new ListBox(xml_elem, macrowindow); - widgets.push_back(listbox); - widget = listbox; - if(watchChanges) - QObject::connect(listbox, SIGNAL(wasChanged()), macrowindow, SLOT(macroChanged())); - //return; // Don't iterate children - - } else if(xml_elem.tagName() == "multilist") { - MultiList *multilist = new MultiList(xml_elem, macrowindow); - widgets.push_back(multilist); - widget = multilist; - if(watchChanges) - QObject::connect(multilist, SIGNAL(wasChanged()), macrowindow, SLOT(macroChanged())); - - if(parent && widget && parent->layout()) parent->layout()->addWidget(widget); - if(widget) widget->show(); - - return widgets; // Don't iterate children - - } else if(xml_elem.tagName() == "altcombobox") { - AltComboBox *altcombobox = new AltComboBox(xml_elem, macrowindow); - widgets.push_back(altcombobox); - widget = altcombobox; - if(watchChanges) - QObject::connect(altcombobox, SIGNAL(wasChanged()), macrowindow, SLOT(macroChanged())); - - if(parent && widget && parent->layout()) parent->layout()->addWidget(widget); - if(widget) widget->show(); - - return widgets; // Don't iterate children - } else if(xml_elem.tagName() == "metawidget") { - MetaWidget *metawidget = new MetaWidget(xml_elem, macrowindow); - widgets.push_back(metawidget); - widget = metawidget; - if(watchChanges) - QObject::connect(metawidget, SIGNAL(wasChanged()), macrowindow, SLOT(macroChanged())); - - if(parent && widget && parent->layout()) parent->layout()->addWidget(widget); - if(widget) widget->show(); - - return widgets; // Don't iterate children - } - - QDomNodeList children = xml_node.childNodes(); - - for (int i=0; i<children.count();i++) { - QDomNode child = children.at(i); - widgets += widgetBuilder(child, widget, macrowindow, watchChanges); - } - - if(parent && widget && parent->layout()) parent->layout()->addWidget(widget); - if(widget) widget->show(); +#include <QLayout> +#include <QObject> - return widgets; -} +#include "widgets.h" +#include "macrowindow.h" -void setValues(QDomNode xml_node, MacroWindow *macrowindow) +void setValues(QDomNode &xml_node, Widget *rootwidget) { QDomElement xml_elem = xml_node.toElement(); @@ -188,15 +40,18 @@ void setValues(QDomNode xml_node, MacroWindow *macrowindow) xml_elem.tagName() == "radiobutton") return; if(xml_elem.hasAttribute("name") && xml_elem.hasAttribute("value")) { - Widget *widget = macrowindow->getWidget(xml_elem.attribute("name")); - if(widget && widget->hasInitialValue() == false) // Don't set the value if it is already set indirectly (altcombobox) - widget->setValue(xml_elem.attribute("value"), xml_elem.attribute("prefilled", "")); + Widget *widget = rootwidget->findWidget(xml_elem.attribute("name"), true); + if(widget && widget->hasInitialValue() == false) { + // Don't set the value if it is already set indirectly (altcombobox) + widget->setValue(xml_elem.attribute("value"), + xml_elem.attribute("prefilled", "")); + } } QDomNodeList children = xml_node.childNodes(); for (int i=0; i<children.count();i++) { QDomNode child = children.at(i); - setValues(child, macrowindow); + setValues(child, rootwidget); } } |