Skip to content

Commit

Permalink
Include project home in browser toplevel browser (implement #6955)
Browse files Browse the repository at this point in the history
[API] add QgsProject::homePath()
[API] make QgsBrowserModel::reload() a public slot
  • Loading branch information
jef-n committed Jan 7, 2013
1 parent 314d144 commit 73dc9b1
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3330,11 +3330,12 @@ bool QgisApp::addProject( QString projectFile )

if ( ! QgsProject::instance()->read( projectFile ) )
{
QApplication::restoreOverrideCursor();

QMessageBox::critical( this,
tr( "Unable to open project" ),
QgsProject::instance()->error() );

QApplication::restoreOverrideCursor();

mMapCanvas->freeze( false );
mMapCanvas->refresh();
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsbrowserdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "qgsrasterlayer.h"
#include "qgsvectorlayer.h"
#include "qgisapp.h"
#include "qgsproject.h"

// browser layer properties dialog
#include "qgsapplication.h"
Expand Down Expand Up @@ -285,6 +286,10 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
if ( item && item->type() == QgsDataItem::Favourites )
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() ) );
}

QDockWidget::showEvent( e );
Expand Down
15 changes: 13 additions & 2 deletions src/core/qgsbrowsermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "qgsproviderregistry.h"

#include "qgsbrowsermodel.h"
#include "qgsproject.h"

#include <QSettings>

Expand All @@ -40,8 +41,18 @@ QgsBrowserModel::~QgsBrowserModel()

void QgsBrowserModel::addRootItems()
{
// give the home directory a prominent first place
QgsDirectoryItem *item = new QgsDirectoryItem( NULL, tr( "Home" ), QDir::homePath() );
QgsDirectoryItem *item;

QString home = QgsProject::instance()->homePath();

if( !home.isNull() )
{
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() );
QStyle *style = QApplication::style();
QIcon homeIcon( style->standardPixmap( QStyle::SP_DirHomeIcon ) );
item->setIcon( homeIcon );
Expand Down
5 changes: 2 additions & 3 deletions src/core/qgsbrowsermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel

bool hasChildren( const QModelIndex &parent = QModelIndex() ) const;

// Reload the whole model
void reload();

// Refresh item specified by path
void refresh( QString path );

Expand All @@ -93,6 +90,8 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
void fetchMore( const QModelIndex & parent );

public slots:
// Reload the whole model
void reload();

void beginInsertItems( QgsDataItem *parent, int first, int last );
void endInsertItems();
Expand Down
13 changes: 10 additions & 3 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,11 +1368,11 @@ QString QgsProject::readPath( QString src ) const
// That means that it was saved with an earlier version of "relative path support",
// where the source file had to exist and only the project directory was stripped
// from the filename.
QFileInfo pfi( fileName() );
if ( !pfi.exists() )
QString home = homePath();
if( home.isNull() )
return src;

QFileInfo fi( pfi.canonicalPath() + "/" + src );
QFileInfo fi( home + "/" + src );

if ( !fi.exists() )
{
Expand Down Expand Up @@ -1763,4 +1763,11 @@ void QgsProjectBadLayerDefaultHandler::handleBadLayers( QList<QDomNode> /*layers
// just ignore any bad layers
}

QString QgsProject::homePath() const
{
QFileInfo pfi( fileName() );
if ( !pfi.exists() )
return QString::null;

return pfi.canonicalPath();
}
5 changes: 5 additions & 0 deletions src/core/qgsproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ class CORE_EXPORT QgsProject : public QObject
@note added in version 1.9*/
bool topologicalEditing() const;

/** Return project's home path
@return home path of project (or QString::null if not set)
@note added in version 2.0 */
QString homePath() const;

protected:

/** Set error message from read/write operation
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wms/qgswmssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget * parent, Qt::WFlags fl, bool ma
: QDialog( parent, fl )
, mManagerMode( managerMode )
, mEmbeddedMode( embeddedMode )
, mCurrentTileset( 0 )
, mDefaultCRS( GEO_EPSG_CRS_AUTHID )
, mCurrentTileset( 0 )
{
setupUi( this );

Expand Down

0 comments on commit 73dc9b1

Please sign in to comment.