@@ -56,6 +56,7 @@ class QgsBrowserTreeView : public QTreeView
56
56
setContextMenuPolicy ( Qt::CustomContextMenu );
57
57
setHeaderHidden ( true );
58
58
setDropIndicatorShown ( true );
59
+
59
60
}
60
61
61
62
void dragEnterEvent ( QDragEnterEvent* e )
@@ -287,6 +288,7 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QString name, QWidget * parent ) :
287
288
288
289
connect ( mBrowserView , SIGNAL ( customContextMenuRequested ( const QPoint & ) ), this , SLOT ( showContextMenu ( const QPoint & ) ) );
289
290
connect ( mBrowserView , SIGNAL ( doubleClicked ( const QModelIndex& ) ), this , SLOT ( addLayerAtIndex ( const QModelIndex& ) ) );
291
+ connect ( mBrowserView , SIGNAL ( expanded ( const QModelIndex& ) ), this , SLOT ( itemExpanded ( const QModelIndex& ) ) );
290
292
}
291
293
292
294
void QgsBrowserDockWidget::showEvent ( QShowEvent * e )
@@ -314,6 +316,15 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
314
316
if ( item && item->type () == QgsDataItem::Favourites )
315
317
mBrowserView ->expand ( index );
316
318
}
319
+
320
+ // expand last expanded path from previous session
321
+ QSettings settings;
322
+ QString lastPath = settings.value ( " /BrowserWidget/lastExpanded" ).toString ();
323
+ QgsDebugMsg ( " lastPath = " + lastPath );
324
+ if ( !lastPath.isEmpty () )
325
+ {
326
+ expandPath ( lastPath );
327
+ }
317
328
}
318
329
319
330
QDockWidget::showEvent ( e );
@@ -678,3 +689,34 @@ void QgsBrowserDockWidget::setCaseSensitive( bool caseSensitive )
678
689
return ;
679
690
mProxyModel ->setCaseSensitive ( caseSensitive );
680
691
}
692
+
693
+ void QgsBrowserDockWidget::itemExpanded ( const QModelIndex& index )
694
+ {
695
+ if ( !mModel || !mProxyModel )
696
+ return ;
697
+ QSettings settings;
698
+ QModelIndex srcIndex = mProxyModel ->mapToSource ( index );
699
+ QgsDataItem *item = mModel ->dataItem ( srcIndex );
700
+ if ( !item )
701
+ return ;
702
+
703
+ // TODO: save separately each type (FS, WMS)?
704
+ settings.setValue ( " /BrowserWidget/lastExpanded" , item->path () );
705
+ QgsDebugMsg ( " last expanded: " + item->path () );
706
+ }
707
+
708
+ void QgsBrowserDockWidget::expandPath ( QString path )
709
+ {
710
+ QgsDebugMsg ( " path = " + path );
711
+
712
+ if ( !mModel || !mProxyModel )
713
+ return ;
714
+ QModelIndex srcIndex = mModel ->findPath ( path );
715
+ QModelIndex index = mProxyModel ->mapFromSource ( srcIndex );
716
+ QgsDebugMsg ( QString ( " srcIndex.isValid() = %1 index.isValid() = %2" ).arg ( srcIndex.isValid () ).arg ( index.isValid () ) );
717
+ if ( index.isValid () )
718
+ {
719
+ mBrowserView ->expand ( index );
720
+ mBrowserView ->scrollTo ( index, QAbstractItemView::PositionAtTop );
721
+ }
722
+ }
0 commit comments