Add ability to search measurements by regex.
You do this by prepending "/r/" to the front of the search string. This makes it much easier to find measurements when one has a lot of measurements for a given individual. I also refactored that common table search code to consolidate this functionality and make it easier to add other search methods in the future. --HG-- branch : develop
This commit is contained in:
parent
42b00c5c58
commit
71f7f40875
|
@ -29,6 +29,7 @@
|
|||
#include "vtablesearch.h"
|
||||
|
||||
#include <QPalette>
|
||||
#include <QStringBuilder>
|
||||
#include <QTableWidget>
|
||||
#include <QTableWidgetItem>
|
||||
#include <Qt>
|
||||
|
@ -92,6 +93,40 @@ void VTableSearch::ShowNext(int newIndex)
|
|||
}
|
||||
}
|
||||
|
||||
QList<QTableWidgetItem *> VTableSearch::FindTableItems(QString term)
|
||||
{
|
||||
if (term.isEmpty())
|
||||
{
|
||||
return QList<QTableWidgetItem *>();
|
||||
}
|
||||
|
||||
if (term.startsWith("/"))
|
||||
{
|
||||
QRegularExpression qre("^/(?<searchType>[^/]+)/(?<searchString>.+)$");
|
||||
QScopedPointer<QRegularExpressionMatch> match(new QRegularExpressionMatch());
|
||||
if (!term.contains(qre, match.data()))
|
||||
{
|
||||
return QList<QTableWidgetItem *>();
|
||||
}
|
||||
|
||||
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<QTableWidgetItem *>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return table->findItems(term, Qt::MatchContains);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTableSearch::Find(const QString &term)
|
||||
{
|
||||
|
@ -99,9 +134,7 @@ void VTableSearch::Find(const QString &term)
|
|||
|
||||
Clear();
|
||||
|
||||
if (not term.isEmpty())
|
||||
{
|
||||
searchList = table->findItems(term, Qt::MatchContains);
|
||||
searchList = FindTableItems(term);
|
||||
|
||||
if (not searchList.isEmpty())
|
||||
{
|
||||
|
@ -118,7 +151,6 @@ void VTableSearch::Find(const QString &term)
|
|||
emit HasResult(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTableSearch::FindPrevious()
|
||||
|
@ -195,20 +227,15 @@ void VTableSearch::RefreshList(const QString &term)
|
|||
{
|
||||
SCASSERT(table != nullptr)
|
||||
|
||||
if (term.isEmpty())
|
||||
searchList = FindTableItems(term);
|
||||
|
||||
if (not searchList.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
searchList = table->findItems(term, Qt::MatchContains);
|
||||
|
||||
for (auto item : qAsConst(searchList))
|
||||
{
|
||||
item->setBackground(Qt::yellow);
|
||||
}
|
||||
|
||||
if (not searchList.isEmpty())
|
||||
{
|
||||
if (searchIndex < 0)
|
||||
{
|
||||
searchIndex = searchList.size() - 1;
|
||||
|
|
|
@ -60,6 +60,7 @@ private:
|
|||
|
||||
void Clear();
|
||||
void ShowNext(int newIndex);
|
||||
QList<QTableWidgetItem *> FindTableItems(QString term);
|
||||
};
|
||||
|
||||
#endif // VTABLESEARCH_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user