@@ -56,6 +56,7 @@ class QgsBrowserTreeView : public QTreeView
5656 setContextMenuPolicy ( Qt::CustomContextMenu );
5757 setHeaderHidden ( true );
5858 setDropIndicatorShown ( true );
59+
5960 }
6061
6162 void dragEnterEvent ( QDragEnterEvent* e )
@@ -287,6 +288,7 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QString name, QWidget * parent ) :
287288
288289 connect ( mBrowserView , SIGNAL ( customContextMenuRequested ( const QPoint & ) ), this , SLOT ( showContextMenu ( const QPoint & ) ) );
289290 connect ( mBrowserView , SIGNAL ( doubleClicked ( const QModelIndex& ) ), this , SLOT ( addLayerAtIndex ( const QModelIndex& ) ) );
291+ connect ( mBrowserView , SIGNAL ( expanded ( const QModelIndex& ) ), this , SLOT ( itemExpanded ( const QModelIndex& ) ) );
290292}
291293
292294void QgsBrowserDockWidget::showEvent ( QShowEvent * e )
@@ -314,6 +316,15 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
314316 if ( item && item->type () == QgsDataItem::Favourites )
315317 mBrowserView ->expand ( index );
316318 }
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+ }
317328 }
318329
319330 QDockWidget::showEvent ( e );
@@ -678,3 +689,34 @@ void QgsBrowserDockWidget::setCaseSensitive( bool caseSensitive )
678689 return ;
679690 mProxyModel ->setCaseSensitive ( caseSensitive );
680691}
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