diff --git a/src/app/qgsbrowserdockwidget.cpp b/src/app/qgsbrowserdockwidget.cpp index 63e22a5b93c5..278cf15490d8 100644 --- a/src/app/qgsbrowserdockwidget.cpp +++ b/src/app/qgsbrowserdockwidget.cpp @@ -56,6 +56,7 @@ class QgsBrowserTreeView : public QTreeView setContextMenuPolicy( Qt::CustomContextMenu ); setHeaderHidden( true ); setDropIndicatorShown( true ); + } void dragEnterEvent( QDragEnterEvent* e ) @@ -287,6 +288,7 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QString name, QWidget * parent ) : connect( mBrowserView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) ); connect( mBrowserView, SIGNAL( doubleClicked( const QModelIndex& ) ), this, SLOT( addLayerAtIndex( const QModelIndex& ) ) ); + connect( mBrowserView, SIGNAL( expanded( const QModelIndex& ) ), this, SLOT( itemExpanded( const QModelIndex& ) ) ); } void QgsBrowserDockWidget::showEvent( QShowEvent * e ) @@ -314,6 +316,15 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e ) if ( item && item->type() == QgsDataItem::Favourites ) mBrowserView->expand( index ); } + + // expand last expanded path from previous session + QSettings settings; + QString lastPath = settings.value( "/BrowserWidget/lastExpanded" ).toString(); + QgsDebugMsg( "lastPath = " + lastPath ); + if ( !lastPath.isEmpty() ) + { + expandPath( lastPath ); + } } QDockWidget::showEvent( e ); @@ -678,3 +689,34 @@ void QgsBrowserDockWidget::setCaseSensitive( bool caseSensitive ) return; mProxyModel->setCaseSensitive( caseSensitive ); } + +void QgsBrowserDockWidget::itemExpanded( const QModelIndex& index ) +{ + if ( !mModel || !mProxyModel ) + return; + QSettings settings; + QModelIndex srcIndex = mProxyModel->mapToSource( index ); + QgsDataItem *item = mModel->dataItem( srcIndex ); + if ( !item ) + return; + + // TODO: save separately each type (FS, WMS)? + settings.setValue( "/BrowserWidget/lastExpanded", item->path() ); + QgsDebugMsg( "last expanded: " + item->path() ); +} + +void QgsBrowserDockWidget::expandPath( QString path ) +{ + QgsDebugMsg( "path = " + path ); + + if ( !mModel || !mProxyModel ) + return; + QModelIndex srcIndex = mModel->findPath( path ); + QModelIndex index = mProxyModel->mapFromSource( srcIndex ); + QgsDebugMsg( QString( "srcIndex.isValid() = %1 index.isValid() = %2" ).arg( srcIndex.isValid() ).arg( index.isValid() ) ); + if ( index.isValid() ) + { + mBrowserView->expand( index ); + mBrowserView->scrollTo( index, QAbstractItemView::PositionAtTop ); + } +} diff --git a/src/app/qgsbrowserdockwidget.h b/src/app/qgsbrowserdockwidget.h index 261c9c27d5b6..09c21ccbba4e 100644 --- a/src/app/qgsbrowserdockwidget.h +++ b/src/app/qgsbrowserdockwidget.h @@ -31,6 +31,7 @@ class APP_EXPORT QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrows public: explicit QgsBrowserDockWidget( QString name, QWidget *parent = 0 ); void addFavouriteDirectory( QString favDir ); + void expandPath( QString path ); public slots: void addLayerAtIndex( const QModelIndex& index ); @@ -53,6 +54,8 @@ class APP_EXPORT QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrows void showProperties(); void toggleFastScan(); + void itemExpanded( const QModelIndex& index ); + protected: void refreshModel( const QModelIndex& index ); diff --git a/src/core/qgsbrowsermodel.cpp b/src/core/qgsbrowsermodel.cpp index d7926229f5e8..0afd677750f9 100644 --- a/src/core/qgsbrowsermodel.cpp +++ b/src/core/qgsbrowsermodel.cpp @@ -296,6 +296,7 @@ QModelIndex QgsBrowserModel::findPath( QString path ) if ( path.startsWith( item->path() ) ) { // we have found a preceding item: stop searching on this level and go deeper + item->populate(); foundChild = true; theIndex = idx; break; @@ -303,6 +304,7 @@ QModelIndex QgsBrowserModel::findPath( QString path ) } } + QgsDebugMsg( "path not found" ); return QModelIndex(); // not found }