diff --git a/src/libs/vmisc/vtablesearch.cpp b/src/libs/vmisc/vtablesearch.cpp index f683a2b8b..82df0700e 100644 --- a/src/libs/vmisc/vtablesearch.cpp +++ b/src/libs/vmisc/vtablesearch.cpp @@ -29,6 +29,7 @@ #include "vtablesearch.h" #include +#include #include #include #include @@ -92,6 +93,40 @@ void VTableSearch::ShowNext(int newIndex) } } +QList VTableSearch::FindTableItems(QString term) +{ + if (term.isEmpty()) + { + return QList(); + } + + if (term.startsWith("/")) + { + QRegularExpression qre("^/(?[^/]+)/(?.+)$"); + QScopedPointer match(new QRegularExpressionMatch()); + if (!term.contains(qre, match.data())) + { + return QList(); + } + + auto searchType = match->capturedRef("searchType"); + auto searchString = match->capturedRef("searchString"); + if (searchType == "r") + { + QString reSearchString = ".*" % searchString % ".*"; + return table->findItems(reSearchString, Qt::MatchRegExp); + } + else + { + return QList(); + } + } + else + { + return table->findItems(term, Qt::MatchContains); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VTableSearch::Find(const QString &term) { @@ -99,24 +134,21 @@ void VTableSearch::Find(const QString &term) Clear(); - if (not term.isEmpty()) + searchList = FindTableItems(term); + + if (not searchList.isEmpty()) { - searchList = table->findItems(term, Qt::MatchContains); - - if (not searchList.isEmpty()) + for (auto item : qAsConst(searchList)) { - for (auto item : qAsConst(searchList)) - { - item->setBackground(Qt::yellow); - } - - searchIndex = 0; - QTableWidgetItem *item = searchList.at(searchIndex); - item->setBackground(Qt::red); - table->scrollToItem(item); - - emit HasResult(true); + item->setBackground(Qt::yellow); } + + searchIndex = 0; + QTableWidgetItem *item = searchList.at(searchIndex); + item->setBackground(Qt::red); + table->scrollToItem(item); + + emit HasResult(true); } } @@ -195,20 +227,15 @@ void VTableSearch::RefreshList(const QString &term) { SCASSERT(table != nullptr) - if (term.isEmpty()) - { - return; - } - - searchList = table->findItems(term, Qt::MatchContains); - - for (auto item : qAsConst(searchList)) - { - item->setBackground(Qt::yellow); - } + searchList = FindTableItems(term); if (not searchList.isEmpty()) { + for (auto item : qAsConst(searchList)) + { + item->setBackground(Qt::yellow); + } + if (searchIndex < 0) { searchIndex = searchList.size() - 1; diff --git a/src/libs/vmisc/vtablesearch.h b/src/libs/vmisc/vtablesearch.h index 243f4a44d..18c1eba6d 100644 --- a/src/libs/vmisc/vtablesearch.h +++ b/src/libs/vmisc/vtablesearch.h @@ -60,6 +60,7 @@ private: void Clear(); void ShowNext(int newIndex); + QList FindTableItems(QString term); }; #endif // VTABLESEARCH_H