From 8c3994b02e3a0cf81ead56c8dcfefb67be078328 Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 18 Jun 2008 11:03:34 +0000 Subject: Restructured widget building, completed inital version of MultiList with format string parsing, db commiting and rereading. --- client/client.pro | 4 ++ client/formatparser.cc | 100 ++++++++++++++++++++++++++++++++++++++ client/formatparser.h | 36 ++++++++++++++ client/macrowindow.cc | 98 ++++++------------------------------- client/macrowindow.h | 3 +- client/widgetbuilder.cc | 114 ++++++++++++++++++++++++++++++++++++++++++++ client/widgetbuilder.h | 38 +++++++++++++++ client/widgets/multilist.cc | 112 ++++++++++++++++++++++++++----------------- client/widgets/multilist.h | 8 +++- client/widgets/widget.cc | 1 - 10 files changed, 383 insertions(+), 131 deletions(-) create mode 100644 client/formatparser.cc create mode 100644 client/formatparser.h create mode 100644 client/widgetbuilder.cc create mode 100644 client/widgetbuilder.h (limited to 'client') diff --git a/client/client.pro b/client/client.pro index 37a8da1..49b718a 100644 --- a/client/client.pro +++ b/client/client.pro @@ -23,10 +23,12 @@ unix { } HEADERS += \ + formatparser.h \ lua.h \ macro.h \ macrowindow.h \ sendrecieve.h \ + widgetbuilder.h \ widgets.h \ widgets/widget.h \ widgets/label.h \ @@ -45,10 +47,12 @@ HEADERS += \ SOURCES += \ pracro.cc \ + formatparser.cc \ lua.cc \ macro.cc \ macrowindow.cc \ sendrecieve.cc \ + widgetbuilder.cc \ widgets/widget.cc \ widgets/label.cc \ widgets/lineedit.cc \ diff --git a/client/formatparser.cc b/client/formatparser.cc new file mode 100644 index 0000000..260a2bf --- /dev/null +++ b/client/formatparser.cc @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * resumeparser.cc + * + * Mon Oct 1 11:17:35 CEST 2007 + * Copyright 2007 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "formatparser.h" + +#include + +QString format_parser(QString format, QVector< Widget *> widgets) +{ + QString resume; + QString var; + + QChar *p = format.data(); + QChar *theend = p + format.size(); + while(p < theend) { + switch((*p).toLatin1()) { + case '$': + p++; + switch((*p).toLatin1()) { + case '$': + resume.append(*p); + break; + + case '{': + p++; + var = ""; + // Parser + while(p < theend && *p != '}') { + var.append(*p); + p++; + } + { + QVector< Widget* >::iterator i = widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + if(w->getName() == var) resume += w->getValue(); + i++; + } + } + break; + + default: + resume.append(*p); + break; + } + p++; + break; + + case '\\': + p++; + switch((*p).toLatin1()) { + case 't': + resume.append('\t'); + break; + case 'n': + resume.append('\n'); + break; + case 'r': + resume.append('\r'); + break; + case '\\': + default: + resume.append(*p); + break; + } + p++; + break; + + default: + resume.append(QChar(*p)); + p++; + break; + } + } + + return resume; +} diff --git a/client/formatparser.h b/client/formatparser.h new file mode 100644 index 0000000..8612a0e --- /dev/null +++ b/client/formatparser.h @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * formatparser.h + * + * Mon Oct 1 11:17:35 CEST 2007 + * Copyright 2007 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __PRACRO_FORMATPARSER_H__ +#define __PRACRO_FORMATPARSER_H__ + +#include +#include +#include "widgets/widget.h" + +QString format_parser(QString format, QVector< Widget *> widgets); + +#endif/*__PRACRO_FORMATPARSER_H__*/ diff --git a/client/macrowindow.cc b/client/macrowindow.cc index b799d31..6f52916 100644 --- a/client/macrowindow.cc +++ b/client/macrowindow.cc @@ -26,8 +26,8 @@ */ #include "macrowindow.h" #include "sendrecieve.h" -#include "widgets.h" #include "macro.h" +#include "widgets/widget.h" #include #include #include @@ -35,6 +35,8 @@ #include #include +#include "widgets/window.h" +#include "widgetbuilder.h" #include "lua.h" extern QString cpr; @@ -46,11 +48,13 @@ MacroWindow::MacroWindow(QDomNode &xml_doc) : QObject() { isclosed = false; + mainwidget = NULL; this->lua = new LUA(this); - // Execute the recursive function with documentElement - recurser(xml_doc, NULL); + initMacro(xml_doc); + + if(mainwidget) mainwidget->show(); } MacroWindow::~MacroWindow() @@ -58,10 +62,9 @@ MacroWindow::~MacroWindow() delete lua; } -void MacroWindow::recurser(QDomNode xml_node, QWidget *parent) +void MacroWindow::initMacro(QDomNode &node) { - QWidget *widget = NULL; - QDomElement xml_elem = xml_node.toElement(); + QDomElement xml_elem = node.toElement(); if(xml_elem.tagName() == "macro") { // Assign the macro name and version to QStrings for use when comitting @@ -78,97 +81,24 @@ void MacroWindow::recurser(QDomNode xml_node, QWidget *parent) } else if(xml_elem.tagName() == "window") { Window *window = new Window(xml_elem, this); - widget = window; mainwidget = window; - } else if(xml_elem.tagName() == "frame") { - if(xml_elem.hasAttribute("caption")) { - GroupBox *frame = new GroupBox(xml_elem, this); - widget = frame; - } else { - Frame *frame = new Frame(xml_elem, this); - widget = frame; - } + QDomNodeList children = node.childNodes(); - } else if(xml_elem.tagName() == "label") { - Label *label = new Label(xml_elem, this); - widget = label; - - } else if(xml_elem.tagName() == "lineedit") { - LineEdit *lineedit = new LineEdit(xml_elem, this); - widgets.push_back(lineedit); - widget = lineedit; - - } else if(xml_elem.tagName() == "button") { - PushButton *pushbutton = new PushButton(xml_elem, this); - //connect(pushbutton, SIGNAL(act_continue()), main, SLOT(get_macro())); - connect(pushbutton, SIGNAL(act_commit()), this, SLOT(commit())); - connect(pushbutton, SIGNAL(act_reset()), this, SLOT(reset())); - connect(pushbutton, SIGNAL(act_cancel()), this, SLOT(cancel())); - connect(pushbutton, SIGNAL(act_continue(QString)), this, SLOT(cont(QString))); - widget = pushbutton; - - } else if(xml_elem.tagName() == "textedit") { - TextEdit *textedit = new TextEdit(xml_elem, this); - widgets.push_back(textedit); - widget = textedit; - - } else if(xml_elem.tagName() == "checkbox") { - CheckBox *checkbox = new CheckBox(xml_elem, this); - widgets.push_back(checkbox); - widget = checkbox; - - } else if(xml_elem.tagName() == "radiobuttons") { - RadioButtons *radiobuttons = new RadioButtons(xml_elem, this); - widgets.push_back(radiobuttons); - widget = radiobuttons; - //return; // Don't iterate children - - } else if(xml_elem.tagName() == "combobox") { - ComboBox *combobox = new ComboBox(xml_elem, this); - widgets.push_back(combobox); - widget = combobox; - //return; // Don't iterate children - - } else if(xml_elem.tagName() == "listbox") { - ListBox *listbox = new ListBox(xml_elem, this); - widgets.push_back(listbox); - widget = listbox; - //return; // Don't iterate children - } else if(xml_elem.tagName() == "multilist") { - - MultiList *multilist = new MultiList(xml_elem, this); - widgets.push_back(multilist); - if(parent) parent->layout()->addWidget(multilist); - - QDomNodeList children = xml_node.childNodes(); for (int i=0; iinputcontainer); - } - break; - } + widgets += widgetBuilder(child, mainwidget, this); } - - multilist->inputcontainer->show(); - multilist->show(); - return; // Don't iterate children + return; } - QDomNodeList children = xml_node.childNodes(); + QDomNodeList children = node.childNodes(); for (int i=0; ilayout()->addWidget(widget); - if(widget != NULL) widget->show(); } bool MacroWindow::doCommit() diff --git a/client/macrowindow.h b/client/macrowindow.h index 138c438..82853d8 100644 --- a/client/macrowindow.h +++ b/client/macrowindow.h @@ -60,8 +60,9 @@ public slots: void cont(QString name); private: + void initMacro(QDomNode &node); + bool doCommit(); - void recurser(QDomNode xml_node, QWidget *parent); QVector< Widget* > widgets; QString macro; QString version; diff --git a/client/widgetbuilder.cc b/client/widgetbuilder.cc new file mode 100644 index 0000000..8d23c0b --- /dev/null +++ b/client/widgetbuilder.cc @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * widgetbuilder.cc + * + * Wed Jun 18 08:03:04 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "widgetbuilder.h" +#include +#include "widgets.h" + +QVector< Widget* > widgetBuilder(QDomNode xml_node, QWidget *parent, MacroWindow *macrowindow) +{ + QVector< Widget* > widgets; + + QDomElement xml_elem = xml_node.toElement(); + + QWidget *widget = NULL; + if(xml_elem.tagName() == "frame") { + if(xml_elem.hasAttribute("caption")) { + GroupBox *frame = new GroupBox(xml_elem, macrowindow); + widget = frame; + } else { + Frame *frame = new Frame(xml_elem, macrowindow); + 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; + + } else if(xml_elem.tagName() == "button") { + PushButton *pushbutton = new PushButton(xml_elem, macrowindow); + //macrowindow->connect(pushbutton, SIGNAL(act_continue()), main, SLOT(get_macro())); + macrowindow->connect(pushbutton, SIGNAL(act_commit()), macrowindow, SLOT(commit())); + macrowindow->connect(pushbutton, SIGNAL(act_reset()), macrowindow, SLOT(reset())); + macrowindow->connect(pushbutton, SIGNAL(act_cancel()), macrowindow, SLOT(cancel())); + macrowindow->connect(pushbutton, SIGNAL(act_continue(QString)), macrowindow, SLOT(cont(QString))); + widget = pushbutton; + + } else if(xml_elem.tagName() == "textedit") { + TextEdit *textedit = new TextEdit(xml_elem, macrowindow); + widgets.push_back(textedit); + widget = textedit; + + } else if(xml_elem.tagName() == "checkbox") { + CheckBox *checkbox = new CheckBox(xml_elem, macrowindow); + widgets.push_back(checkbox); + widget = checkbox; + + } else if(xml_elem.tagName() == "radiobuttons") { + RadioButtons *radiobuttons = new RadioButtons(xml_elem, macrowindow); + widgets.push_back(radiobuttons); + widget = radiobuttons; + //return; // Don't iterate children + + } else if(xml_elem.tagName() == "combobox") { + ComboBox *combobox = new ComboBox(xml_elem, macrowindow); + widgets.push_back(combobox); + widget = combobox; + //return; // Don't iterate children + + } else if(xml_elem.tagName() == "listbox") { + ListBox *listbox = new ListBox(xml_elem, macrowindow); + widgets.push_back(listbox); + widget = listbox; + //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(parent != NULL && widget != NULL) parent->layout()->addWidget(widget); + if(widget != NULL) widget->show(); + + return widgets; // Don't iterate children + } + + QDomNodeList children = xml_node.childNodes(); + + for (int i=0; ilayout()->addWidget(widget); + if(widget != NULL) widget->show(); + + return widgets; +} diff --git a/client/widgetbuilder.h b/client/widgetbuilder.h new file mode 100644 index 0000000..f3b7369 --- /dev/null +++ b/client/widgetbuilder.h @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * widgetbuilder.h + * + * Wed Jun 18 08:03:04 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __PRACRO_WIDGETBUILDER_H__ +#define __PRACRO_WIDGETBUILDER_H__ + +#include +#include +#include +#include "widgets/widget.h" +#include "macrowindow.h" + +QVector< Widget* > widgetBuilder(QDomNode xml_node, QWidget *parent, MacroWindow *macrowindow); + +#endif/*__PRACRO_WIDGETBUILDER_H__*/ diff --git a/client/widgets/multilist.cc b/client/widgets/multilist.cc index 73a9747..99772dd 100644 --- a/client/widgets/multilist.cc +++ b/client/widgets/multilist.cc @@ -31,79 +31,78 @@ #include #include +#include "widgetbuilder.h" +#include "formatparser.h" + MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow) : QFrame(), Widget(node, macrowindow) { - /* - QDomElement elem = node.toElement(); - - if(elem.hasAttribute("width")) { - //resize(elem.attribute("width").toInt(), height()); - setMinimumWidth(elem.attribute("width").toInt()); - } - - if(elem.hasAttribute("height")) { - //resize(width(), elem.attribute("height").toInt()); - setMinimumHeight(elem.attribute("height").toInt()); - } - */ - QGridLayout *layout = new QGridLayout(); setLayout(layout); QWidget *inputbox = new QWidget(this); inputbox->setContentsMargins(0,0,0,0); - inputbox->setLayout(new QHBoxLayout()); - inputbox->layout()->setContentsMargins(0,0,0,0); layout->addWidget(inputbox, 0, 0, Qt::AlignTop); QPushButton *add = new QPushButton(this); - add->setText("Add"); + connect(add, SIGNAL(clicked()), this, SLOT(add())); + add->setText("+"); layout->addWidget(add, 0, 1, Qt::AlignTop); - // QFrame *listbox = new QFrame(this); - // listbox->setLayout(new QHBoxLayout()); - // layout()->addWidget(listbox); - list = new QListWidget(this); layout->addWidget(list, 1, 0, Qt::AlignTop); QPushButton *rem = new QPushButton(this); - rem->setText("Remove"); + connect(rem, SIGNAL(clicked()), this, SLOT(remove())); + rem->setText("-"); layout->addWidget(rem, 1, 1, Qt::AlignTop); - inputcontainer = inputbox; - - /* + QDomElement elem = node.toElement(); if(elem.hasAttribute("layout")) { if(elem.attribute("layout") == "hbox") { QHBoxLayout *layout = new QHBoxLayout(); - setLayout(layout); + inputbox->setLayout(layout); } else if (elem.attribute("layout") == "vbox") { QVBoxLayout *layout = new QVBoxLayout(); - setLayout(layout); + inputbox->setLayout(layout); } + } else { + QHBoxLayout *layout = new QHBoxLayout(); + inputbox->setLayout(layout); } - + + inputbox->layout()->setContentsMargins(0,0,0,0); + QDomNodeList children = node.childNodes(); - + for (int i=0; i::iterator i = widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + if(format != "") format += ", "; + format += "${" + w->getName() + "}"; + i++; } - RadioButton *radiobutton = new RadioButton(child, radio_bool); + } - // Create radiobutton from child, insert in this - layout()->addWidget(radiobutton); - radiobutton_list.push_back(radiobutton); + if(elem.hasAttribute("width")) { + setMinimumWidth(elem.attribute("width").toInt()); } - */ + if(elem.hasAttribute("height")) { + setMinimumHeight(elem.attribute("height").toInt()); + } } void MultiList::changed() @@ -112,10 +111,37 @@ void MultiList::changed() QString MultiList::getValue() { - return ""; + QString values; + + QList items = list->findItems("*", Qt::MatchWildcard); + QList::iterator i = items.begin(); + while(i != items.end()) { + QListWidgetItem *item = *i; + if(values != "") values += "\n"; + values += item->text(); + i++; + } + + return values; +} + +void MultiList::setValue(QString values) +{ + QString value; + int idx = 0; + do { + value = values.section('\n', idx, idx); + if(value != "") list->addItem(value); + idx++; + } while(value != ""); +} + +void MultiList::remove() +{ + list->takeItem(list->currentRow()); } -void MultiList::setValue(QString value) +void MultiList::add() { - value = value; + list->addItem(format_parser(format, widgets)); } diff --git a/client/widgets/multilist.h b/client/widgets/multilist.h index 6057677..cee6ccb 100644 --- a/client/widgets/multilist.h +++ b/client/widgets/multilist.h @@ -32,6 +32,7 @@ #include #include +#include class MultiList : public QFrame, public Widget { @@ -39,15 +40,18 @@ Q_OBJECT public: MultiList(QDomNode &node, MacroWindow *macrowindow); - QWidget *inputcontainer; - public slots: void changed(); QString getValue(); void setValue(QString value); + void remove(); + void add(); + private: QListWidget *list; + QVector< Widget* > widgets; + QString format; }; #endif/*__PRACRO_MULTILIST_H__*/ diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc index 25d37f6..dafe4b7 100644 --- a/client/widgets/widget.cc +++ b/client/widgets/widget.cc @@ -52,7 +52,6 @@ Widget::Widget(QDomNode &node, MacroWindow *macrowindow) } else { hasregexpvalidator = false; } - } QString Widget::getName() -- cgit v1.2.3