[QGIS Commit] r11363 - in trunk/qgis/src: app core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Aug 13 08:13:22 EDT 2009
Author: homann
Date: 2009-08-13 08:13:22 -0400 (Thu, 13 Aug 2009)
New Revision: 11363
Modified:
trunk/qgis/src/app/qgisapp.cpp
trunk/qgis/src/core/qgsexception.h
trunk/qgis/src/core/qgsproject.cpp
Log:
Re-order layers after finding missing files. Also restructured the exception logic in qgisapp.cpp. Fixes #1561
Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp 2009-08-13 06:57:37 UTC (rev 11362)
+++ trunk/qgis/src/app/qgisapp.cpp 2009-08-13 12:13:22 UTC (rev 11363)
@@ -3297,15 +3297,11 @@
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 @@
// 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 @@
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 @@
try
{
- if ( QgsProject::instance()->read( projectFile ) )
+ 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
- {
mMapCanvas->freeze( false );
mMapCanvas->refresh();
return false;
}
+ // Continue after last catch statement
+
}
catch ( QgsProjectBadLayerException & e )
{
@@ -3394,8 +3385,16 @@
// 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 @@
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 );
Modified: trunk/qgis/src/core/qgsexception.h
===================================================================
--- trunk/qgis/src/core/qgsexception.h 2009-08-13 06:57:37 UTC (rev 11362)
+++ trunk/qgis/src/core/qgsexception.h 2009-08-13 12:13:22 UTC (rev 11363)
@@ -23,6 +23,7 @@
#include <list>
#include <QDomNode>
+#include <QDomDocument>
/** \ingroup core
* Defines a qgis exception class.
@@ -83,9 +84,10 @@
{
public:
- QgsProjectBadLayerException( std::list<QDomNode> const & layers )
- : QgsException( std::string( msg_ ) ),
- mBrokenLayers( layers )
+ QgsProjectBadLayerException( std::list<QDomNode> const & layers, QDomDocument const & doc = QDomDocument() )
+ : QgsException( std::string( msg_ ) ),
+ mBrokenLayers( layers ),
+ mProjectDom ( doc )
{}
~QgsProjectBadLayerException() throw()
@@ -96,6 +98,10 @@
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 @@
*/
std::list<QDomNode> mBrokenLayers;
+ // A default empty document does not contain any extra information
+ QDomDocument mProjectDom;
+
static const char * msg_;
}; // class QgsProjectBadLayerException
Modified: trunk/qgis/src/core/qgsproject.cpp
===================================================================
--- trunk/qgis/src/core/qgsproject.cpp 2009-08-13 06:57:37 UTC (rev 11362)
+++ trunk/qgis/src/core/qgsproject.cpp 2009-08-13 12:13:22 UTC (rev 11363)
@@ -644,7 +644,8 @@
*/
std::pair< bool, std::list<QDomNode> > 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 @@
// 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;
}
More information about the QGIS-commit
mailing list