Skip to content
Permalink
Browse files

Re-order layers after finding missing files. Also restructured the ex…

…ception logic in qgisapp.cpp. Fixes #1561

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11363 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann
homann committed Aug 13, 2009
1 parent c23f508 commit 19f18d9943fca9f22607f6a7d0be6f6c19c19f7a
Showing with 67 additions and 35 deletions.
  1. +52 −30 src/app/qgisapp.cpp
  2. +12 −3 src/core/qgsexception.h
  3. +3 −2 src/core/qgsproject.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,15 +3314,29 @@ 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 )
{
QMessageBox::critical( this,
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 );
@@ -23,6 +23,7 @@
#include <list>

#include <QDomNode>
#include <QDomDocument>

/** \ingroup core
* Defines a qgis exception class.
@@ -83,9 +84,10 @@ class QgsProjectBadLayerException : public QgsException
{
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 @@ 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<QDomNode> mBrokenLayers;

// A default empty document does not contain any extra information
QDomDocument mProjectDom;

static const char * msg_;

}; // class QgsProjectBadLayerException
@@ -644,7 +644,8 @@ static QgsProjectVersion _getVersion( QDomDocument const &doc )
*/
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 @@ 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;
}

0 comments on commit 19f18d9

Please sign in to comment.
You can’t perform that action at this time.