Improve search in Tape app. Provide search not only in selected measurement

description, but in all descriptions. ref #732.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-02-03 12:45:16 +02:00
parent 34ffa5ab51
commit 28044ff4c6
4 changed files with 49 additions and 24 deletions

View File

@ -315,20 +315,7 @@ void DialogMDataBase::ShowDescription(QTreeWidgetItem *item, int column)
return; return;
} }
const QString name = item->data(0, Qt::UserRole).toString(); ui->textEdit->setHtml(ItemFullDescription(item));
const VTranslateVars *trv = qApp->TrVars();
const QString number = trv->MNumber(name);
const QString text = QString("<p align=\"center\" style=\"font-variant: normal; font-style: normal; font-weight: "
"normal\"> %1 <br clear=\"left\"><b>%2</b>. <i>%3</i></p>"
"<p align=\"left\" style=\"font-variant: normal; font-style: normal; font-weight: "
"normal\">%4</p>")
.arg(ImgTag(number))
.arg(number)
.arg(trv->GuiText(name))
.arg(trv->Description(name));
ui->textEdit->setHtml(text);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -456,10 +443,12 @@ void DialogMDataBase::FilterGroup(QTreeWidgetItem *group, const QString &search)
for (int i=0; i < group->childCount(); ++i) for (int i=0; i < group->childCount(); ++i)
{ {
QTreeWidgetItem *childItem = group->child(i); QTreeWidgetItem *childItem = group->child(i);
const bool hidden = (not childItem->isSelected() const QString description = QTextDocumentFragment::fromHtml(ItemFullDescription(childItem, false))
&& not childItem->text(0).contains(search, Qt::CaseInsensitive)) .toPlainText();
|| (childItem->isSelected() && not ui->textEdit->toPlainText().contains(search, Qt::CaseInsensitive)
&& not childItem->text(0).contains(search, Qt::CaseInsensitive)); const bool hidden = not childItem->text(0).contains(search, Qt::CaseInsensitive)
&& not description.contains(search, Qt::CaseInsensitive);
childItem->setHidden(hidden); childItem->setHidden(hidden);
if (not hidden) if (not hidden)
{ {
@ -527,6 +516,40 @@ void DialogMDataBase::WriteSettings()
qApp->TapeSettings()->SetDataBaseGeometry(saveGeometry()); 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("<p align=\"center\" style=\"font-variant: normal; font-style: normal; font-weight: "
"normal\"> %1 <br clear=\"left\"><b>%2</b>. <i>%3</i></p>"
"<p align=\"left\" style=\"font-variant: normal; font-style: normal; font-weight: "
"normal\">%4</p>")
.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) void DialogMDataBase::RetranslateGroup(QTreeWidgetItem *group, const QString &groupText, const QStringList &list)
{ {

View File

@ -100,6 +100,8 @@ private:
void ReadSettings(); void ReadSettings();
void WriteSettings(); void WriteSettings();
QString ItemFullDescription(QTreeWidgetItem *item, bool showImage = true) const;
void RetranslateGroup(QTreeWidgetItem *group, const QString &groupText, const QStringList &list); void RetranslateGroup(QTreeWidgetItem *group, const QString &groupText, const QStringList &list);
void RetranslateMeasurement(QTreeWidgetItem *group, int index, const QString &name); void RetranslateMeasurement(QTreeWidgetItem *group, int index, const QString &name);

View File

@ -404,12 +404,6 @@ void MApplication::InitOptions()
QResource::registerResource(diagramsPath()); QResource::registerResource(diagramsPath());
} }
//---------------------------------------------------------------------------------------------------------------------
const VTranslateVars *MApplication::TrVars()
{
return trVars;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MApplication::InitTrVars() void MApplication::InitTrVars()
{ {

View File

@ -97,5 +97,11 @@ private:
void Clean(); void Clean();
}; };
//---------------------------------------------------------------------------------------------------------------------
inline const VTranslateVars *MApplication::TrVars()
{
return trVars;
}
#endif // MAPPLICATION_H #endif // MAPPLICATION_H