Skip to content

Commit f05e245

Browse files
author
pcav
committedAug 19, 2009

File tree

8 files changed

+142
-164
lines changed

8 files changed

+142
-164
lines changed
 

‎DONORS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Ivan Marchesini|http://www.gfosservices.it/
3232
James Crone
3333
Jaroslaw Kowalczyk
3434
Jason Jorgenson
35-
John C. Tull
35+
John C. Tull|http://www.wildnevada.org
3636
John Dean
3737
Kanton Solothurn SOGIS
3838
Kevin Shook

‎src/plugins/grass/qgsgrassmodel.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class QgsGrassModelItem
3737
{
3838
public:
3939
QgsGrassModelItem( QgsGrassModelItem *parent, int row, QString name,
40-
QString path, int type );
40+
QString path, int type );
4141
QgsGrassModelItem();
4242
~QgsGrassModelItem();
4343

@@ -81,7 +81,7 @@ QgsGrassModelItem::QgsGrassModelItem()
8181

8282
QgsGrassModelItem::~QgsGrassModelItem()
8383
{
84-
for ( int i = 0; i < mChildren.size();i++ )
84+
for ( int i = 0; i < mChildren.size(); i++ )
8585
{
8686
delete mChildren[i];
8787
}
@@ -606,13 +606,13 @@ void QgsGrassModel::addItems( QgsGrassModelItem *item, QStringList list, int typ
606606

607607
// Add new items
608608

609-
for ( int i = 0; i < list.size();i++ )
609+
for ( int i = 0; i < list.size(); i++ )
610610
{
611611
QString name = list.at( i );
612612
// QgsDebugMsg(QString("? add %1").arg(name));
613613

614614
int insertAt = item->mChildren.size();
615-
for ( int i = 0; i < item->mChildren.size();i++ )
615+
for ( int i = 0; i < item->mChildren.size(); i++ )
616616
{
617617
if ( item->mChildren[i]->name() == name )
618618
{
@@ -897,7 +897,6 @@ QVariant QgsGrassModel::data( const QModelIndex &index, int role ) const
897897
default:
898898
return mIconDirectory;
899899
}
900-
return mIconDirectory;
901900
}
902901
return item->data( role );
903902
}

‎src/plugins/grass/qgsgrassnewmapset.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,17 +1268,20 @@ void QgsGrassNewMapset::createMapset()
12681268

12691269
int ret = 0;
12701270

1271-
QgsGrass::resetError();
1272-
if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
1271+
try
12731272
{
12741273
ret = G_make_location( location.toAscii().data(), &mCellHead, mProjInfo, mProjUnits, stdout );
12751274
}
1276-
QgsGrass::clearErrorEnv();
1275+
catch ( QgsGrass::Exception &e )
1276+
{
1277+
ret = -1;
1278+
Q_UNUSED( e );
1279+
}
12771280

1278-
if ( QgsGrass::getError() == QgsGrass::FATAL || ret != 0 )
1281+
if ( ret != 0 )
12791282
{
12801283
QMessageBox::warning( this, tr( "Create location" ),
1281-
tr( "Cannot create new location: %1" ).arg( QgsGrass::getErrorMessage() ) );
1284+
tr( "Cannot create new location: %1" ).arg( QgsGrass::errorMessage() ) );
12821285
return;
12831286
}
12841287

‎src/plugins/grass/qgsgrassplugin.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,13 @@ void QgsGrassPlugin::addVector()
301301
QgsGrass::setLocation( sel->gisdbase, sel->location );
302302

303303
/* Open vector */
304-
QgsGrass::resetError();
305-
Vect_set_open_level( 2 );
306-
struct Map_info map;
307-
int level = Vect_open_old_head( &map, sel->map.toAscii().data(),
308-
sel->mapset.toAscii().data() );
309-
310-
if ( QgsGrass::getError() != QgsGrass::FATAL )
304+
try
311305
{
306+
Vect_set_open_level( 2 );
307+
struct Map_info map;
308+
int level = Vect_open_old_head( &map, sel->map.toAscii().data(),
309+
sel->mapset.toAscii().data() );
310+
312311
if ( level >= 2 )
313312
{
314313
// Count layers
@@ -336,9 +335,9 @@ void QgsGrassPlugin::addVector()
336335

337336
Vect_close( &map );
338337
}
339-
else
338+
catch ( QgsGrass::Exception &e )
340339
{
341-
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( QgsGrass::getErrorMessage() ) );
340+
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( e.what() ) );
342341
}
343342

