diff options
author | senator <senator> | 2007-10-02 10:05:34 +0000 |
---|---|---|
committer | senator <senator> | 2007-10-02 10:05:34 +0000 |
commit | 4cbb885daf4ce4a4fb9827c5d6b67e9f82f730d3 (patch) | |
tree | 8bd0d38818df16dd6940a61fc8146d5d424fc21e /client | |
parent | 665db9f7d20b9deaf1e30d1efb06a7378813eeda (diff) |
now uses the correct macro name and version when comitting
Diffstat (limited to 'client')
-rw-r--r-- | client/builder.cc | 173 | ||||
-rw-r--r-- | client/builder.h | 11 |
2 files changed, 109 insertions, 75 deletions
diff --git a/client/builder.cc b/client/builder.cc index d868f12..48739a2 100644 --- a/client/builder.cc +++ b/client/builder.cc @@ -1,23 +1,25 @@ #include "builder.h" +#include "sendrecieve.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/listbox.h" #include "widgets/frame.h" +#include "widgets/groupbox.h" +#include "widgets/radiobuttons.h" #include "widgets/radiobutton.h" #include "widgets/checkbox.h" #include "widgets/window.h" -//#include <QApplication> #include <QVBoxLayout> #include <QDomDocument> #include <QDomElement> #include <QDomNode> +#include <QByteArray> #include <vector> -std::vector< Widget* > widgets; - Builder::Builder(QDomDocument *xml_doc) : QObject() { @@ -27,66 +29,6 @@ Builder::Builder(QDomDocument *xml_doc) // 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() @@ -97,17 +39,23 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent) { QWidget *widget = NULL; QDomElement xml_elem = xml_node.toElement(); - if(xml_elem.tagName() == "window") { + if(xml_elem.tagName() == "macro") { + // Assign the macro name and version to QStrings for use when comitting + if(xml_elem.hasAttribute("name")) macro = xml_elem.attribute("name"); + if(xml_elem.hasAttribute("version")) version = xml_elem.attribute("version"); + } else 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; + if(xml_elem.hasAttribute("caption")) { + GroupBox *frame = new GroupBox(xml_elem); + widget = frame; + } else { + Frame *frame = new Frame(xml_elem); + 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); @@ -115,7 +63,9 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent) widget = lineedit; } else if(xml_elem.tagName() == "button") { PushButton *pushbutton = new PushButton(xml_elem); - widgets.push_back(pushbutton); + connect(pushbutton, SIGNAL(act_commit()), this, SLOT(commit())); + connect(pushbutton, SIGNAL(act_reset()), this, SLOT(reset())); + connect(pushbutton, SIGNAL(act_cancel()), this, SLOT(cancel())); widget = pushbutton; } else if(xml_elem.tagName() == "textedit") { TextEdit *textedit = new TextEdit(xml_elem); @@ -125,10 +75,21 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent) 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; + } else if(xml_elem.tagName() == "radiobuttons") { + RadioButtons *radiobuttons = new RadioButtons(xml_elem); + widgets.push_back(radiobuttons); + widget = radiobuttons; + //return; // Don't iterate children + } else if(xml_elem.tagName() == "combobox") { + ComboBox *combobox = new ComboBox(xml_elem); + widgets.push_back(combobox); + widget = combobox; + //return; // Don't iterate children + } else if(xml_elem.tagName() == "listbox") { + ListBox *listbox = new ListBox(xml_elem); + widgets.push_back(listbox); + widget = listbox; + //return; // Don't iterate children } QDomNodeList children = xml_node.childNodes(); @@ -140,3 +101,67 @@ void Builder::recurser(QDomNode xml_node, QWidget *parent) if(parent != NULL && widget != NULL) parent->layout()->addWidget(widget); if(widget != NULL) widget->show(); } + +void Builder::commit() +{ + // Check for errors on all entries before comitting + int faulty = 0; + QVector< Widget* >::iterator i=widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + if(!w->isValid()) faulty++; + + // All selectable entries return "none" if nothing is selected + if(w->getValue() == "none") faulty++; + i++; + } + // If all entries passed validation, continue commit + if(faulty == 0) { + printf("Builder -> committing...\n"); + + QString xml_string; + xml_string.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + xml_string.append("<pracro version=\"1.0\" cpr=\"1505050505\" user=\"tux\">\n"); + xml_string.append(" <commit macro=\"" + macro + "\" version=\"" + + version + "\">\n"); + + // 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; + + xml_string.append(" <field name=\"" + w->getName() + + "\" value=\"" + w->getValue() + "\"/>\n"); + i++; + } + + xml_string.append(" </commit>\n"); + xml_string.append("</pracro>\n"); + + //char *test = xml_array.data(); + printf("%s\n", xml_string.toStdString().c_str()); + + QByteArray xml_array = xml_string.toUtf8(); + QDomDocument xml_result; + //QDomDocument xml_req; + if (!xml_result.setContent(xml_array)) { + printf("Parse error: Invalid XML\n"); + } + + SendRecieve xml_acquire; + xml_acquire.makeConnection(&xml_result); + QByteArray ba = xml_acquire.getResult(); + } else { + printf("ERROR!!! Some entries contain errors, aborting commit...\n"); + } +} + +void Builder::reset() +{ + printf("Builder -> resetting...\n"); +} + +void Builder::cancel() +{ + printf("Builder -> cancelling...\n"); +} diff --git a/client/builder.h b/client/builder.h index 6c0577d..586370d 100644 --- a/client/builder.h +++ b/client/builder.h @@ -28,23 +28,32 @@ #ifndef _BUILDER_H #define _BUILDER_H +#include "widgets/widget.h" #include <QDomDocument> #include <QWidget> #include <QDomNode> #include <QObject> +#include <QVector> class Builder : public QObject { Q_OBJECT + public: Builder(QDomDocument *xml_doc); ~Builder(); - public slots: +public slots: + void commit(); + void reset(); + void cancel(); private: void recurser(QDomNode xml_node, QWidget *parent); QDomDocument *xml_doc; + QVector< Widget* > widgets; + QString macro; + QString version; }; |