28
28
29
29
#include " qgsoptionsdialoghighlightwidgetsimpl.h"
30
30
31
-
31
+ # include < functional >
32
32
33
33
// ****************
34
34
// QLabel
@@ -190,6 +190,18 @@ bool QgsOptionsDialogHighlightTree::highlightText( const QString &text )
190
190
QTreeWidget *treeWidget = qobject_cast<QTreeWidget *>( mTreeView );
191
191
if ( treeWidget )
192
192
{
193
+ mTreeInitialVisible .clear ();
194
+ // initially hide everything
195
+ std::function< void ( QTreeWidgetItem *, bool ) > setChildrenVisible;
196
+ setChildrenVisible = [this , &setChildrenVisible]( QTreeWidgetItem * item, bool visible )
197
+ {
198
+ for ( int i = 0 ; i < item->childCount (); ++i )
199
+ setChildrenVisible ( item->child ( i ), visible );
200
+ mTreeInitialVisible .insert ( item, !item->isHidden () );
201
+ item->setHidden ( !visible );
202
+ };
203
+ setChildrenVisible ( treeWidget->invisibleRootItem (), false );
204
+
193
205
QList<QTreeWidgetItem *> items = treeWidget->findItems ( text, Qt::MatchContains | Qt::MatchRecursive, 0 );
194
206
success = items.count () ? true : false ;
195
207
mTreeInitialStyle .clear ();
@@ -199,6 +211,7 @@ bool QgsOptionsDialogHighlightTree::highlightText( const QString &text )
199
211
mTreeInitialStyle .insert ( item, qMakePair ( item->background ( 0 ), item->foreground ( 0 ) ) );
200
212
item->setBackground ( 0 , QBrush ( QColor ( Qt::yellow ) ) );
201
213
item->setForeground ( 0 , QBrush ( QColor ( Qt::blue ) ) );
214
+ setChildrenVisible ( item, true );
202
215
203
216
QTreeWidgetItem *parent = item;
204
217
while ( ( parent = parent->parent () ) )
@@ -207,6 +220,7 @@ bool QgsOptionsDialogHighlightTree::highlightText( const QString &text )
207
220
break ;
208
221
mTreeInitialExpand .insert ( parent, parent->isExpanded () );
209
222
parent->setExpanded ( true );
223
+ parent->setHidden ( false );
210
224
}
211
225
}
212
226
}
@@ -222,6 +236,15 @@ void QgsOptionsDialogHighlightTree::reset()
222
236
QTreeWidget *treeWidget = qobject_cast<QTreeWidget *>( mTreeView );
223
237
if ( treeWidget )
224
238
{
239
+ // show everything
240
+ std::function< void ( QTreeWidgetItem * ) > showChildren;
241
+ showChildren = [this , &showChildren]( QTreeWidgetItem * item )
242
+ {
243
+ for ( int i = 0 ; i < item->childCount (); ++i )
244
+ showChildren ( item->child ( i ) );
245
+ item->setHidden ( !mTreeInitialVisible .value ( item, true ) );
246
+ };
247
+ showChildren ( treeWidget->invisibleRootItem () );
225
248
for ( QTreeWidgetItem *item : mTreeInitialExpand .keys () )
226
249
{
227
250
if ( item )
0 commit comments