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:
Wren Turkal 2019-01-06 01:25:12 -08:00
parent 42b00c5c58
commit 71f7f40875
2 changed files with 54 additions and 26 deletions

View File

@ -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())
{
@ -117,7 +150,6 @@ void VTableSearch::Find(const QString &term)
emit HasResult(true);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -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;

View File

@ -60,6 +60,7 @@ private:
void Clear();
void ShowNext(int newIndex);
QList<QTableWidgetItem *> FindTableItems(QString term);
};
#endif // VTABLESEARCH_H