Skip to content

Commit

Permalink
remember browser last expanded item
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Nov 6, 2014
1 parent 443264f commit abf0087
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/app/qgsbrowserdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class QgsBrowserTreeView : public QTreeView
setContextMenuPolicy( Qt::CustomContextMenu );
setHeaderHidden( true );
setDropIndicatorShown( true );

}

void dragEnterEvent( QDragEnterEvent* e )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
}
3 changes: 3 additions & 0 deletions src/app/qgsbrowserdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );

Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsbrowsermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,15 @@ 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;
}
}
}

QgsDebugMsg( "path not found" );
return QModelIndex(); // not found
}

Expand Down

0 comments on commit abf0087

Please sign in to comment.