Skip to content

Commit 6bff6a6

Browse files
author
homann
committed
Re-order layers after finding missing files. Also restructured the exception logic in qgisapp.cpp. Fixes #1561
git-svn-id: http://svn.osgeo.org/qgis/trunk@11363 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent b9b367c commit 6bff6a6

File tree

3 files changed

+67
-35
lines changed

3 files changed

+67
-35
lines changed

src/app/qgisapp.cpp

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,15 +3297,11 @@ void QgisApp::fileOpen()
32973297

32983298
try
32993299
{
3300-
if ( QgsProject::instance()->read() )
3300+
if ( ! QgsProject::instance()->read() )
33013301
{
3302-
setTitleBarText_( *this );
3303-
emit projectRead(); // let plug-ins know that we've read in a new
3304-
// project so that they can check any project
3305-
// specific plug-in state
3306-
3307-
// add this to the list of recently used project files
3308-
saveRecentProjectPath( fullPath, settings );
3302+
mMapCanvas->freeze( false );
3303+
mMapCanvas->refresh();
3304+
return;
33093305
}
33103306
}
33113307
catch ( QgsProjectBadLayerException & e )
@@ -3318,15 +3314,29 @@ void QgisApp::fileOpen()
33183314
// attempt to find the new locations for missing layers
33193315
// XXX vector file hard-coded -- but what if it's raster?
33203316
findLayers_( mVectorFileFilter, e.layers() );
3317+
3318+
// Tell the legend to update the ordering
3319+
mMapLegend->readProject( e.document() );
33213320
}
33223321
catch ( std::exception & e )
33233322
{
33243323
QMessageBox::critical( this,
33253324
tr( "QGIS Project Read Error" ),
33263325
QString::fromLocal8Bit( e.what() ) );
33273326
QgsDebugMsg( "BAD QgsMapLayer::LayerType FOUND" );
3327+
mMapCanvas->freeze( false );
3328+
mMapCanvas->refresh();
3329+
return;
33283330
}
33293331

3332+
setTitleBarText_( *this );
3333+
emit projectRead(); // let plug-ins know that we've read in a new
3334+
// project so that they can check any project
3335+
// specific plug-in state
3336+
3337+
// add this to the list of recently used project files
3338+
saveRecentProjectPath( fullPath, settings );
3339+
33303340
mMapCanvas->freeze( false );
33313341
mMapCanvas->refresh();
33323342
}
@@ -3353,33 +3363,14 @@ bool QgisApp::addProject( QString projectFile )
33533363

33543364
try
33553365
{
3356-
if ( QgsProject::instance()->read( projectFile ) )
3357-
{
3358-
setTitleBarText_( *this );
3359-
int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 );
3360-
int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 );
3361-
int myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorBluePart", 255 );
3362-
QColor myColor = QColor( myRedInt, myGreenInt, myBlueInt );
3363-
mMapCanvas->setCanvasColor( myColor ); //this is fill colour before rendering starts
3364-
QgsDebugMsg( "Canvas background color restored..." );
3365-
3366-
mMapCanvas->updateScale();
3367-
QgsDebugMsg( "Scale restored..." );
3368-
3369-
emit projectRead(); // let plug-ins know that we've read in a new
3370-
// project so that they can check any project
3371-
// specific plug-in state
3372-
3373-
// add this to the list of recently used project files
3374-
QSettings settings;
3375-
saveRecentProjectPath( projectFile, settings );
3376-
}
3377-
else
3366+
if ( ! QgsProject::instance()->read( projectFile ) )
33783367
{
33793368
mMapCanvas->freeze( false );
33803369
mMapCanvas->refresh();
33813370
return false;
33823371
}
3372+
// Continue after last catch statement
3373+
33833374
}
33843375
catch ( QgsProjectBadLayerException & e )
33853376
{
@@ -3394,8 +3385,16 @@ bool QgisApp::addProject( QString projectFile )
33943385

33953386
// attempt to find the new locations for missing layers
33963387
// XXX vector file hard-coded -- but what if it's raster?
3388+
QApplication::restoreOverrideCursor();
3389+
33973390
findLayers_( mVectorFileFilter, e.layers() );
3391+
3392+
QApplication::setOverrideCursor( Qt::WaitCursor );
3393+
3394+
// Tell the legend to update the ordering
3395+
mMapLegend->readProject( e.document() );
33983396
}
3397+
// Continue after last catch statement
33993398

