From 28044ff4c6d090e252e002478a4c65955c2ef317 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 3 Feb 2018 12:45:16 +0200 Subject: [PATCH] Improve search in Tape app. Provide search not only in selected measurement description, but in all descriptions. ref #732. --HG-- branch : develop --- src/app/tape/dialogs/dialogmdatabase.cpp | 59 ++++++++++++++++-------- src/app/tape/dialogs/dialogmdatabase.h | 2 + src/app/tape/mapplication.cpp | 6 --- src/app/tape/mapplication.h | 6 +++ 4 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/app/tape/dialogs/dialogmdatabase.cpp b/src/app/tape/dialogs/dialogmdatabase.cpp index d15624724..ebe92decc 100644 --- a/src/app/tape/dialogs/dialogmdatabase.cpp +++ b/src/app/tape/dialogs/dialogmdatabase.cpp @@ -315,20 +315,7 @@ void DialogMDataBase::ShowDescription(QTreeWidgetItem *item, int column) return; } - const QString name = item->data(0, Qt::UserRole).toString(); - const VTranslateVars *trv = qApp->TrVars(); - const QString number = trv->MNumber(name); - - const QString text = QString("

%1
%2. %3

" - "

%4

") - .arg(ImgTag(number)) - .arg(number) - .arg(trv->GuiText(name)) - .arg(trv->Description(name)); - - ui->textEdit->setHtml(text); + ui->textEdit->setHtml(ItemFullDescription(item)); } //--------------------------------------------------------------------------------------------------------------------- @@ -456,10 +443,12 @@ void DialogMDataBase::FilterGroup(QTreeWidgetItem *group, const QString &search) for (int i=0; i < group->childCount(); ++i) { QTreeWidgetItem *childItem = group->child(i); - const bool hidden = (not childItem->isSelected() - && not childItem->text(0).contains(search, Qt::CaseInsensitive)) - || (childItem->isSelected() && not ui->textEdit->toPlainText().contains(search, Qt::CaseInsensitive) - && not childItem->text(0).contains(search, Qt::CaseInsensitive)); + const QString description = QTextDocumentFragment::fromHtml(ItemFullDescription(childItem, false)) + .toPlainText(); + + const bool hidden = not childItem->text(0).contains(search, Qt::CaseInsensitive) + && not description.contains(search, Qt::CaseInsensitive); + childItem->setHidden(hidden); if (not hidden) { @@ -527,6 +516,40 @@ void DialogMDataBase::WriteSettings() qApp->TapeSettings()->SetDataBaseGeometry(saveGeometry()); } +//--------------------------------------------------------------------------------------------------------------------- +QString DialogMDataBase::ItemFullDescription(QTreeWidgetItem *item, bool showImage) const +{ + if (item == nullptr || item->childCount() != 0) + { + return QString(); + } + + const QString name = item->data(0, Qt::UserRole).toString(); + if (name.isEmpty()) + { + return QString(); + } + + const QString number = qApp->TrVars()->MNumber(name); + + QString imgTag; + if (showImage) + { + imgTag = ImgTag(number); + } + + const QString text = QString("

%1
%2. %3

" + "

%4

") + .arg(imgTag) + .arg(number) + .arg(qApp->TrVars()->GuiText(name)) + .arg(qApp->TrVars()->Description(name)); + + return text; +} + //--------------------------------------------------------------------------------------------------------------------- void DialogMDataBase::RetranslateGroup(QTreeWidgetItem *group, const QString &groupText, const QStringList &list) { diff --git a/src/app/tape/dialogs/dialogmdatabase.h b/src/app/tape/dialogs/dialogmdatabase.h index d9ff31ded..a9e8f33ea 100644 --- a/src/app/tape/dialogs/dialogmdatabase.h +++ b/src/app/tape/dialogs/dialogmdatabase.h @@ -100,6 +100,8 @@ private: void ReadSettings(); void WriteSettings(); + QString ItemFullDescription(QTreeWidgetItem *item, bool showImage = true) const; + void RetranslateGroup(QTreeWidgetItem *group, const QString &groupText, const QStringList &list); void RetranslateMeasurement(QTreeWidgetItem *group, int index, const QString &name); diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index 5fa948676..fff4a658d 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -404,12 +404,6 @@ void MApplication::InitOptions() QResource::registerResource(diagramsPath()); } -//--------------------------------------------------------------------------------------------------------------------- -const VTranslateVars *MApplication::TrVars() -{ - return trVars; -} - //--------------------------------------------------------------------------------------------------------------------- void MApplication::InitTrVars() { diff --git a/src/app/tape/mapplication.h b/src/app/tape/mapplication.h index a181cf6bf..f9f0b98c0 100644 --- a/src/app/tape/mapplication.h +++ b/src/app/tape/mapplication.h @@ -97,5 +97,11 @@ private: void Clean(); }; +//--------------------------------------------------------------------------------------------------------------------- + +inline const VTranslateVars *MApplication::TrVars() +{ + return trVars; +} #endif // MAPPLICATION_H