From 19f18d9943fca9f22607f6a7d0be6f6c19c19f7a Mon Sep 17 00:00:00 2001 From: homann Date: Thu, 13 Aug 2009 12:13:22 +0000 Subject: [PATCH] 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/qgis@11363 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/app/qgisapp.cpp | 82 ++++++++++++++++++++++++++--------------- src/core/qgsexception.h | 15 ++++++-- src/core/qgsproject.cpp | 5 ++- 3 files changed, 67 insertions(+), 35 deletions(-) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index d875ddac289d..36ee4fa947cc 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -3297,15 +3297,11 @@ void QgisApp::fileOpen() try { - if ( QgsProject::instance()->read() ) + if ( ! QgsProject::instance()->read() ) { - setTitleBarText_( *this ); - emit projectRead(); // let plug-ins know that we've read in a new - // project so that they can check any project - // specific plug-in state - - // add this to the list of recently used project files - saveRecentProjectPath( fullPath, settings ); + mMapCanvas->freeze( false ); + mMapCanvas->refresh(); + return; } } catch ( QgsProjectBadLayerException & e ) @@ -3318,6 +3314,9 @@ void QgisApp::fileOpen() // attempt to find the new locations for missing layers // XXX vector file hard-coded -- but what if it's raster? findLayers_( mVectorFileFilter, e.layers() ); + + // Tell the legend to update the ordering + mMapLegend->readProject( e.document() ); } catch ( std::exception & e ) { @@ -3325,8 +3324,19 @@ void QgisApp::fileOpen() tr( "QGIS Project Read Error" ), QString::fromLocal8Bit( e.what() ) ); QgsDebugMsg( "BAD QgsMapLayer::LayerType FOUND" ); + mMapCanvas->freeze( false ); + mMapCanvas->refresh(); + return; } + setTitleBarText_( *this ); + emit projectRead(); // let plug-ins know that we've read in a new + // project so that they can check any project + // specific plug-in state + + // add this to the list of recently used project files + saveRecentProjectPath( fullPath, settings ); + mMapCanvas->freeze( false ); mMapCanvas->refresh(); } @@ -3353,33 +3363,14 @@ bool QgisApp::addProject( QString projectFile ) try { - if ( QgsProject::instance()->read( projectFile ) ) - { - setTitleBarText_( *this ); - int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 ); - int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 ); - int myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorBluePart", 255 ); - QColor myColor = QColor( myRedInt, myGreenInt, myBlueInt ); - mMapCanvas->setCanvasColor( myColor ); //this is fill colour before rendering starts - QgsDebugMsg( "Canvas background color restored..." ); - - mMapCanvas->updateScale(); - QgsDebugMsg( "Scale restored..." ); - - emit projectRead(); // let plug-ins know that we've read in a new - // project so that they can check any project - // specific plug-in state - - // add this to the list of recently used project files - QSettings settings; - saveRecentProjectPath( projectFile, settings ); - } - else + if ( ! QgsProject::instance()->read( projectFile ) ) { mMapCanvas->freeze( false ); mMapCanvas->refresh(); return false; } + // Continue after last catch statement + } catch ( QgsProjectBadLayerException & e ) { @@ -3394,8 +3385,16 @@ bool QgisApp::addProject( QString projectFile ) // attempt to find the new locations for missing layers // XXX vector file hard-coded -- but what if it's raster? + QApplication::restoreOverrideCursor(); + findLayers_( mVectorFileFilter, e.layers() ); + + QApplication::setOverrideCursor( Qt::WaitCursor ); + + // Tell the legend to update the ordering + mMapLegend->readProject( e.document() ); } + // Continue after last catch statement } catch ( std::exception & e ) @@ -3406,11 +3405,34 @@ bool QgisApp::addProject( QString projectFile ) tr( "Unable to open project" ), QString::fromLocal8Bit( e.what() ) ); + QApplication::restoreOverrideCursor(); + mMapCanvas->freeze( false ); mMapCanvas->refresh(); return false; } + // Continue, now with layers found (hopefully) + + setTitleBarText_( *this ); + int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 ); + int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 ); + int myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorBluePart", 255 ); + QColor myColor = QColor( myRedInt, myGreenInt, myBlueInt ); + mMapCanvas->setCanvasColor( myColor ); //this is fill colour before rendering starts + QgsDebugMsg( "Canvas background color restored..." ); + + mMapCanvas->updateScale(); + QgsDebugMsg( "Scale restored..." ); + + emit projectRead(); // let plug-ins know that we've read in a new + // project so that they can check any project + // specific plug-in state + + // add this to the list of recently used project files + QSettings settings; + saveRecentProjectPath( projectFile, settings ); + QApplication::restoreOverrideCursor(); mMapCanvas->freeze( false ); diff --git a/src/core/qgsexception.h b/src/core/qgsexception.h index 6b3ffb66bae3..96b7b753be41 100644 --- a/src/core/qgsexception.h +++ b/src/core/qgsexception.h @@ -23,6 +23,7 @@ #include #include +#include /** \ingroup core * Defines a qgis exception class. @@ -83,9 +84,10 @@ class QgsProjectBadLayerException : public QgsException { public: - QgsProjectBadLayerException( std::list const & layers ) - : QgsException( std::string( msg_ ) ), - mBrokenLayers( layers ) + QgsProjectBadLayerException( std::list const & layers, QDomDocument const & doc = QDomDocument() ) + : QgsException( std::string( msg_ ) ), + mBrokenLayers( layers ), + mProjectDom ( doc ) {} ~QgsProjectBadLayerException() throw() @@ -96,6 +98,10 @@ class QgsProjectBadLayerException : public QgsException return mBrokenLayers; } + QDomDocument const & document() const + { + return mProjectDom; + } private: /** QDomNodes representing the state of a layer that couldn't be loaded @@ -106,6 +112,9 @@ class QgsProjectBadLayerException : public QgsException */ std::list mBrokenLayers; + // A default empty document does not contain any extra information + QDomDocument mProjectDom; + static const char * msg_; }; // class QgsProjectBadLayerException diff --git a/src/core/qgsproject.cpp b/src/core/qgsproject.cpp index 69b5bfc277ba..8d745aff953d 100644 --- a/src/core/qgsproject.cpp +++ b/src/core/qgsproject.cpp @@ -644,7 +644,8 @@ static QgsProjectVersion _getVersion( QDomDocument const &doc ) */ std::pair< bool, std::list > QgsProject::_getMapLayers( QDomDocument const &doc ) { - // Layer order is implicit in the order they are stored in the project file + // Layer order is set by the restoring the legend settings from project file. + // This is done on the 'readProject( ... ) signal QDomNodeList nl = doc.elementsByTagName( "maplayer" ); @@ -847,7 +848,7 @@ bool QgsProject::read() // doesn't *have* layers -- nor a GUI for that matter -- we'll just // leave in the whining and boldly stomp on. emit readProject( *doc ); - throw QgsProjectBadLayerException( getMapLayersResults.second ); + throw QgsProjectBadLayerException( getMapLayersResults.second, *doc ); // return false; }