diff --git a/plugins/gui/include/gui/grouping/grouping_proxy_model.h b/plugins/gui/include/gui/grouping/grouping_proxy_model.h index ecf4217f6db..d820b84f6a9 100644 --- a/plugins/gui/include/gui/grouping/grouping_proxy_model.h +++ b/plugins/gui/include/gui/grouping/grouping_proxy_model.h @@ -28,6 +28,7 @@ #include "gui/gui_utils/sort.h" #include +#include namespace hal { @@ -39,7 +40,7 @@ namespace hal * GroupingTableModel (source model) to support data filtering. * It is used to provide a search bar (CTRL+F) for groupings. */ - class GroupingProxyModel : public QSortFilterProxyModel + class GroupingProxyModel : public SearchProxyModel { Q_OBJECT @@ -64,6 +65,7 @@ namespace hal * @param sortMechanism - the new sorting mechanism */ void setSortMechanism(gui_utility::mSortMechanism sortMechanism); + void startSearch(QString text, int options) override; protected: /** diff --git a/plugins/gui/include/gui/searchbar/search_proxy_model.h b/plugins/gui/include/gui/searchbar/search_proxy_model.h index a3d8b23172c..7effd6d8a97 100644 --- a/plugins/gui/include/gui/searchbar/search_proxy_model.h +++ b/plugins/gui/include/gui/searchbar/search_proxy_model.h @@ -59,6 +59,7 @@ namespace hal protected: SearchOptions mSearchOptions; + QString mSearchString; }; } diff --git a/plugins/gui/src/grouping/grouping_manager_widget.cpp b/plugins/gui/src/grouping/grouping_manager_widget.cpp index bb03553ecef..0f03c513f3f 100644 --- a/plugins/gui/src/grouping/grouping_manager_widget.cpp +++ b/plugins/gui/src/grouping/grouping_manager_widget.cpp @@ -96,8 +96,9 @@ namespace hal mContentLayout->addWidget(mSearchbar); mSearchbar->hide(); + mSearchbar->setColumnNames(mProxyModel->getColumnNames()); - connect(mSearchbar, &Searchbar::textEdited, this, &GroupingManagerWidget::filter); + connect(mSearchbar, &Searchbar::triggerNewSearch, mProxyModel, &GroupingProxyModel::startSearch); connect(mSearchbar, &Searchbar::textEdited, this, &GroupingManagerWidget::updateSearchIcon); connect(mNewGroupingAction, &QAction::triggered, this, &GroupingManagerWidget::handleCreateGroupingClicked); diff --git a/plugins/gui/src/grouping/grouping_proxy_model.cpp b/plugins/gui/src/grouping/grouping_proxy_model.cpp index 62ec6ceacc5..76c847693fa 100644 --- a/plugins/gui/src/grouping/grouping_proxy_model.cpp +++ b/plugins/gui/src/grouping/grouping_proxy_model.cpp @@ -4,25 +4,36 @@ namespace hal { - GroupingProxyModel::GroupingProxyModel(QObject* parent) : QSortFilterProxyModel(parent), mSortMechanism(gui_utility::mSortMechanism::natural) + GroupingProxyModel::GroupingProxyModel(QObject* parent) : SearchProxyModel(parent), mSortMechanism(gui_utility::mSortMechanism::natural) { + } bool GroupingProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { - if(filterRegularExpression().pattern().isEmpty()) - return true; - QModelIndex source_index = sourceModel()->index(sourceRow, filterKeyColumn(), sourceParent); - if(source_index.isValid()) + QList columns = mSearchOptions.getColumns(); + if(columns.empty()){ + //iterate over each column + for(int index = 0; index < 3; index++){ + QString entry = sourceModel()->index(sourceRow, index, sourceParent).data().toString(); + if(isMatching(mSearchString, entry)) + return true; + + } + return false; + }else { - if (sourceModel()->data(source_index, filterRole()).toString().contains(filterRegularExpression())) - return true; - else - return false; + for(int index : columns) + { + QString entry = sourceModel()->index(sourceRow, index, sourceParent).data().toString(); + qInfo() << "Entry: " << entry; + if(isMatching(mSearchString, entry)) + return true; + } + return false; } - return true; } bool GroupingProxyModel::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const @@ -57,4 +68,10 @@ namespace hal mSortMechanism = sortMechanism; invalidate(); } + void GroupingProxyModel::startSearch(QString text, int options) + { + mSearchString = text; + mSearchOptions = SearchOptions(options); + invalidateFilter(); + } } diff --git a/plugins/gui/src/grouping/grouping_table_model.cpp b/plugins/gui/src/grouping/grouping_table_model.cpp index da31a7e2359..f28b0179f7a 100644 --- a/plugins/gui/src/grouping/grouping_table_model.cpp +++ b/plugins/gui/src/grouping/grouping_table_model.cpp @@ -147,6 +147,8 @@ namespace hal { return gte.name(); case 1: return gte.id(); + case 2: + return gte.color().name(); } default: break; diff --git a/plugins/gui/src/searchbar/search_proxy_model.cpp b/plugins/gui/src/searchbar/search_proxy_model.cpp index 31f0df7e707..06bd8b65fc9 100644 --- a/plugins/gui/src/searchbar/search_proxy_model.cpp +++ b/plugins/gui/src/searchbar/search_proxy_model.cpp @@ -13,7 +13,7 @@ namespace hal { } bool SearchProxyModel::isMatching(const QString searchString, const QString stringToCheck) const { - if(!mSearchOptions.isExactMatch()){ + if(!mSearchOptions.isExactMatch() && !mSearchOptions.isRegularExpression()){ //check if stringToCheck contains the searchString return stringToCheck.contains(searchString, mSearchOptions.isCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive); } @@ -24,9 +24,6 @@ namespace hal { } else if(mSearchOptions.isRegularExpression()){ //checks if the stringToCheck matches the regEx given by searchString - - //TODO regEx does not work - auto regEx = QRegularExpression(searchString, mSearchOptions.isCaseSensitive() ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption); return regEx.match(stringToCheck).hasMatch(); }