changeset 14:315e6988952a

Only add entries that do not start with # to filter
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 14 Apr 2015 17:25:15 +0200
parents 06c9b37d1e1b
children 43a36293f495
files src/filterwidget.cpp src/filterwidget.h
diffstat 2 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/filterwidget.cpp	Tue Apr 14 13:43:43 2015 +0200
+++ b/src/filterwidget.cpp	Tue Apr 14 17:25:15 2015 +0200
@@ -28,8 +28,18 @@
     QAbstractItemModel *newSource = mModel->sourceModel();
     Q_ASSERT(newSource);
     mCombo->clear();
+    mColFilterMap.clear();
+    int addedItems = 0;
     for (int i=0; i < newSource->columnCount(); i++) {
-        mCombo->addItem(newSource->headerData(i, Qt::Horizontal).toString());
+        QString entry = newSource->headerData(i, Qt::Horizontal).toString();
+        if (!entry.startsWith("#")) {
+            mCombo->addItem(entry);
+            mColFilterMap.insert(addedItems++, i);
+        } else {
+            QString shortended = entry.remove(0,1);
+            // TODO this does not work as expected
+            newSource->setHeaderData(i, Qt::Horizontal, shortended);
+        }
     }
 }
 
@@ -38,7 +48,9 @@
     if (filterText.size() < 1) {
         return;
     }
-    mModel->setFilterKeyColumn(mCombo->currentIndex());
+    qDebug() << "Filter on Column: " << mColFilterMap.value(mCombo->currentIndex());
+    qDebug() << "Instead of: " << mCombo->currentIndex();
+    mModel->setFilterKeyColumn(mColFilterMap.value(mCombo->currentIndex()));
     mModel->setFilterWildcard(filterText);
 }
 
--- a/src/filterwidget.h	Tue Apr 14 13:43:43 2015 +0200
+++ b/src/filterwidget.h	Tue Apr 14 17:25:15 2015 +0200
@@ -7,6 +7,7 @@
  * See LICENSE.txt for details.
  */
 #include <QWidget>
+#include <QMap>
 
 class QSortFilterProxyModel;
 class QComboBox;
@@ -32,5 +33,7 @@
     QSortFilterProxyModel *mModel;
     QComboBox *mCombo;
     QLineEdit *mEditLine;
+    /* Maps the combo index to the model col index */
+    QMap<int, int> mColFilterMap;
 };
 #endif // FILTERWIDGET_H
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)