[QGIS Commit] r12349 - in trunk/qgis: python/core src/app src/core
src/plugins/north_arrow
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Dec 7 09:22:37 EST 2009
Author: wonder
Date: 2009-12-07 09:22:37 -0500 (Mon, 07 Dec 2009)
New Revision: 12349
Modified:
trunk/qgis/python/core/qgsproject.sip
trunk/qgis/src/app/qgisapp.cpp
trunk/qgis/src/core/qgsexception.h
trunk/qgis/src/core/qgsproject.cpp
trunk/qgis/src/core/qgsproject.h
trunk/qgis/src/plugins/north_arrow/plugin.cpp
Log:
Removed QgsIOException. From now if QgsProject's read() and write() functions return false, it's possible to find out the error message using error() function.
Modified: trunk/qgis/python/core/qgsproject.sip
===================================================================
--- trunk/qgis/python/core/qgsproject.sip 2009-12-07 10:43:06 UTC (rev 12348)
+++ trunk/qgis/python/core/qgsproject.sip 2009-12-07 14:22:37 UTC (rev 12349)
@@ -231,6 +231,20 @@
@note added in 1.3 */
QString readPath( QString filename ) const;
+ /** Return error message from previous read/write
+ @note added in 1.4 */
+ QString error() const;
+
+ protected:
+
+ /** Set error message from read/write operation
+ @note added in 1.4 */
+ void setError( QString errorMessage );
+
+ /** Clear error message
+ @note added in 1.4 */
+ void clearError();
+
signals:
//! emitted when project is being read
Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp 2009-12-07 10:43:06 UTC (rev 12348)
+++ trunk/qgis/src/app/qgisapp.cpp 2009-12-07 14:22:37 UTC (rev 12349)
@@ -3370,6 +3370,9 @@
{
if ( ! QgsProject::instance()->read() )
{
+ QMessageBox::critical( this,
+ tr( "QGIS Project Read Error" ),
+ QgsProject::instance()->error() );
mMapCanvas->freeze( false );
mMapCanvas->refresh();
return;
@@ -3389,16 +3392,6 @@
// 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
@@ -3436,6 +3429,12 @@
{
if ( ! QgsProject::instance()->read( projectFile ) )
{
+ QMessageBox::critical( this,
+ tr( "Unable to open project" ),
+ QgsProject::instance()->error() );
+
+ QApplication::restoreOverrideCursor();
+
mMapCanvas->freeze( false );
mMapCanvas->refresh();
return false;
@@ -3468,21 +3467,7 @@
// Continue after last catch statement
}
- catch ( std::exception & e )
- {
- QgsDebugMsg( "BAD QgsMapLayer::LayerType FOUND" );
- QMessageBox::critical( this,
- 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 );
@@ -3569,33 +3554,23 @@
QgsProject::instance()->setFileName( fullPath.filePath() );
}
- try
+ if ( QgsProject::instance()->write() )
{
- if ( QgsProject::instance()->write() )
- {
- setTitleBarText_( *this ); // update title bar
- statusBar()->showMessage( tr( "Saved project to: %1" ).arg( QgsProject::instance()->fileName() ) );
+ setTitleBarText_( *this ); // update title bar
+ statusBar()->showMessage( tr( "Saved project to: %1" ).arg( QgsProject::instance()->fileName() ) );
- if ( isNewProject )
- {
- // add this to the list of recently used project files
- QSettings settings;
- saveRecentProjectPath( fullPath.filePath(), settings );
- }
- }
- else
+ if ( isNewProject )
{
- QMessageBox::critical( this,
- tr( "Unable to save project" ),
- tr( "Unable to save project to %1" ).arg( QgsProject::instance()->fileName() ) );
- return false;
+ // add this to the list of recently used project files
+ QSettings settings;
+ saveRecentProjectPath( fullPath.filePath(), settings );
}
}
- catch ( std::exception & e )
+ else
{
QMessageBox::critical( this,
tr( "Unable to save project %1" ).arg( QgsProject::instance()->fileName() ),
- QString::fromLocal8Bit( e.what() ) );
+ QgsProject::instance()->error() );
return false;
}
return true;
@@ -3628,29 +3603,20 @@
saveFilePath = myFI.filePath() + ".qgs";
}
- try
- {
- QgsProject::instance()->setFileName( saveFilePath );
+ QgsProject::instance()->setFileName( saveFilePath );
- if ( QgsProject::instance()->write() )
- {
- setTitleBarText_( *this ); // update title bar
- statusBar()->showMessage( tr( "Saved project to: %1" ).arg( QgsProject::instance()->fileName() ) );
- // add this to the list of recently used project files
- saveRecentProjectPath( saveFilePath, settings );
- }
- else
- {
- QMessageBox::critical( this,
- tr( "Unable to save project" ),
- tr( "Unable to save project to %1" ).arg( QgsProject::instance()->fileName() ) );
- }
+ if ( QgsProject::instance()->write() )
+ {
+ setTitleBarText_( *this ); // update title bar
+ statusBar()->showMessage( tr( "Saved project to: %1" ).arg( QgsProject::instance()->fileName() ) );
+ // add this to the list of recently used project files
+ saveRecentProjectPath( saveFilePath, settings );
}
- catch ( std::exception & e )
+ else
{
- QMessageBox::critical( 0x0,
+ QMessageBox::critical( this,
tr( "Unable to save project %1" ).arg( QgsProject::instance()->fileName() ),
- QString::fromLocal8Bit( e.what() ),
+ QgsProject::instance()->error(),
QMessageBox::Ok,
Qt::NoButton );
}
@@ -3693,20 +3659,8 @@
// possibly save any pending work before opening a different project
if ( saveDirty() )
{
- try
- {
- if ( ! addProject( fileName ) )
- {
- QgsDebugMsg( "unable to load project " + fileName );
- }
- }
- catch ( QgsIOException & io_exception )
- {
- Q_UNUSED( io_exception );
- QMessageBox::critical( this,
- tr( "QGIS: Unable to load project" ),
- tr( "Unable to load project %1" ).arg( fileName ) );
- }
+ // error handling and reporting is in addProject() function
+ addProject( fileName );
}
return ;
}
Modified: trunk/qgis/src/core/qgsexception.h
===================================================================
--- trunk/qgis/src/core/qgsexception.h 2009-12-07 10:43:06 UTC (rev 12348)
+++ trunk/qgis/src/core/qgsexception.h 2009-12-07 14:22:37 UTC (rev 12349)
@@ -56,27 +56,7 @@
}; // class QgsException
-/** for Qgis I/O related exceptions
- @note usually thrown for opening file's that don't exist, and the like.
-
-*/
-class QgsIOException : public QgsException
-{
- public:
-
- QgsIOException( std::string const & what )
- : QgsException( what )
- {}
-
- QgsIOException( QString const & what )
- : QgsException( what )
- {}
-
-}; // class QgsIOException
-
-
-
/** for files missing from layers while reading project files
*/
Modified: trunk/qgis/src/core/qgsproject.cpp
===================================================================
--- trunk/qgis/src/core/qgsproject.cpp 2009-12-07 10:43:06 UTC (rev 12348)
+++ trunk/qgis/src/core/qgsproject.cpp 2009-12-07 14:22:37 UTC (rev 12349)
@@ -747,6 +747,8 @@
*/
bool QgsProject::read()
{
+ clearError();
+
std::auto_ptr< QDomDocument > doc =
std::auto_ptr < QDomDocument > ( new QDomDocument( "qgis" ) );
@@ -755,7 +757,8 @@
imp_->file.close(); // even though we got an error, let's make
// sure it's closed anyway
- throw QgsIOException( tr( "Unable to open %1" ).arg( imp_->file.fileName() ) );
+ setError( tr( "Unable to open %1" ).arg( imp_->file.fileName() ) );
+ return false;
}
// location of problem associated with errorMsg
@@ -776,7 +779,8 @@
imp_->file.close();
- throw QgsException( tr( "%1 for file %2" ).arg( errorString ).arg( imp_->file.fileName() ) );
+ setError( tr( "%1 for file %2" ).arg( errorString ).arg( imp_->file.fileName() ) );
+ return false;
}
imp_->file.close();
@@ -922,6 +926,8 @@
bool QgsProject::write()
{
+ clearError();
+
// if we have problems creating or otherwise writing to the project file,
// let's find out up front before we go through all the hand-waving
// necessary to create all the Dom objects
@@ -930,7 +936,8 @@
imp_->file.close(); // even though we got an error, let's make
// sure it's closed anyway
- throw QgsIOException( tr( "Unable to save to file %1" ).arg( imp_->file.fileName() ) );
+ setError( tr( "Unable to save to file %1" ).arg( imp_->file.fileName() ) );
+ return false;
}
QFileInfo myFileInfo( imp_->file );
if ( !myFileInfo.isWritable() )
@@ -938,8 +945,9 @@
// even though we got an error, let's make
// sure it's closed anyway
imp_->file.close();
- throw QgsIOException( tr( "%1 is not writeable. Please adjust permissions (if possible) and try again." )
- .arg( imp_->file.fileName() ) );
+ setError( tr( "%1 is not writeable. Please adjust permissions (if possible) and try again." )
+ .arg( imp_->file.fileName() ) );
+ return false;
}
QDomImplementation DomImplementation;
@@ -1023,10 +1031,11 @@
//
if ( projectFileStream.pos() == -1 || imp_->file.error() != QFile::NoError )
{
- throw QgsIOException( tr( "Unable to save to file %1. Your project "
- "may be corrupted on disk. Try clearing some space on the volume and "
- "check file permissions before pressing save again." )
- .arg( imp_->file.fileName() ) );
+ setError( tr( "Unable to save to file %1. Your project "
+ "may be corrupted on disk. Try clearing some space on the volume and "
+ "check file permissions before pressing save again." )
+ .arg( imp_->file.fileName() ) );
+ return false;
}
dirty( false ); // reset to pristine state
@@ -1456,3 +1465,18 @@
return srcElems.join( "/" );
}
+
+void QgsProject::setError( QString errorMessage )
+{
+ mErrorMessage = errorMessage;
+}
+
+QString QgsProject::error() const
+{
+ return mErrorMessage;
+}
+
+void QgsProject::clearError()
+{
+ setError( QString() );
+}
Modified: trunk/qgis/src/core/qgsproject.h
===================================================================
--- trunk/qgis/src/core/qgsproject.h 2009-12-07 10:43:06 UTC (rev 12348)
+++ trunk/qgis/src/core/qgsproject.h 2009-12-07 14:22:37 UTC (rev 12349)
@@ -264,6 +264,20 @@
@note added in 1.3 */
QString readPath( QString filename ) const;
+ /** Return error message from previous read/write
+ @note added in 1.4 */
+ QString error() const;
+
+ protected:
+
+ /** Set error message from read/write operation
+ @note added in 1.4 */
+ void setError( QString errorMessage );
+
+ /** Clear error message
+ @note added in 1.4 */
+ void clearError();
+
signals:
//! emitted when project is being read
@@ -295,6 +309,8 @@
std::pair< bool, std::list<QDomNode> > _getMapLayers( QDomDocument const &doc );
+ QString mErrorMessage;
+
}; // QgsProject
#endif
Modified: trunk/qgis/src/plugins/north_arrow/plugin.cpp
===================================================================
--- trunk/qgis/src/plugins/north_arrow/plugin.cpp 2009-12-07 10:43:06 UTC (rev 12348)
+++ trunk/qgis/src/plugins/north_arrow/plugin.cpp 2009-12-07 14:22:37 UTC (rev 12349)
@@ -325,7 +325,7 @@
p1 = transform.transform( p1 );
p2 = transform.transform( p2 );
}
- catch ( QgsException &e )
+ catch ( QgsCsException &e )
{
Q_UNUSED( e );
// just give up
More information about the QGIS-commit
mailing list