summaryrefslogtreecommitdiffstats
path: root/src/gui/combobox.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:17:32 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:17:32 +0000
commite38d2351b83fa65c66ccde443777647ef5cb6cff (patch)
tree1897fc20e9f73a81c520a5b9f76f8ed042124883 /src/gui/combobox.cpp
downloadtellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.tar.gz
tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.zip
Added KDE3 version of Tellico
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/gui/combobox.cpp')
-rw-r--r--src/gui/combobox.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/gui/combobox.cpp b/src/gui/combobox.cpp
new file mode 100644
index 0000000..1aff29b
--- /dev/null
+++ b/src/gui/combobox.cpp
@@ -0,0 +1,71 @@
+/***************************************************************************
+ copyright : (C) 2001-2006 by Robby Stephenson
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of version 2 of the GNU General Public License as *
+ * published by the Free Software Foundation; *
+ * *
+ ***************************************************************************/
+
+#include "combobox.h"
+
+#include <kdebug.h>
+
+using Tellico::GUI::ComboBox;
+
+ComboBox::ComboBox(QWidget* parent_) : KComboBox(parent_) {
+ setEditable(false);
+}
+
+void ComboBox::clear() {
+ KComboBox::clear();
+ m_data.clear();
+}
+
+void ComboBox::insertItem(const QString& s_, const QVariant& t_, int idx_/* =-1 */) {
+ KComboBox::insertItem(s_, idx_);
+ if(idx_ < 0) {
+ m_data.push_back(t_);
+ } else {
+ while(idx_ > static_cast<int>(m_data.count())) {
+ m_data.push_back(QVariant());
+ }
+ m_data.insert(m_data.at(idx_), t_);
+ }
+}
+
+void ComboBox::insertItems(const QStringList& s_, const QValueList<QVariant>& t_, int idx_ /*=-1*/) {
+ if(s_.count() != t_.count()) {
+ kdWarning() << "ComboBox::insertItems() - must have equal number of items in list!" << endl;
+ return;
+ }
+
+ for(uint i = 0; i < s_.count(); ++i) {
+ insertItem(s_[i], t_[i], idx_+i);
+ }
+}
+
+const QVariant& ComboBox::currentData() const {
+ return data(currentItem());
+}
+
+const QVariant& ComboBox::data(uint idx_) const {
+ if(idx_ >= m_data.count()) {
+ static QVariant t; // inescapable
+ return t;
+ }
+ return m_data[idx_];
+}
+
+void ComboBox::setCurrentData(const QVariant& data_) {
+ for(uint i = 0; i < m_data.count(); ++i) {
+ if(m_data[i] == data_) {
+ setCurrentItem(i);
+ break;
+ }
+ }
+}