Skip to content
Permalink
Browse files

remember browser last expanded item

  • Loading branch information
blazek committed Nov 6, 2014
1 parent 443264f commit abf00872c2f80ef69fd992026f1b8b96cd36838d
Showing with 47 additions and 0 deletions.
  1. +42 −0 src/app/qgsbrowserdockwidget.cpp
  2. +3 −0 src/app/qgsbrowserdockwidget.h
  3. +2 −0 src/core/qgsbrowsermodel.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 );
}
}
@@ -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 );

@@ -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
}

0 comments on commit abf0087

Please sign in to comment.
You can’t perform that action at this time.