Skip to content

Commit

Permalink
[GRASS] show init error in tools title
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Oct 15, 2015
1 parent c358aea commit 0ded855
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/plugins/grass/qgsgrassplugin.cpp
Expand Up @@ -298,13 +298,15 @@ void QgsGrassPlugin::onGisbaseChanged()
if ( !QgsGrass::init() )
{
// TODO: save init error and get it here more reliably
qGisInterface->messageBar()->pushMessage( tr( "GRASS error" ), QgsGrass::errorMessage(), QgsMessageBar::WARNING );
QString error = tr( "GRASS init error" );
qGisInterface->messageBar()->pushMessage( error, QgsGrass::initError(), QgsMessageBar::WARNING );

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

mTools->setWindowTitle( error + " : " + QgsGrass::initError() );
mTools->setDisabled( true );
}
else
Expand All @@ -316,6 +318,7 @@ void QgsGrassPlugin::onGisbaseChanged()
mCloseMapsetAction->setDisabled( !QgsGrass::activeMode() );

mTools->setDisabled( false );
mTools->resetTitle();
}
}

Expand Down
17 changes: 9 additions & 8 deletions src/plugins/grass/qgsgrasstools.cpp
Expand Up @@ -163,17 +163,13 @@ QgsGrassTools::QgsGrassTools( QgisInterface *iface, QWidget * parent, const char

qRegisterMetaType<QgsDetailedItemData>();

setWindowTitle( tr( "GRASS Tools" ) );
// setupUi(this);

mIface = iface;
mCanvas = mIface->mapCanvas();

//statusBar()->hide();

// set the dialog title
QString title = tr( "GRASS Tools: %1/%2" ).arg( QgsGrass::getDefaultLocation(), QgsGrass::getDefaultMapset() );
setWindowTitle( title );
resetTitle();

// Tree view code.
if ( !QgsGrass::modulesDebug() )
Expand Down Expand Up @@ -218,10 +214,8 @@ QgsGrassTools::QgsGrassTools( QgisInterface *iface, QWidget * parent, const char
showTabs();
}

void QgsGrassTools::showTabs()
void QgsGrassTools::resetTitle()
{
QgsDebugMsg( "entered." );

QString title;
if ( QgsGrass::activeMode() )
{
Expand All @@ -232,6 +226,13 @@ void QgsGrassTools::showTabs()
title = tr( "GRASS Tools" );
}
setWindowTitle( title );
}

void QgsGrassTools::showTabs()
{
QgsDebugMsg( "entered." );

resetTitle();

// Build modules tree if empty
QgsDebugMsg( QString( "mTreeModel->rowCount() = %1" ).arg( mTreeModel->rowCount() ) );
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/grass/qgsgrasstools.h
Expand Up @@ -57,6 +57,8 @@ class QgsGrassTools: public QDockWidget, public Ui::QgsGrassToolsBase
//! Returns application directory
QString appDir();

void resetTitle();

public slots:
bool loadConfig();

Expand Down
12 changes: 7 additions & 5 deletions src/providers/grass/qgsgrass.cpp
Expand Up @@ -350,8 +350,8 @@ bool QgsGrass::init( void )
}
G_CATCH( QgsGrass::Exception &e )
{
error_message = tr( "Problem in GRASS initialization, GRASS provider and plugin will not work" ) + " : " + e.what();
QgsDebugMsg( error_message );
mInitError = tr( "Problem in GRASS initialization, GRASS provider and plugin will not work" ) + " : " + e.what();
QgsDebugMsg( mInitError );
mNonInitializable = true;
unlock();
return false;
Expand All @@ -373,8 +373,8 @@ bool QgsGrass::init( void )
if ( !isValidGrassBaseDir( gisbase() ) )
{
mNonInitializable = true;
error_message = tr( "GRASS was not found in '%1'(GISBASE), provider and plugin will not work." ).arg( gisbase() );
QgsDebugMsg( error_message );
mInitError = tr( "GRASS was not found in '%1' (GISBASE), provider and plugin will not work." ).arg( gisbase() );
QgsDebugMsg( mInitError );
#if 0
// TODO: how to emit message from provider (which does not know about QgisApp)
QgisApp::instance()->messageBar()->pushMessage( tr( "GRASS error" ),
Expand Down Expand Up @@ -742,6 +742,7 @@ bool QgsGrass::active = 0;
QgsGrass::GERROR QgsGrass::lastError = QgsGrass::OK;

QString QgsGrass::error_message;
QString QgsGrass::mInitError;

QStringList QgsGrass::mGrassModulesPaths;
QString QgsGrass::defaultGisdbase;
Expand Down Expand Up @@ -2655,9 +2656,10 @@ void QgsGrass::setGisbase( bool custom, const QString &customDir )
{
mNonInitializable = false;
initialized = false;
mInitError.clear();
if ( !QgsGrass::init() )
{
QgsDebugMsg( "cannot init : " + QgsGrass::errorMessage() );
QgsDebugMsg( "cannot init : " + QgsGrass::initError() );
}
emit gisbaseChanged();
}
Expand Down
5 changes: 5 additions & 0 deletions src/providers/grass/qgsgrass.h
Expand Up @@ -248,6 +248,9 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
//! Get last error message
static QString errorMessage( void );

//! Get initialization error
static QString initError() { return mInitError; }

/** Test is current user is owner of mapset */
static bool isOwner( const QString& gisdbase, const QString& location, const QString& mapset );

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

// G_set_error_routine has two versions of the function's first argument it expects:
// - char* msg - older version
Expand Down
2 changes: 1 addition & 1 deletion src/providers/grass/qgsgrassprovider.cpp
Expand Up @@ -116,7 +116,7 @@ QgsGrassProvider::QgsGrassProvider( QString uri )
mValid = false;
if ( !QgsGrass::init() )
{
appendError( QgsGrass::errorMessage() );
appendError( QgsGrass::initError() );
return;
}

Expand Down
5 changes: 4 additions & 1 deletion tests/src/providers/grass/testqgsgrassprovider.cpp
Expand Up @@ -220,7 +220,10 @@ void TestQgsGrassProvider::initTestCase()
#endif

QgsGrass::setMute();
QgsGrass::init();
if ( !QgsGrass::init() )
{
reportRow( "Cannot init GRASS: " + QgsGrass::initError() );
}

//create some objects that will be used in all tests...
//create a raster layer that will be used in all tests...
Expand Down

0 comments on commit 0ded855

Please sign in to comment.