diff options
author | senator <senator> | 2007-10-02 10:08:09 +0000 |
---|---|---|
committer | senator <senator> | 2007-10-02 10:08:09 +0000 |
commit | 9910c8962ab813ab7d9a04609b689e1d9ae038e0 (patch) | |
tree | 5ca422f7c3e4cfffed3f57d6201f75ed10986578 /client/widgets/combobox.cc | |
parent | 4cbb885daf4ce4a4fb9827c5d6b67e9f82f730d3 (diff) |
selectable entries now uses xml items correctly
Diffstat (limited to 'client/widgets/combobox.cc')
-rw-r--r-- | client/widgets/combobox.cc | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/client/widgets/combobox.cc b/client/widgets/combobox.cc index 5499d09..22efc96 100644 --- a/client/widgets/combobox.cc +++ b/client/widgets/combobox.cc @@ -2,7 +2,7 @@ /*************************************************************************** * combobox.cc * - * Wed Jul 18 09:39:40 CEST 2007 + * Wed Jul 18 10:35:52 CEST 2007 * Copyright 2007 Bent Bisballe Nyeng, Lars Bisballe Jensen and Peter Skaarup * deva@aasimon.org, elsenator@gmail.com and piparum@piparum.dk ****************************************************************************/ @@ -25,14 +25,45 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "combobox.h" +#include <QDomNodeList> ComboBox::ComboBox(QDomNode node) : QComboBox(), Widget(node) { QDomElement elem = node.toElement(); + + if(elem.hasAttribute("width")) { + resize(elem.attribute("width").toInt(), height()); + } + + if(elem.hasAttribute("height")) { + resize(width(), elem.attribute("height").toInt()); + } + + QDomNodeList children = node.childNodes(); + int default_found = 0; + + for (int i=0; i<children.count();i++) { + QDomNode child = children.at(i); + QDomElement combo_elem = child.toElement(); + + if(combo_elem.hasAttribute("caption") && combo_elem.hasAttribute("value")) { + // insert item into current combobox + addItem(combo_elem.attribute("caption"), combo_elem.attribute("value")); + if(elem.attribute("value") == combo_elem.attribute("value")) { + setCurrentIndex(count() - 1); + default_found = 1; + } + } else { + printf("XML Error!!! Combobox item is missing one or more attributes...\n"); + } + } + if(default_found == 0) setCurrentIndex(-1); // -1 is default for none selected } QString ComboBox::getValue() { - return "combobox"; + QString value = "none"; + if(currentIndex() != -1) value = itemData(currentIndex()).toString(); + return value; } |