diff --git a/src/app/qgsbrowserdockwidget.cpp b/src/app/qgsbrowserdockwidget.cpp index 33f2f20..4b87a88 100644 --- a/src/app/qgsbrowserdockwidget.cpp +++ b/src/app/qgsbrowserdockwidget.cpp @@ -287,9 +287,12 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e ) mBrowserView->expand( index ); } - connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ), mModel, SLOT( reload() ) ); - connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ), mModel, SLOT( reload() ) ); - connect( QgisApp::instance(), SIGNAL( newProject() ), mModel, SLOT( reload() ) ); + // connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ), mModel, SLOT( reload() ) ); + // connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ), mModel, SLOT( reload() ) ); + // connect( QgisApp::instance(), SIGNAL( newProject() ), mModel, SLOT( reload() ) ); + connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ), this, SLOT( setProjectHome() ) ); + connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ), this, SLOT( setProjectHome() ) ); + connect( QgisApp::instance(), SIGNAL( newProject() ), this, SLOT( setProjectHome() ) ); } QDockWidget::showEvent( e ); @@ -425,7 +428,7 @@ void QgsBrowserDockWidget::refreshModel( const QModelIndex& index ) QgsDataItem *item = mModel->dataItem( index ); if ( item ) { - QgsDebugMsg( "path = " + item->path() ); + QgsDebugMsg( QString( "path %1 has %2 children" ).arg( item->path() ).arg( mModel->rowCount( index ) ) ); } else { @@ -663,3 +666,9 @@ void QgsBrowserDockWidget::setFilterSyntax( QAction * action ) return; mProxyModel->setFilterSyntax(( QRegExp::PatternSyntax ) action->data().toInt() ); } + +void QgsBrowserDockWidget::setProjectHome() +{ + mModel->setProjectHome(); + refresh(); +} diff --git a/src/app/qgsbrowserdockwidget.h b/src/app/qgsbrowserdockwidget.h index 2e7a87b..5ae8afb 100644 --- a/src/app/qgsbrowserdockwidget.h +++ b/src/app/qgsbrowserdockwidget.h @@ -67,6 +67,10 @@ class QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrowserDockWidge QgsBrowserTreeView* mBrowserView; QgsBrowserModel* mModel; QgsBrowserTreeFilterProxyModel* mProxyModel; + + protected slots: + void setProjectHome(); + }; #endif // QGSBROWSERDOCKWIDGET_H diff --git a/src/core/qgsbrowsermodel.cpp b/src/core/qgsbrowsermodel.cpp index 334bc00..d33a827 100644 --- a/src/core/qgsbrowsermodel.cpp +++ b/src/core/qgsbrowsermodel.cpp @@ -43,13 +43,12 @@ void QgsBrowserModel::addRootItems() { QgsDirectoryItem *item; + // project home, default is current path (where application was started) QString home = QgsProject::instance()->homePath(); - - if ( !home.isNull() ) - { - item = new QgsDirectoryItem( NULL, tr( "Project home" ), home ); - mRootItems << item; - } + if ( home.isNull() ) + home = QDir::currentPath(); + item = new QgsDirectoryItem( NULL, tr( "Project home" ), home ); + mRootItems << item; // give the home directory a prominent second place item = new QgsDirectoryItem( NULL, tr( "Home" ), QDir::homePath() ); @@ -261,11 +260,42 @@ QModelIndex QgsBrowserModel::findPath( QString path ) void QgsBrowserModel::reload() { + QgsDebugMsg( "entered" ); removeRootItems(); addRootItems(); reset(); // Qt4.6 brings better methods beginResetModel + endResetModel } +void QgsBrowserModel::setProjectHome() +{ + // project home, default is current path (where application was started) + QString home = QgsProject::instance()->homePath(); + if ( home.isNull() ) + home = QDir::currentPath(); + + // search for project home item and replace it with new item + // if old home is same as new home, do nothing + // if not found something is broken because it should be created in addRootItems() + for( int i=0; iname() == tr( "Project home" ) ) + { + QgsDebugMsg( QString( "found project home item (%1), new home (%2)" ).arg( item->path() ).arg( home ) ); + if ( item->path() != home ) + { + delete item; + item = new QgsDirectoryItem( NULL, tr( "Project home" ), home ); + mRootItems[i] = item; + item->refresh(); + QgsDebugMsg( QString( "new project item has %1 children" ).arg( item->rowCount() ) ); + } + break; + } + } + +} + /* Refresh dir path */ void QgsBrowserModel::refresh( QString path ) { diff --git a/src/core/qgsbrowsermodel.h b/src/core/qgsbrowsermodel.h index b0ef32f..e5807ef 100644 --- a/src/core/qgsbrowsermodel.h +++ b/src/core/qgsbrowsermodel.h @@ -92,6 +92,7 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel public slots: // Reload the whole model void reload(); + void setProjectHome(); void beginInsertItems( QgsDataItem *parent, int first, int last ); void endInsertItems();