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/widgets/multilist.cc | 112 +++++++++++++++++++++++++++----------------- client/widgets/multilist.h | 8 +++- client/widgets/widget.cc | 1 - 3 files changed, 75 insertions(+), 46 deletions(-) (limited to 'client/widgets') 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