diff --git a/plugins/gui/include/gui/context_manager_widget/models/context_table_proxy_model.h b/plugins/gui/include/gui/context_manager_widget/models/context_table_proxy_model.h index db5f76a73e7..a94617e3cc9 100644 --- a/plugins/gui/include/gui/context_manager_widget/models/context_table_proxy_model.h +++ b/plugins/gui/include/gui/context_manager_widget/models/context_table_proxy_model.h @@ -82,7 +82,5 @@ namespace hal */ bool lessThan(const QModelIndex& left, const QModelIndex& right) const override; - private: - QString mSearchString; }; } // namespace hal diff --git a/plugins/gui/include/gui/module_dialog/module_select_model.h b/plugins/gui/include/gui/module_dialog/module_select_model.h index e09ab2aa614..4b67872827e 100644 --- a/plugins/gui/include/gui/module_dialog/module_select_model.h +++ b/plugins/gui/include/gui/module_dialog/module_select_model.h @@ -133,11 +133,12 @@ namespace hal { void setSortMechanism(gui_utility::mSortMechanism sortMechanism); void searchTextChanged(const QString& txt); void startSearch(QString text, int options) override; + bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const; protected: static bool lessThan(const QColor& a, const QColor& b); bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override; - bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override; + private: gui_utility::mSortMechanism mSortMechanism; diff --git a/plugins/gui/include/gui/searchbar/search_proxy_model.h b/plugins/gui/include/gui/searchbar/search_proxy_model.h index 7effd6d8a97..6e4167c7c93 100644 --- a/plugins/gui/include/gui/searchbar/search_proxy_model.h +++ b/plugins/gui/include/gui/searchbar/search_proxy_model.h @@ -36,6 +36,15 @@ namespace hal public: SearchProxyModel(QObject* parent = nullptr); + /** + * @return List of QString matching the corresponding column header. + */ + virtual QList getColumnNames(); + + public Q_SLOTS: + virtual void startSearch(QString text, int options) = 0; + + protected: /** * @brief Check if a string matches the SearchOptions. * @@ -48,16 +57,21 @@ namespace hal */ bool isMatching(const QString searchString, const QString stringToCheck) const; - /** - * @return List of QString matching the corresponding column header. + * @brief Should be called inside filterAcceptsRow function and returns true if the source_row, source_parent matches given SearchOptions + * + * This function checks whether a given `source_row` should be shown + * based on given `search options` . + * + * @param sourceRow The row index in the source model to be checked. + * @param sourceParent The QModelIndex representing the parent of the source model. + * @param startIndex The index of the first column to start checking. + * @param endIndex The index of the last column to stop checking. + * @param offset The offset to apply to the column indices based on search options if specific columns are checked. + * + * @return True if the row contains a matching entry, otherwise false. */ - virtual QList getColumnNames(); - - public Q_SLOTS: - virtual void startSearch(QString text, int options) = 0; - - protected: + bool checkRow(int sourceRow, const QModelIndex& sourceParent, int startIndex, int endIndex, int offset = 0) const; SearchOptions mSearchOptions; QString mSearchString; }; diff --git a/plugins/gui/src/context_manager_widget/models/context_table_proxy_model.cpp b/plugins/gui/src/context_manager_widget/models/context_table_proxy_model.cpp index 42d65aed265..e75369d2d94 100644 --- a/plugins/gui/src/context_manager_widget/models/context_table_proxy_model.cpp +++ b/plugins/gui/src/context_manager_widget/models/context_table_proxy_model.cpp @@ -15,29 +15,7 @@ namespace hal { //TODO somehow the program crashes with segfault if this method ever returns a false at the initial start - - QList columns = mSearchOptions.getColumns(); - if(columns.empty()){ - //iterate over each column - for(int index = 0; index < 2; index++){ - QString entry = sourceModel()->index(source_row, index, source_parent).data().toString(); - if(isMatching(mSearchString, entry)) - { - return true; - } - } - return false; - }else - { - for(int index : columns) - { - QString entry = sourceModel()->index(source_row, index, source_parent).data().toString(); - if(isMatching(mSearchString, entry)) - return true; - } - return false; - } - + return checkRow(source_row, source_parent, 0, 1); } bool ContextTableProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/plugins/gui/src/grouping/grouping_proxy_model.cpp b/plugins/gui/src/grouping/grouping_proxy_model.cpp index 2f0de288586..eab30485bd0 100644 --- a/plugins/gui/src/grouping/grouping_proxy_model.cpp +++ b/plugins/gui/src/grouping/grouping_proxy_model.cpp @@ -1,3 +1,7 @@ + + + + #include "gui/grouping/grouping_proxy_model.h" #include "gui/gui_globals.h" @@ -11,27 +15,7 @@ namespace hal bool GroupingProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { - 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 - { - for(int index : columns) - { - QString entry = sourceModel()->index(sourceRow, index, sourceParent).data().toString(); - if(isMatching(mSearchString, entry)) - return true; - } - return false; - } - + return checkRow(sourceRow, sourceParent, 0, 2); } bool GroupingProxyModel::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const diff --git a/plugins/gui/src/module_dialog/gate_dialog.cpp b/plugins/gui/src/module_dialog/gate_dialog.cpp index 3148b637a5d..b336ef2c678 100644 --- a/plugins/gui/src/module_dialog/gate_dialog.cpp +++ b/plugins/gui/src/module_dialog/gate_dialog.cpp @@ -1,3 +1,4 @@ + #include "gui/module_dialog/gate_dialog.h" #include "gui/module_dialog/module_select_model.h" #include "gui/gui_globals.h" diff --git a/plugins/gui/src/module_dialog/gate_select_model.cpp b/plugins/gui/src/module_dialog/gate_select_model.cpp index d130c8231da..42763e840ec 100644 --- a/plugins/gui/src/module_dialog/gate_select_model.cpp +++ b/plugins/gui/src/module_dialog/gate_select_model.cpp @@ -1,3 +1,4 @@ + #include "gui/module_dialog/gate_select_model.h" #include "gui/content_manager/content_manager.h" @@ -165,27 +166,7 @@ namespace hal bool GateSelectProxy::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const { - QList columns = mSearchOptions.getColumns(); - if(columns.empty()){ - //iterate over each column - for(int index = 0; index < 3; index++){ - QString entry = sourceModel()->index(source_row, index, source_parent).data().toString(); - if(isMatching(mSearchString, entry)) - { - return true; - } - } - return false; - }else - { - for(int index : columns) - { - QString entry = sourceModel()->index(source_row, index, source_parent).data().toString(); - if(isMatching(mSearchString, entry)) - return true; - } - return false; - } + return checkRow(source_row, source_parent, 0, 2); } //---------------- PICKER ----------------------------------------- diff --git a/plugins/gui/src/module_dialog/module_select_model.cpp b/plugins/gui/src/module_dialog/module_select_model.cpp index c6204b5e28d..df8bd1e3bf5 100644 --- a/plugins/gui/src/module_dialog/module_select_model.cpp +++ b/plugins/gui/src/module_dialog/module_select_model.cpp @@ -201,7 +201,7 @@ namespace hal setFilterRegularExpression(txt); } void ModuleSelectProxy::startSearch(QString text, int options) - { + { mSearchString = text; mSearchOptions = SearchOptions(options); invalidateFilter(); @@ -209,28 +209,7 @@ namespace hal bool ModuleSelectProxy::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const { - QList columns = mSearchOptions.getColumns(); - if(columns.empty()){ - //iterate over each column - for(int index = 1; index < 4; index++){ - QString entry = sourceModel()->index(source_row, index, source_parent).data().toString(); - if(isMatching(mSearchString, entry)) - { - return true; - } - } - return false; - }else - { - for(int index : columns) - { - //offset the index by one to account for missing color column - QString entry = sourceModel()->index(source_row, index + 1, source_parent).data().toString(); - if(isMatching(mSearchString, entry)) - return true; - } - return false; - } + return checkRow(source_row, source_parent, 1, 3, 1); } //---------------- EXCLUDE ---------------------------------------- diff --git a/plugins/gui/src/searchbar/search_proxy_model.cpp b/plugins/gui/src/searchbar/search_proxy_model.cpp index 06bd8b65fc9..4d20186c179 100644 --- a/plugins/gui/src/searchbar/search_proxy_model.cpp +++ b/plugins/gui/src/searchbar/search_proxy_model.cpp @@ -41,4 +41,30 @@ namespace hal { return list; } + bool SearchProxyModel::checkRow(int sourceRow, const QModelIndex& sourceParent, int startIndex, int endIndex, int offset) const + { + QList columns = mSearchOptions.getColumns(); + if(columns.empty()){ + //iterate over each column + for(int index = startIndex; index <= endIndex; index++){ + QString entry = sourceModel()->index(sourceRow, index, sourceParent).data().toString(); + if(isMatching(mSearchString, entry)) + { + return true; + } + } + return false; + }else + { + for(int index : columns) + { + QString entry = sourceModel()->index(sourceRow, index + offset, sourceParent).data().toString(); + if(isMatching(mSearchString, entry)) + return true; + } + return false; + } + + } + } diff --git a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_proxy.cpp b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_proxy.cpp index ffc379039fb..f8e32751ea8 100644 --- a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_proxy.cpp +++ b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_proxy.cpp @@ -14,27 +14,7 @@ namespace hal bool SelectionTreeProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const { - QList columns = mSearchOptions.getColumns(); - if(columns.empty()){ - //iterate over each column - for(int index = 0; index < 3; index++){ - QString entry = sourceModel()->index(source_row, index, source_parent).data().toString(); - if(isMatching(mSearchString, entry)) - { - return true; - } - } - return false; - }else - { - for(int index : columns) - { - QString entry = sourceModel()->index(source_row, index, source_parent).data().toString(); - if(isMatching(mSearchString, entry)) - return true; - } - return false; - } + return checkRow(source_row, source_parent, 0, 2); } bool SelectionTreeProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const