Skip to content

Commit 0ded855

Browse files
committedOct 15, 2015
[GRASS] show init error in tools title
1 parent c358aea commit 0ded855

File tree

7 files changed

+32
-16
lines changed

7 files changed

+32
-16
lines changed
 

‎src/plugins/grass/qgsgrassplugin.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,15 @@ void QgsGrassPlugin::onGisbaseChanged()
298298
if ( !QgsGrass::init() )
299299
{
300300
// TODO: save init error and get it here more reliably
301-
qGisInterface->messageBar()->pushMessage( tr( "GRASS error" ), QgsGrass::errorMessage(), QgsMessageBar::WARNING );
301+
QString error = tr( "GRASS init error" );
302+
qGisInterface->messageBar()->pushMessage( error, QgsGrass::initError(), QgsMessageBar::WARNING );
302303

303304
mOpenToolsAction->setDisabled( false ); // allow to open to see that tools are disabled
304305
mRegionAction->setDisabled( true );
305306
mOpenMapsetAction->setDisabled( true );
306307
mCloseMapsetAction->setDisabled( true );
307308

309+
mTools->setWindowTitle( error + " : " + QgsGrass::initError() );
308310
mTools->setDisabled( true );
309311
}
310312
else
@@ -316,6 +318,7 @@ void QgsGrassPlugin::onGisbaseChanged()
316318
mCloseMapsetAction->setDisabled( !QgsGrass::activeMode() );
317319

318320
mTools->setDisabled( false );
321+
mTools->resetTitle();
319322
}
320323
}
321324

‎src/plugins/grass/qgsgrasstools.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,13 @@ QgsGrassTools::QgsGrassTools( QgisInterface *iface, QWidget * parent, const char
163163

164164
qRegisterMetaType<QgsDetailedItemData>();
165165

166-
setWindowTitle( tr( "GRASS Tools" ) );
167-
// setupUi(this);
168-
169166
mIface = iface;
170167
mCanvas = mIface->mapCanvas();
171168

172169
//statusBar()->hide();
173170

174171
// set the dialog title
175-
QString title = tr( "GRASS Tools: %1/%2" ).arg( QgsGrass::getDefaultLocation(), QgsGrass::getDefaultMapset() );
176-
setWindowTitle( title );
172+
resetTitle();
177173

178174
// Tree view code.
179175
if ( !QgsGrass::modulesDebug() )
@@ -218,10 +214,8 @@ QgsGrassTools::QgsGrassTools( QgisInterface *iface, QWidget * parent, const char
218214
showTabs();
219215
}
220216

221-
void QgsGrassTools::showTabs()
217+
void QgsGrassTools::resetTitle()
222218
{
223-
QgsDebugMsg( "entered." );
224-
225219
QString title;
226220
if ( QgsGrass::activeMode() )
227221
{
@@ -232,6 +226,13 @@ void QgsGrassTools::showTabs()
232226
title = tr( "GRASS Tools" );
233227
}
234228
setWindowTitle( title );
229+
}
230+
231+
void QgsGrassTools::showTabs()
232+
{
233+
QgsDebugMsg( "entered." );
234+
235+
resetTitle();
235236

236237
// Build modules tree if empty
237238
QgsDebugMsg( QString( "mTreeModel->rowCount() = %1" ).arg( mTreeModel->rowCount() ) );

‎src/plugins/grass/qgsgrasstools.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class QgsGrassTools: public QDockWidget, public Ui::QgsGrassToolsBase
5757
//! Returns application directory
5858
QString appDir();
5959

60+
void resetTitle();
61+
6062
public slots:
6163
bool loadConfig();
6264

‎src/providers/grass/qgsgrass.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ bool QgsGrass::init( void )
350350
}
351351
G_CATCH( QgsGrass::Exception &e )
352352
{
353-
error_message = tr( "Problem in GRASS initialization, GRASS provider and plugin will not work" ) + " : " + e.what();
354-
QgsDebugMsg( error_message );
353+
mInitError = tr( "Problem in GRASS initialization, GRASS provider and plugin will not work" ) + " : " + e.what();
354+
QgsDebugMsg( mInitError );
355355
mNonInitializable = true;
356356
unlock();
357357
return false;
@@ -373,8 +373,8 @@ bool QgsGrass::init( void )
373373
if ( !isValidGrassBaseDir( gisbase() ) )
374374
{
375375
mNonInitializable = true;
376-
error_message = tr( "GRASS was not found in '%1'(GISBASE), provider and plugin will not work." ).arg( gisbase() );
377-
QgsDebugMsg( error_message );
376+
mInitError = tr( "GRASS was not found in '%1' (GISBASE), provider and plugin will not work." ).arg( gisbase() );
377+
QgsDebugMsg( mInitError );
378378
#if 0
379379
// TODO: how to emit message from provider (which does not know about QgisApp)
380380
QgisApp::instance()->messageBar()->pushMessage( tr( "GRASS error" ),
@@ -742,6 +742,7 @@ bool QgsGrass::active = 0;
742742
QgsGrass::GERROR QgsGrass::lastError = QgsGrass::OK;
743743

744744
QString QgsGrass::error_message;
745+
QString QgsGrass::mInitError;
745746

746747
QStringList QgsGrass::mGrassModulesPaths;
747748
QString QgsGrass::defaultGisdbase;
@@ -2655,9 +2656,10 @@ void QgsGrass::setGisbase( bool custom, const QString &customDir )
26552656
{
26562657
mNonInitializable = false;
26572658
initialized = false;
2659+
mInitError.clear();
26582660
if ( !QgsGrass::init() )
26592661
{
2660-
QgsDebugMsg( "cannot init : " + QgsGrass::errorMessage() );
2662+
QgsDebugMsg( "cannot init : " + QgsGrass::initError() );
26612663
}
26622664
emit gisbaseChanged();
26632665
}

‎src/providers/grass/qgsgrass.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
248248
//! Get last error message
249249
static QString errorMessage( void );
250250

251+
//! Get initialization error
252+
static QString initError() { return mInitError; }
253+
251254
/** Test is current user is owner of mapset */
252255
static bool isOwner( const QString& gisdbase, const QString& location, const QString& mapset );
253256

@@ -657,6 +660,8 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
657660
/* last error in GRASS libraries */
658661
static GERROR lastError; // static, because used in constructor
659662
static QString error_message;
663+
// error set in init() if it failed
664+
static QString mInitError;
660665

661666
// G_set_error_routine has two versions of the function's first argument it expects:
662667
// - char* msg - older version

‎src/providers/grass/qgsgrassprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ QgsGrassProvider::QgsGrassProvider( QString uri )
116116
mValid = false;
117117
if ( !QgsGrass::init() )
118118
{
119-
appendError( QgsGrass::errorMessage() );
119+
appendError( QgsGrass::initError() );
120120
return;
121121
}
122122

‎tests/src/providers/grass/testqgsgrassprovider.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ void TestQgsGrassProvider::initTestCase()
220220
#endif
221221

222222
QgsGrass::setMute();
223-
QgsGrass::init();
223+
if ( !QgsGrass::init() )
224+
{
225+
reportRow( "Cannot init GRASS: " + QgsGrass::initError() );
226+
}
224227

225228
//create some objects that will be used in all tests...
226229
//create a raster layer that will be used in all tests...

0 commit comments

Comments
 (0)
Please sign in to comment.