From 78e6edf0ab19eacfc4afc826ec5186a76c71bc57 Mon Sep 17 00:00:00 2001 From: donovaly Date: Sat, 14 Mar 2020 07:23:18 +0100 Subject: [PATCH] [GUI] new feature to search for parameter groups --- src/Gui/DlgParameter.ui | 16 +++++++++ src/Gui/DlgParameterImp.cpp | 67 +++++++++++++++++++++++++++++++++++++ src/Gui/DlgParameterImp.h | 7 ++++ 3 files changed, 90 insertions(+) diff --git a/src/Gui/DlgParameter.ui b/src/Gui/DlgParameter.ui index 1f2ff08707..1bdbb1f7d3 100644 --- a/src/Gui/DlgParameter.ui +++ b/src/Gui/DlgParameter.ui @@ -46,6 +46,22 @@ + + + + Type in a group name to find it + + + Search Group + + + + 0 + 0 + + + + diff --git a/src/Gui/DlgParameterImp.cpp b/src/Gui/DlgParameterImp.cpp index 1ad8b1e75a..f9948829e9 100644 --- a/src/Gui/DlgParameterImp.cpp +++ b/src/Gui/DlgParameterImp.cpp @@ -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. diff --git a/src/Gui/DlgParameterImp.h b/src/Gui/DlgParameterImp.h index fdea01bb3a..86e1b7cd09 100644 --- a/src/Gui/DlgParameterImp.h +++ b/src/Gui/DlgParameterImp.h @@ -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 finder; + +private: + QFont defaultFont; + QBrush defaultColor; + const QFont boldFont = QFont(QString(), -1, QFont::Bold); + QList foundList; }; // --------------------------------------------------------------------