344343
qGisInterface->addVectorLayer( uri, name, "grass" );
@@ -486,25 +485,28 @@ void QgsGrassPlugin::newVector()
486485
QgsGrass::getDefaultLocation(),
487486
QgsGrass::getDefaultMapset() );
488487

489-
QgsGrass::resetError();
490-
struct Map_info Map;
491-
Vect_open_new( &Map, name.toAscii().data(), 0 );
492-
493-
if ( QgsGrass::getError() == QgsGrass::FATAL )
488+
try
494489
{
495-
QMessageBox::warning( 0, tr( "Warning" ),
496-
tr( "Cannot create new vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
497-
return;
498-
}
490+
struct Map_info Map;
491+
Vect_open_new( &Map, name.toAscii().data(), 0 );
499492

500493
#if defined(GRASS_VERSION_MAJOR) && defined(GRASS_VERSION_MINOR) && \
501494
( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6 )
502-
Vect_build( &Map );
495+
Vect_build( &Map );
503496
#else
504-
Vect_build( &Map, stderr );
497+
Vect_build( &Map, stderr );
505498
#endif
506-
Vect_set_release_support( &Map );
507-
Vect_close( &Map );
499+
Vect_set_release_support( &Map );
500+
Vect_close( &Map );
501+
}
502+
catch ( QgsGrass::Exception &e )
503+
{
504+
QMessageBox::warning( 0, tr( "Warning" ),
505+
tr( "Cannot create new vector: %1" ).arg( e.what() ) );
506+
return;
507+
}
508+
509+
508510

509511
// Open in GRASS vector provider
510512

‎src/plugins/grass/qgsgrassselect.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,15 +410,14 @@ QStringList QgsGrassSelect::vectorLayers( QString gisdbase,
410410
// Call to setjmp() returns 0 first time. In case of fatal error,
411411
// our error routine uses longjmp() to come back to this context,
412412
// this time setjmp() will return non-zero value and we can continue...
413-
if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
413+
414+
try
414415
{
415416
level = Vect_open_old_head( &map, ( char * ) mapName.toAscii().data(), ( char * ) mapset.toAscii().data() );
416417
}
417-
QgsGrass::clearErrorEnv();
418-
419-
if ( QgsGrass::getError() == QgsGrass::FATAL )
418+
catch ( QgsGrass::Exception &e )
420419
{
421-
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
420+
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
422421
return list;
423422
}
424423

‎src/providers/grass/qgsgrass.cpp

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ void GRASS_EXPORT QgsGrass::init( void )
5454
// Set error function
5555
G_set_error_routine( &error_routine );
5656

57-
if ( initialized ) return;
57+
if ( initialized )
58+
return;
5859

5960
QSettings settings;
6061

@@ -355,7 +356,7 @@ int QgsGrass::initialized = 0;
355356

356357
bool QgsGrass::active = 0;
357358

358-
QgsGrass::GERROR QgsGrass::error = QgsGrass::OK;
359+
QgsGrass::GERROR QgsGrass::lastError = QgsGrass::OK;
359360

360361
QString QgsGrass::error_message;
361362

@@ -367,9 +368,6 @@ QString QgsGrass::mMapsetLock;
367368
QString QgsGrass::mGisrc;
368369
QString QgsGrass::mTmp;
369370

370-
jmp_buf QgsGrass::mFatalErrorEnv;
371-
bool QgsGrass::mFatalErrorEnvActive = false;
372-
373371
int QgsGrass::error_routine( char *msg, int fatal )
374372
{
375373
return error_routine(( const char* ) msg, fatal );
@@ -383,52 +381,30 @@ int QgsGrass::error_routine( const char *msg, int fatal )
383381

384382
if ( fatal )
385383
{
386-
error = FATAL;
387384
// we have to do a long jump here, otherwise GRASS >= 6.3 will kill our process
388-
if ( mFatalErrorEnvActive )
389-
longjmp( mFatalErrorEnv, 1 );
390-
else
391-
{
392-
QMessageBox::warning( 0, QObject::tr( "Uncatched fatal GRASS error" ), msg );
393-
abort();
394-
}
385+
throw QgsGrass::Exception( msg );
395386
}
396387
else
397-
error = WARNING;
388+
lastError = WARNING;
398389

399390
return 1;
400391
}
401392

402393
void GRASS_EXPORT QgsGrass::resetError( void )
403394
{
404-
error = OK;
395+
lastError = OK;
405396
}
406397

407-
int GRASS_EXPORT QgsGrass::getError( void )
398+
int GRASS_EXPORT QgsGrass::error( void )
408399
{
409-
return error;
400+
return lastError;
410401
}
411402

412-
QString GRASS_EXPORT QgsGrass::getErrorMessage( void )
403+
QString GRASS_EXPORT QgsGrass::errorMessage( void )
413404
{
414405
return error_message;
415406
}
416407

417-
jmp_buf GRASS_EXPORT &QgsGrass::fatalErrorEnv()
418-
{
419-
if ( mFatalErrorEnvActive )
420-
QgsDebugMsg( "fatal error environment already active." );
421-
mFatalErrorEnvActive = true;
422-
return mFatalErrorEnv;
423-
}
424-
425-
void GRASS_EXPORT QgsGrass::clearErrorEnv()
426-
{
427-
if ( !mFatalErrorEnvActive )
428-
QgsDebugMsg( "fatal error environment already deactive." );
429-
mFatalErrorEnvActive = false;
430-
}
431-
432408
QString GRASS_EXPORT QgsGrass::openMapset( QString gisdbase, QString location, QString mapset )
433409
{
434410
QgsDebugMsg( QString( "gisdbase = %1" ).arg( gisdbase.toLocal8Bit().constData() ) );

‎src/providers/grass/qgsgrass.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,21 @@ extern "C"
2424
}
2525

2626
#include <QString>
27-
#include <setjmp.h>
2827

2928
/*!
3029
Methods for C library initialization and error handling.
3130
*/
3231
class QgsGrass
3332
{
34-
3533
public:
34+
class Exception
35+
{
36+
QString mMsg;
37+
public:
38+
Exception( const char *msg ) : mMsg( msg ) {}
39+
QString what() const { return mMsg; }
40+
};
41+
3642
//! Get info about the mode
3743
/*! QgsGrass may be running in active or passive mode.
3844
* Active mode means that GISRC is set up and GISRC file is available,
@@ -64,10 +70,9 @@ class QgsGrass
6470
*/
6571
static GRASS_EXPORT void setMapset( QString gisdbase, QString location, QString mapset );
6672

67-
//! Error codes returned by GetError()
73+
//! Error codes returned by error()
6874
enum GERROR { OK, /*!< OK. No error. */
69-
WARNING, /*!< Warning, non fatal error. Should be printed by application. */
70-
FATAL /*!< Fatal error. Function faild. */
75+
WARNING /*!< Warning, non fatal error. Should be printed by application. */
7176
};
7277

7378
//! Map type
@@ -77,10 +82,10 @@ class QgsGrass
7782
static GRASS_EXPORT void resetError( void ); // reset error status
7883

7984
//! Check if any error occured in lately called functions. Returns value from ERROR.
80-
static GRASS_EXPORT int getError( void );
85+
static GRASS_EXPORT int error( void );
8186

8287
//! Get last error message
83-
static GRASS_EXPORT QString getErrorMessage( void );
88+
static GRASS_EXPORT QString errorMessage( void );
8489

8590
/** \brief Open existing GRASS mapset
8691
* \return NULL string or error message
@@ -160,10 +165,6 @@ class QgsGrass
160165
static GRASS_EXPORT int versionRelease();
161166
static GRASS_EXPORT QString versionString();
162167

163-
static GRASS_EXPORT jmp_buf& fatalErrorEnv();
164-
static GRASS_EXPORT void clearErrorEnv();
165-
166-
167168
private:
168169
static int initialized; // Set to 1 after initialization
169170
static bool active; // is active mode
@@ -172,7 +173,7 @@ class QgsGrass
172173
static QString defaultMapset;
173174

174175
/* last error in GRASS libraries */
175-
static GERROR error; // static, because used in constructor
176+
static GERROR lastError; // static, because used in constructor
176177
static QString error_message;
177178

178179
// G_set_error_routine has two versions of the function's first argument it expects:
@@ -188,10 +189,6 @@ class QgsGrass
188189
static QString mGisrc;
189190
// Temporary directory where GISRC and sockets are stored
190191
static QString mTmp;
191-
192-
// Context saved before a call to routine that can produce a fatal error
193-
static jmp_buf mFatalErrorEnv;
194-
static bool mFatalErrorEnvActive;
195192
};
196193

197194
#endif // QGSGRASS_H

0 commit comments

Comments
 (0)
Please sign in to comment.