mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
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.
git-svn-id: http://svn.osgeo.org/qgis/trunk@12349 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
0da6f38336
commit
90eac5ee05
@ -231,6 +231,20 @@ public:
|
||||
@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
|
||||
|
@ -3370,6 +3370,9 @@ void QgisApp::fileOpen()
|
||||
{
|
||||
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 @@ void QgisApp::fileOpen()
|
||||
// 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 @@ bool QgisApp::addProject( QString projectFile )
|
||||
{
|
||||
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,20 +3467,6 @@ bool QgisApp::addProject( QString projectFile )
|
||||
// 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)
|
||||
|
||||
@ -3569,33 +3554,23 @@ bool QgisApp::fileSave()
|
||||
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 @@ void QgisApp::fileSaveAs()
|
||||
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() ) );
|
||||
}
|
||||
}
|
||||
catch ( std::exception & e )
|
||||
if ( QgsProject::instance()->write() )
|
||||
{
|
||||
QMessageBox::critical( 0x0,
|
||||
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 %1" ).arg( QgsProject::instance()->fileName() ),
|
||||
QString::fromLocal8Bit( e.what() ),
|
||||
QgsProject::instance()->error(),
|
||||
QMessageBox::Ok,
|
||||
Qt::NoButton );
|
||||
}
|
||||
@ -3693,20 +3659,8 @@ void QgisApp::openProject( const QString & fileName )
|
||||
// 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 ;
|
||||
}
|
||||
|
@ -56,26 +56,6 @@ class CORE_EXPORT QgsException : public std::exception
|
||||
}; // 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
|
||||
|
||||
|
@ -747,6 +747,8 @@ bool QgsProject::read( QFileInfo const &file )
|
||||
*/
|
||||
bool QgsProject::read()
|
||||
{
|
||||
clearError();
|
||||
|
||||
std::auto_ptr< QDomDocument > doc =
|
||||
std::auto_ptr < QDomDocument > ( new QDomDocument( "qgis" ) );
|
||||
|
||||
@ -755,7 +757,8 @@ bool QgsProject::read()
|
||||
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 @@ bool QgsProject::read()
|
||||
|
||||
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( QFileInfo const &file )
|
||||
|
||||
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 @@ bool QgsProject::write()
|
||||
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 @@ bool QgsProject::write()
|
||||
// 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 @@ bool QgsProject::write()
|
||||
//
|
||||
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 @@ QString QgsProject::writePath( QString src ) const
|
||||
|
||||
return srcElems.join( "/" );
|
||||
}
|
||||
|
||||
void QgsProject::setError( QString errorMessage )
|
||||
{
|
||||
mErrorMessage = errorMessage;
|
||||
}
|
||||
|
||||
QString QgsProject::error() const
|
||||
{
|
||||
return mErrorMessage;
|
||||
}
|
||||
|
||||
void QgsProject::clearError()
|
||||
{
|
||||
setError( QString() );
|
||||
}
|
||||
|
@ -264,6 +264,20 @@ class CORE_EXPORT QgsProject : public QObject
|
||||
@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 @@ class CORE_EXPORT QgsProject : public QObject
|
||||
|
||||
std::pair< bool, std::list<QDomNode> > _getMapLayers( QDomDocument const &doc );
|
||||
|
||||
QString mErrorMessage;
|
||||
|
||||
}; // QgsProject
|
||||
|
||||
#endif
|
||||
|
@ -325,7 +325,7 @@ bool QgsNorthArrowPlugin::calculateNorthDirection()
|
||||
p1 = transform.transform( p1 );
|
||||
p2 = transform.transform( p2 );
|
||||
}
|
||||
catch ( QgsException &e )
|
||||
catch ( QgsCsException &e )
|
||||
{
|
||||
Q_UNUSED( e );
|
||||
// just give up
|
||||
|
Loading…
x
Reference in New Issue
Block a user