Skip to content
Permalink
Browse files

[GRASS] show init error in tools title

  • Loading branch information
blazek committed Oct 15, 2015
1 parent c358aea commit 0ded8553bf5c71799af0ecea7f5e75e218ec6fda
@@ -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
@@ -316,6 +318,7 @@ void QgsGrassPlugin::onGisbaseChanged()
mCloseMapsetAction->setDisabled( !QgsGrass::activeMode() );

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

@@ -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() )
@@ -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() )
{
@@ -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() ) );
@@ -57,6 +57,8 @@ class QgsGrassTools: public QDockWidget, public Ui::QgsGrassToolsBase
//! Returns application directory
QString appDir();

void resetTitle();

public slots:
bool loadConfig();

@@ -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;
@@ -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" ),
@@ -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;
@@ -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();
}
@@ -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 );

@@ -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
@@ -116,7 +116,7 @@ QgsGrassProvider::QgsGrassProvider( QString uri )
mValid = false;
if ( !QgsGrass::init() )
{
appendError( QgsGrass::errorMessage() );
appendError( QgsGrass::initError() );
return;
}

@@ -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...

0 comments on commit 0ded855

Please sign in to comment.
You can’t perform that action at this time.