summaryrefslogtreecommitdiff
path: root/client/widgets/multilist.cc
diff options
context:
space:
mode:
authordeva <deva>2008-06-18 11:03:34 +0000
committerdeva <deva>2008-06-18 11:03:34 +0000
commit8c3994b02e3a0cf81ead56c8dcfefb67be078328 (patch)
tree7bf98b5b9438e0f64725bfc12a34b98c20583116 /client/widgets/multilist.cc
parentb681594b7e4f9a5375b555b152d661581c600a96 (diff)
Restructured widget building, completed inital version of MultiList with format string parsing, db commiting and rereading.
Diffstat (limited to 'client/widgets/multilist.cc')
-rw-r--r--client/widgets/multilist.cc112
1 files changed, 69 insertions, 43 deletions
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 <QGridLayout>
#include <QPushButton>
+#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<children.count();i++) {
QDomNode child = children.at(i);
- QDomElement radio_elem = child.toElement();
- bool radio_bool = false;
- if(elem.hasAttribute("value")) {
- if(elem.attribute("value") == radio_elem.attribute("value")) {
- radio_bool = true;
- }
+ widgets += widgetBuilder(child, inputbox, macrowindow);
+ }
+
+ if(elem.hasAttribute("value")) {
+ setValue(elem.attribute("value"));
+ }
+
+ if(elem.hasAttribute("format")) {
+ format = elem.attribute("format");
+ } else {
+ QVector< Widget* >::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<QListWidgetItem *> items = list->findItems("*", Qt::MatchWildcard);
+ QList<QListWidgetItem *>::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));
}