Skip to content

Commit 73dc9b1

Browse files
committedJan 7, 2013
Include project home in browser toplevel browser (implement #6955)
[API] add QgsProject::homePath() [API] make QgsBrowserModel::reload() a public slot
1 parent 314d144 commit 73dc9b1

File tree

7 files changed

+38
-10
lines changed

7 files changed

+38
-10
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3330,11 +3330,12 @@ bool QgisApp::addProject( QString projectFile )
33303330

33313331
if ( ! QgsProject::instance()->read( projectFile ) )
33323332
{
3333+
QApplication::restoreOverrideCursor();
3334+
33333335
QMessageBox::critical( this,
33343336
tr( "Unable to open project" ),
33353337
QgsProject::instance()->error() );
33363338

3337-
QApplication::restoreOverrideCursor();
33383339

33393340
mMapCanvas->freeze( false );
33403341
mMapCanvas->refresh();

‎src/app/qgsbrowserdockwidget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "qgsrasterlayer.h"
2929
#include "qgsvectorlayer.h"
3030
#include "qgisapp.h"
31+
#include "qgsproject.h"
3132

3233
// browser layer properties dialog
3334
#include "qgsapplication.h"
@@ -285,6 +286,10 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
285286
if ( item && item->type() == QgsDataItem::Favourites )
286287
mBrowserView->expand( index );
287288
}
289+
290+
connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ), mModel, SLOT( reload() ) );
291+
connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ), mModel, SLOT( reload() ) );
292+
connect( QgisApp::instance(), SIGNAL( newProject() ), mModel, SLOT( reload() ) );
288293
}
289294

290295
QDockWidget::showEvent( e );

‎src/core/qgsbrowsermodel.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "qgsproviderregistry.h"
2525

2626
#include "qgsbrowsermodel.h"
27+
#include "qgsproject.h"
2728

2829
#include <QSettings>
2930

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

4142
void QgsBrowserModel::addRootItems()
4243
{
43-
// give the home directory a prominent first place
44-
QgsDirectoryItem *item = new QgsDirectoryItem( NULL, tr( "Home" ), QDir::homePath() );
44+
QgsDirectoryItem *item;
45+
46+
QString home = QgsProject::instance()->homePath();
47+
48+
if( !home.isNull() )
49+
{
50+
item = new QgsDirectoryItem( NULL, tr( "Project home" ), home );
51+
mRootItems << item;
52+
}
53+
54+
// give the home directory a prominent second place
55+
item = new QgsDirectoryItem( NULL, tr( "Home" ), QDir::homePath() );
4556
QStyle *style = QApplication::style();
4657
QIcon homeIcon( style->standardPixmap( QStyle::SP_DirHomeIcon ) );
4758
item->setIcon( homeIcon );

‎src/core/qgsbrowsermodel.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
7575

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

78-
// Reload the whole model
79-
void reload();
80-
8178
// Refresh item specified by path
8279
void refresh( QString path );
8380

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

9592
public slots:
93+
// Reload the whole model
94+
void reload();
9695

9796
void beginInsertItems( QgsDataItem *parent, int first, int last );
9897
void endInsertItems();

‎src/core/qgsproject.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,11 +1368,11 @@ QString QgsProject::readPath( QString src ) const
13681368
// That means that it was saved with an earlier version of "relative path support",
13691369
// where the source file had to exist and only the project directory was stripped
13701370
// from the filename.
1371-
QFileInfo pfi( fileName() );
1372-
if ( !pfi.exists() )
1371+
QString home = homePath();
1372+
if( home.isNull() )
13731373
return src;
13741374

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

13771377
if ( !fi.exists() )
13781378
{
@@ -1763,4 +1763,11 @@ void QgsProjectBadLayerDefaultHandler::handleBadLayers( QList<QDomNode> /*layers
17631763
// just ignore any bad layers
17641764
}
17651765

1766+
QString QgsProject::homePath() const
1767+
{
1768+
QFileInfo pfi( fileName() );
1769+
if ( !pfi.exists() )
1770+
return QString::null;
17661771

1772+
return pfi.canonicalPath();
1773+
}

‎src/core/qgsproject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ class CORE_EXPORT QgsProject : public QObject
310310
@note added in version 1.9*/
311311
bool topologicalEditing() const;
312312

313+
/** Return project's home path
314+
@return home path of project (or QString::null if not set)
315+
@note added in version 2.0 */
316+
QString homePath() const;
317+
313318
protected:
314319

315320
/** Set error message from read/write operation

‎src/providers/wms/qgswmssourceselect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget * parent, Qt::WFlags fl, bool ma
5858
: QDialog( parent, fl )
5959
, mManagerMode( managerMode )
6060
, mEmbeddedMode( embeddedMode )
61-
, mCurrentTileset( 0 )
6261
, mDefaultCRS( GEO_EPSG_CRS_AUTHID )
62+
, mCurrentTileset( 0 )
6363
{
6464
setupUi( this );
6565

0 commit comments

Comments
 (0)
Please sign in to comment.