34003399
}
34013400
catch ( std::exception & e )
@@ -3406,11 +3405,34 @@ bool QgisApp::addProject( QString projectFile )
34063405
tr( "Unable to open project" ),
34073406
QString::fromLocal8Bit( e.what() ) );
34083407

3408+
QApplication::restoreOverrideCursor();
3409+
34093410
mMapCanvas->freeze( false );
34103411
mMapCanvas->refresh();
34113412
return false;
34123413
}
34133414

3415+
// Continue, now with layers found (hopefully)
3416+
3417+
setTitleBarText_( *this );
3418+
int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 );
3419+
int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 );
3420+
int myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorBluePart", 255 );
3421+
QColor myColor = QColor( myRedInt, myGreenInt, myBlueInt );
3422+
mMapCanvas->setCanvasColor( myColor ); //this is fill colour before rendering starts
3423+
QgsDebugMsg( "Canvas background color restored..." );
3424+
3425+
mMapCanvas->updateScale();
3426+
QgsDebugMsg( "Scale restored..." );
3427+
3428+
emit projectRead(); // let plug-ins know that we've read in a new
3429+
// project so that they can check any project
3430+
// specific plug-in state
3431+
3432+
// add this to the list of recently used project files
3433+
QSettings settings;
3434+
saveRecentProjectPath( projectFile, settings );
3435+
34143436
QApplication::restoreOverrideCursor();
34153437

34163438
mMapCanvas->freeze( false );

src/core/qgsexception.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <list>
2424

2525
#include <QDomNode>
26+
#include <QDomDocument>
2627

2728
/** \ingroup core
2829
* Defines a qgis exception class.
@@ -83,9 +84,10 @@ class QgsProjectBadLayerException : public QgsException
8384
{
8485
public:
8586

86-
QgsProjectBadLayerException( std::list<QDomNode> const & layers )
87-
: QgsException( std::string( msg_ ) ),
88-
mBrokenLayers( layers )
87+
QgsProjectBadLayerException( std::list<QDomNode> const & layers, QDomDocument const & doc = QDomDocument() )
88+
: QgsException( std::string( msg_ ) ),
89+
mBrokenLayers( layers ),
90+
mProjectDom ( doc )
8991
{}
9092

9193
~QgsProjectBadLayerException() throw()
@@ -96,6 +98,10 @@ class QgsProjectBadLayerException : public QgsException
9698
return mBrokenLayers;
9799
}
98100

101+
QDomDocument const & document() const
102+
{
103+
return mProjectDom;
104+
}
99105
private:
100106

101107
/** QDomNodes representing the state of a layer that couldn't be loaded
@@ -106,6 +112,9 @@ class QgsProjectBadLayerException : public QgsException
106112
*/
107113
std::list<QDomNode> mBrokenLayers;
108114

115+
// A default empty document does not contain any extra information
116+
QDomDocument mProjectDom;
117+
109118
static const char * msg_;
110119

111120
}; // class QgsProjectBadLayerException

src/core/qgsproject.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,8 @@ static QgsProjectVersion _getVersion( QDomDocument const &doc )
644644
*/
645645
std::pair< bool, std::list<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &doc )
646646
{
647-
// Layer order is implicit in the order they are stored in the project file
647+
// Layer order is set by the restoring the legend settings from project file.
648+
// This is done on the 'readProject( ... ) signal
648649

649650
QDomNodeList nl = doc.elementsByTagName( "maplayer" );
650651

@@ -847,7 +848,7 @@ bool QgsProject::read()
847848
// doesn't *have* layers -- nor a GUI for that matter -- we'll just
848849
// leave in the whining and boldly stomp on.
849850
emit readProject( *doc );
850-
throw QgsProjectBadLayerException( getMapLayersResults.second );
851+
throw QgsProjectBadLayerException( getMapLayersResults.second, *doc );
851852

852853
// return false;
853854
}

0 commit comments

Comments
 (0)