[GUI] new feature to search for parameter groups

This commit is contained in:
donovaly
2020-03-14 07:23:18 +01:00
committed by wmayer
parent 2430ab4866
commit 78e6edf0ab
3 changed files with 90 additions and 0 deletions

View File

@@ -46,6 +46,22 @@
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="findGroupLE">
<property name="toolTip">
<string>Type in a group name to find it</string>
</property>
<property name="placeholderText">
<string>Search Group</string>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonFind" >
<property name="text" >

View File

@@ -117,6 +117,15 @@ DlgParameterImp::DlgParameterImp( QWidget* parent, Qt::WindowFlags fl )
connect(paramGroup, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
this, SLOT(onGroupSelected(QTreeWidgetItem*)));
onGroupSelected(paramGroup->currentItem());
connect(ui->findGroupLE, SIGNAL(textChanged(QString)),
this, SLOT(on_findGroup_changed(QString)));
// setup for function on_findGroup_changed:
// store the current font properties
// because we don't know what style sheet the user uses for FC
defaultFont = paramGroup->font();
defaultColor = paramGroup->topLevelItem(0)->foreground(0);
}
/**
@@ -135,6 +144,64 @@ void DlgParameterImp::on_buttonFind_clicked()
finder->show();
}
void DlgParameterImp::on_findGroup_changed(const QString &SearchStr)
{
// search for group tree items and highlight found results
// if SearchStr not empty
QTreeWidgetItem* ExpandItem;
// at first reset all items to the default font and nesting
if (foundList.size() > 0) {
for (QTreeWidgetItem* item : foundList) {
item->setFont(0, defaultFont);
item->setForeground(0, defaultColor);
ExpandItem = item;
// a group can be nested down to several levels
while (true) {
if (!ExpandItem->parent())
break;
else {
ExpandItem->setExpanded(false);
ExpandItem = ExpandItem->parent();
}
}
}
}
// expand the top level entries to get the initial tree state
for (int i = 0; i < paramGroup->topLevelItemCount(); ++i) {
paramGroup->topLevelItem(i)->setExpanded(true);
}
// don't perform a search if the search is empty
if (SearchStr.isEmpty())
return;
// search the tree widget
foundList = paramGroup->findItems(SearchStr, Qt::MatchContains | Qt::MatchRecursive);
if (foundList.size() > 0) {
for (QTreeWidgetItem* item : foundList) {
item->setFont(0, boldFont);
item->setForeground(0, Qt::red);
// expand its parent to see the item
// a group can be nested down to several levels
ExpandItem = item;
while (true) {
if (!ExpandItem->parent())
break;
else {
ExpandItem->setExpanded(true);
ExpandItem = ExpandItem->parent();
}
}
// if there is only one found item, scrollt o it
if (foundList.size() == 1) {
paramGroup->scrollToItem(foundList[0], QAbstractItemView::PositionAtCenter);
}
}
}
}
/**
* Sets the strings of the subwidgets using the current
* language.

View File

@@ -57,6 +57,7 @@ public:
protected Q_SLOTS:
void onChangeParameterSet(int);
void on_buttonFind_clicked();
void on_findGroup_changed(const QString &SearchStr);
void on_buttonSaveToDisk_clicked();
void onGroupSelected(QTreeWidgetItem *);
@@ -73,6 +74,12 @@ protected:
QTreeWidget* paramValue;
Ui_DlgParameter* ui;
QPointer<DlgParameterFind> finder;
private:
QFont defaultFont;
QBrush defaultColor;
const QFont boldFont = QFont(QString(), -1, QFont::Bold);
QList<QTreeWidgetItem*> foundList;
};
// --------------------------------------------------------------------