From 5cd4f2a6617e9f92e797eb86ca3555b94b5116ea Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Fri, 16 Nov 2007 10:40:23 -0500 Subject: [PATCH] ENH: more robust search filter. --- Source/QtDialog/QCMakeCacheView.cxx | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx index 7f3d40bdd7..5505644423 100644 --- a/Source/QtDialog/QCMakeCacheView.cxx +++ b/Source/QtDialog/QCMakeCacheView.cxx @@ -31,6 +31,25 @@ static QRegExp AdvancedRegExp[2] = { QRegExp("(false)"), QRegExp("(true|false)") }; +// filter for searches +class QCMakeSearchFilter : public QSortFilterProxyModel +{ +public: + QCMakeSearchFilter(QObject* o) : QSortFilterProxyModel(o) {} +protected: + bool filterAcceptsRow(int row, const QModelIndex& p) const + { + // accept row if either column matches + QModelIndex idx0 = this->sourceModel()->index(row, 0, p); + QModelIndex idx1 = this->sourceModel()->index(row, 1, p); + QString str0 = this->sourceModel()->data(idx0).toString(); + QString str1 = this->sourceModel()->data(idx1).toString(); + + return str0.contains(this->filterRegExp()) || + str1.contains(this->filterRegExp()); + } +}; + QCMakeCacheView::QCMakeCacheView(QWidget* p) : QTableView(p), Init(false) { @@ -41,12 +60,9 @@ QCMakeCacheView::QCMakeCacheView(QWidget* p) this->AdvancedFilter->setFilterRole(QCMakeCacheModel::AdvancedRole); this->AdvancedFilter->setFilterRegExp(AdvancedRegExp[0]); this->AdvancedFilter->setDynamicSortFilter(true); - this->SearchFilter = new QSortFilterProxyModel(this); + this->SearchFilter = new QCMakeSearchFilter(this); this->SearchFilter->setSourceModel(this->AdvancedFilter); this->SearchFilter->setFilterCaseSensitivity(Qt::CaseInsensitive); -#if QT_VERSION >= 0x040300 // breaks search in Qt 4.2 - this->SearchFilter->setFilterKeyColumn(-1); // all columns -#endif this->SearchFilter->setDynamicSortFilter(true); this->setModel(this->SearchFilter);