diff options
author | senator <senator> | 2007-09-11 12:28:05 +0000 |
---|---|---|
committer | senator <senator> | 2007-09-11 12:28:05 +0000 |
commit | 07ff9de80d37dc0cd33feb027628eb95c1fccd35 (patch) | |
tree | ce0dd936f12120b428ed62f0c6a8eed37a31e571 /client/builder.cc | |
parent | 20c7a5d63dc1f68fcf0e1aa053a4b725235e6f78 (diff) |
xml request and retrieval functioning; basic macro layout recursing functioning
Diffstat (limited to 'client/builder.cc')
-rw-r--r-- | client/builder.cc | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/client/builder.cc b/client/builder.cc new file mode 100644 index 0000000..d868f12 --- /dev/null +++ b/client/builder.cc @@ -0,0 +1,142 @@ +#include "builder.h" +#include "widgets/widget.h" +#include "widgets/label.h" +#include "widgets/lineedit.h" +#include "widgets/textedit.h" +#include "widgets/pushbutton.h" +#include "widgets/combobox.h" +#include "widgets/frame.h" +#include "widgets/radiobutton.h" +#include "widgets/checkbox.h" +#include "widgets/window.h" +//#include <QApplication> +#include <QVBoxLayout> +#include <QDomDocument> +#include <QDomElement> +#include <QDomNode> +#include <vector> + +std::vector< Widget* > widgets; + +Builder::Builder(QDomDocument *xml_doc) + : QObject() +{ + // Assign root element from xml_doc + this->xml_doc = xml_doc; + QDomElement xml_elem = xml_doc->documentElement(); + + // Execute the recursive function with documentElement + recurser(xml_elem, NULL); + + /* + Window widget(window_elem); + + Frame *frame = new Frame(frame_elem); + + QVBoxLayout *layout = new QVBoxLayout(); + QVBoxLayout *window_layout = new QVBoxLayout(); + + Label *label = new Label(label_elem); + widgets.push_back(label); + LineEdit *lineedit = new LineEdit(lineedit_elem); + widgets.push_back(lineedit); + LineEdit *lineedit2 = new LineEdit(lineedit_elem); + widgets.push_back(lineedit2); + TextEdit *textedit = new TextEdit(textedit_elem); + widgets.push_back(textedit); + + ComboBox *combobox = new ComboBox(combobox_elem); + widgets.push_back(combobox); + + RadioButton *radiobutton1 = new RadioButton(radiobutton1_elem); + widgets.push_back(radiobutton1); + RadioButton *radiobutton2 = new RadioButton(radiobutton2_elem); + widgets.push_back(radiobutton2); + CheckBox *checkbox = new CheckBox(checkbox_elem); + widgets.push_back(checkbox); + PushButton *pushbutton1 = new PushButton(pushbutton1_elem); + widgets.push_back(pushbutton1); + PushButton *pushbutton2 = new PushButton(pushbutton2_elem); + widgets.push_back(pushbutton2); + PushButton *pushbutton3 = new PushButton(pushbutton3_elem); + widgets.push_back(pushbutton3); + + layout->addWidget(label); + layout->addWidget(lineedit); + layout->addWidget(lineedit2); + layout->addWidget(textedit); + //layout->addWidget(combobox); + layout->addWidget(radiobutton1); + layout->addWidget(radiobutton2); + layout->addWidget(checkbox); + layout->addWidget(pushbutton1); + layout->addWidget(pushbutton2); + layout->addWidget(pushbutton3); + + frame->setLayout(layout); + + window_layout->addWidget(frame); + + widget.setLayout(window_layout); + widget.show(); + + std::vector< Widget* >::iterator i=widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + printf("%s = %s\n", w->getName().toStdString().c_str(), w->getValue().toStdString().c_str()); + i++; + } + */ +} + +Builder::~Builder() +{ +} + +void Builder::recurser(QDomNode xml_node, QWidget *parent) +{ + QWidget *widget = NULL; + QDomElement xml_elem = xml_node.toElement(); + if(xml_elem.tagName() == "window") { + Window *window = new Window(xml_elem); + widgets.push_back(window); + widget = window; + } else if(xml_elem.tagName() == "frame") { + Frame *frame = new Frame(xml_elem); + widgets.push_back(frame); + widget = frame; + } else if(xml_elem.tagName() == "label") { + Label *label = new Label(xml_elem); + widgets.push_back(label); + widget = label; + } else if(xml_elem.tagName() == "lineedit") { + LineEdit *lineedit = new LineEdit(xml_elem); + widgets.push_back(lineedit); + widget = lineedit; + } else if(xml_elem.tagName() == "button") { + PushButton *pushbutton = new PushButton(xml_elem); + widgets.push_back(pushbutton); + widget = pushbutton; + } else if(xml_elem.tagName() == "textedit") { + TextEdit *textedit = new TextEdit(xml_elem); + widgets.push_back(textedit); + widget = textedit; + } else if(xml_elem.tagName() == "checkbox") { + CheckBox *checkbox = new CheckBox(xml_elem); + widgets.push_back(checkbox); + widget = checkbox; + } else if(xml_elem.tagName() == "radiobutton") { + RadioButton *radiobutton = new RadioButton(xml_elem); + widgets.push_back(radiobutton); + widget = radiobutton; + } + QDomNodeList children = xml_node.childNodes(); + + for (int i=0; i<children.count();i++) { + QDomNode child = children.at(i); + recurser(child, widget); + } + + if(parent != NULL && widget != NULL) parent->layout()->addWidget(widget); + if(widget != NULL) widget->show(); +} |