Skip to content

Commit abf0087

Browse files
committedNov 6, 2014
remember browser last expanded item
1 parent 443264f commit abf0087

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
 

‎src/app/qgsbrowserdockwidget.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

292294
void 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+
}

‎src/app/qgsbrowserdockwidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class APP_EXPORT QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrows
3131
public:
3232
explicit QgsBrowserDockWidget( QString name, QWidget *parent = 0 );
3333
void addFavouriteDirectory( QString favDir );
34+
void expandPath( QString path );
3435

3536
public slots:
3637
void addLayerAtIndex( const QModelIndex& index );
@@ -53,6 +54,8 @@ class APP_EXPORT QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrows
5354
void showProperties();
5455
void toggleFastScan();
5556

57+
void itemExpanded( const QModelIndex& index );
58+
5659
protected:
5760
void refreshModel( const QModelIndex& index );
5861

‎src/core/qgsbrowsermodel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,15 @@ QModelIndex QgsBrowserModel::findPath( QString path )
296296
if ( path.startsWith( item->path() ) )
297297
{
298298
// we have found a preceding item: stop searching on this level and go deeper
299+
item->populate();
299300
foundChild = true;
300301
theIndex = idx;
301302
break;
302303
}
303304
}
304305
}
305306

307+
QgsDebugMsg( "path not found" );
306308
return QModelIndex(); // not found
307309
}
308310

0 commit comments

Comments
 (0)
Please sign in to comment.