# HG changeset patch # User Andre Heinecke # Date 1429025115 -7200 # Node ID 315e6988952af29f80f1b13ab61ca46d5dc58bf0 # Parent 06c9b37d1e1be79cea596aeafe599eb96dec75f2 Only add entries that do not start with # to filter diff -r 06c9b37d1e1b -r 315e6988952a src/filterwidget.cpp --- 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); } diff -r 06c9b37d1e1b -r 315e6988952a src/filterwidget.h --- 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 +#include class QSortFilterProxyModel; class QComboBox; @@ -32,5 +33,7 @@ QSortFilterProxyModel *mModel; QComboBox *mCombo; QLineEdit *mEditLine; + /* Maps the combo index to the model col index */ + QMap mColFilterMap; }; #endif // FILTERWIDGET_H