Skip to content

Commit

Permalink
Re-order layers after finding missing files. Also restructured the ex…
Browse files Browse the repository at this point in the history
…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 committed Aug 13, 2009
1 parent c23f508 commit 19f18d9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 35 deletions.
82 changes: 52 additions & 30 deletions src/app/qgisapp.cpp
Expand Up @@ -3297,15 +3297,11 @@ void QgisApp::fileOpen()


try try
{ {
if ( QgsProject::instance()->read() ) if ( ! QgsProject::instance()->read() )
{ {
setTitleBarText_( *this ); mMapCanvas->freeze( false );
emit projectRead(); // let plug-ins know that we've read in a new mMapCanvas->refresh();
// project so that they can check any project return;
// specific plug-in state

// add this to the list of recently used project files
saveRecentProjectPath( fullPath, settings );
} }
} }
catch ( QgsProjectBadLayerException & e ) catch ( QgsProjectBadLayerException & e )
Expand All @@ -3318,15 +3314,29 @@ void QgisApp::fileOpen()
// attempt to find the new locations for missing layers // attempt to find the new locations for missing layers
// XXX vector file hard-coded -- but what if it's raster? // XXX vector file hard-coded -- but what if it's raster?
findLayers_( mVectorFileFilter, e.layers() ); findLayers_( mVectorFileFilter, e.layers() );

// Tell the legend to update the ordering
mMapLegend->readProject( e.document() );
} }
catch ( std::exception & e ) catch ( std::exception & e )
{ {
QMessageBox::critical( this, QMessageBox::critical( this,
tr( "QGIS Project Read Error" ), tr( "QGIS Project Read Error" ),
QString::fromLocal8Bit( e.what() ) ); QString::fromLocal8Bit( e.what() ) );
QgsDebugMsg( "BAD QgsMapLayer::LayerType FOUND" ); 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->freeze( false );
mMapCanvas->refresh(); mMapCanvas->refresh();
} }
Expand All @@ -3353,33 +3363,14 @@ bool QgisApp::addProject( QString projectFile )


try 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->freeze( false );
mMapCanvas->refresh(); mMapCanvas->refresh();
return false; return false;
} }
// Continue after last catch statement

} }
catch ( QgsProjectBadLayerException & e ) catch ( QgsProjectBadLayerException & e )
{ {
Expand All @@ -3394,8 +3385,16 @@ bool QgisApp::addProject( QString projectFile )


// attempt to find the new locations for missing layers // attempt to find the new locations for missing layers
// XXX vector file hard-coded -- but what if it's raster? // XXX vector file hard-coded -- but what if it's raster?
QApplication::restoreOverrideCursor();

findLayers_( mVectorFileFilter, e.layers() ); 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 ) catch ( std::exception & e )
Expand All @@ -3406,11 +3405,34 @@ bool QgisApp::addProject( QString projectFile )
tr( "Unable to open project" ), tr( "Unable to open project" ),
QString::fromLocal8Bit( e.what() ) ); QString::fromLocal8Bit( e.what() ) );


QApplication::restoreOverrideCursor();

mMapCanvas->freeze( false ); mMapCanvas->freeze( false );
mMapCanvas->refresh(); mMapCanvas->refresh();
return false; 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(); QApplication::restoreOverrideCursor();


mMapCanvas->freeze( false ); mMapCanvas->freeze( false );
Expand Down
15 changes: 12 additions & 3 deletions src/core/qgsexception.h
Expand Up @@ -23,6 +23,7 @@
#include <list> #include <list>


#include <QDomNode> #include <QDomNode>
#include <QDomDocument>


/** \ingroup core /** \ingroup core
* Defines a qgis exception class. * Defines a qgis exception class.
Expand Down Expand Up @@ -83,9 +84,10 @@ class QgsProjectBadLayerException : public QgsException
{ {
public: public:


QgsProjectBadLayerException( std::list<QDomNode> const & layers ) QgsProjectBadLayerException( std::list<QDomNode> const & layers, QDomDocument const & doc = QDomDocument() )
: QgsException( std::string( msg_ ) ), : QgsException( std::string( msg_ ) ),
mBrokenLayers( layers ) mBrokenLayers( layers ),
mProjectDom ( doc )
{} {}


~QgsProjectBadLayerException() throw() ~QgsProjectBadLayerException() throw()
Expand All @@ -96,6 +98,10 @@ class QgsProjectBadLayerException : public QgsException
return mBrokenLayers; return mBrokenLayers;
} }


QDomDocument const & document() const
{
return mProjectDom;
}
private: private:


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


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

static const char * msg_; static const char * msg_;


}; // class QgsProjectBadLayerException }; // class QgsProjectBadLayerException
Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsproject.cpp
Expand Up @@ -644,7 +644,8 @@ static QgsProjectVersion _getVersion( QDomDocument const &doc )
*/ */
std::pair< bool, std::list<QDomNode> > QgsProject::_getMapLayers( 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" ); QDomNodeList nl = doc.elementsByTagName( "maplayer" );


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


// return false; // return false;
} }
Expand Down

0 comments on commit 19f18d9

Please sign in to comment.