diff --git a/src/plugins/grass/qgsgrassplugin.cpp b/src/plugins/grass/qgsgrassplugin.cpp
index ccc32d95d8b..1de1cd5084c 100644
--- a/src/plugins/grass/qgsgrassplugin.cpp
+++ b/src/plugins/grass/qgsgrassplugin.cpp
@@ -225,6 +225,8 @@ void QgsGrassPlugin::initGui()
connect( qGisInterface, SIGNAL( currentLayerChanged( QgsMapLayer * ) ),
this, SLOT( setEditAction() ) );
+ connect( QgsGrass::instance(), SIGNAL( mapsetChanged() ), SLOT( mapsetChanged() ) );
+
// Init Region symbology
mRegionPen.setColor( QColor( settings.value( "/GRASS/region/color", "#ff0000" ).toString() ) );
mRegionPen.setWidth( settings.value( "/GRASS/region/width", 0 ).toInt() );
@@ -240,6 +242,7 @@ void QgsGrassPlugin::initGui()
void QgsGrassPlugin::mapsetChanged()
{
+ QgsDebugMsg( "entered" );
if ( !QgsGrass::activeMode() )
{
mRegionAction->setEnabled( false );
@@ -260,11 +263,6 @@ void QgsGrassPlugin::mapsetChanged()
mRegionAction->setChecked( on );
switchRegion( on );
- if ( mTools )
- {
- mTools->mapsetChanged();
- }
-
QString gisdbase = QgsGrass::getDefaultGisdbase();
QString location = QgsGrass::getDefaultLocation();
try
@@ -281,21 +279,11 @@ void QgsGrassPlugin::mapsetChanged()
setTransform();
redrawRegion();
}
-}
-void QgsGrassPlugin::saveMapset()
-{
-// QgsDebugMsg("entered.");
-
- // Save working mapset in project file
- QgsProject::instance()->writeEntry( "GRASS", "/WorkingGisdbase",
- QgsProject::instance()->writePath( QgsGrass::getDefaultGisdbase() ) );
-
- QgsProject::instance()->writeEntry( "GRASS", "/WorkingLocation",
- QgsGrass::getDefaultLocation() );
-
- QgsProject::instance()->writeEntry( "GRASS", "/WorkingMapset",
- QgsGrass::getDefaultMapset() );
+ if ( mTools )
+ {
+ mTools->mapsetChanged();
+ }
}
// Open tools
@@ -584,9 +572,6 @@ void QgsGrassPlugin::openMapset()
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open the mapset. %1" ).arg( err ) );
return;
}
-
- saveMapset();
- mapsetChanged();
}
void QgsGrassPlugin::closeMapset()
@@ -600,9 +585,6 @@ void QgsGrassPlugin::closeMapset()
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot close mapset. %1" ).arg( err ) );
return;
}
-
- saveMapset();
- mapsetChanged();
}
void QgsGrassPlugin::newMapset()
@@ -656,7 +638,6 @@ void QgsGrassPlugin::projectRead()
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot close current mapset. %1" ).arg( err ) );
return;
}
- mapsetChanged();
err = QgsGrass::openMapset( gisdbase, location, mapset );
@@ -665,8 +646,6 @@ void QgsGrassPlugin::projectRead()
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS mapset. %1" ).arg( err ) );
return;
}
-
- mapsetChanged();
}
void QgsGrassPlugin::newProject()
diff --git a/src/plugins/grass/qgsgrassplugin.h b/src/plugins/grass/qgsgrassplugin.h
index 1180479f1f9..25764a59dc0 100644
--- a/src/plugins/grass/qgsgrassplugin.h
+++ b/src/plugins/grass/qgsgrassplugin.h
@@ -119,8 +119,6 @@ class QgsGrassPlugin : public QObject, public QgisPlugin
void projectRead();
//! New project
void newProject();
- //! Save mapset to project
- void saveMapset();
//! Set edit action
void setEditAction();
//! Close the edit if layer is removed
diff --git a/src/plugins/grass/qgsgrasstools.cpp b/src/plugins/grass/qgsgrasstools.cpp
index 028dd0f2c38..3696282e30f 100644
--- a/src/plugins/grass/qgsgrasstools.cpp
+++ b/src/plugins/grass/qgsgrasstools.cpp
@@ -137,18 +137,21 @@ void QgsGrassTools::showTabs()
repaint();
#endif
- QString conf = QgsApplication::pkgDataPath() + "/grass/config/default.qgc";
+ // Build modules tree if empty
+ QgsDebugMsg( QString( "topLevelItemCount = %1" ).arg( mModulesTree->topLevelItemCount() ) );
+ if ( mModulesTree->topLevelItemCount() == 0 )
+ {
+ // Load the modules lists
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+ QString conf = QgsApplication::pkgDataPath() + "/grass/config/default.qgc";
+ loadConfig( conf, mModulesTree, mModulesListModel, false );
+ QApplication::restoreOverrideCursor();
+ QgsDebugMsg( QString( "topLevelItemCount = %1" ).arg( mModulesTree->topLevelItemCount() ) );
+ }
+
if ( QgsGrass::activeMode() )
{
- QgsDebugMsg( QString( "topLevelItemCount = %1" ).arg( mModulesTree->topLevelItemCount() ) );
- if ( mModulesTree->topLevelItemCount() == 0 )
- {
- // Load the modules lists
- QApplication::setOverrideCursor( Qt::WaitCursor );
- loadConfig( conf, mModulesTree, mModulesListModel, false );
- QApplication::restoreOverrideCursor();
- }
- QgsDebugMsg( QString( "topLevelItemCount = %1" ).arg( mModulesTree->topLevelItemCount() ) );
+ mMessageLabel->hide();
mTabWidget->setEnabled( true );
}
else
@@ -175,6 +178,7 @@ void QgsGrassTools::showTabs()
QApplication::restoreOverrideCursor();
}
#else
+ mMessageLabel->show();
mTabWidget->setEnabled( false );
#endif
}
diff --git a/src/plugins/grass/qgsgrasstoolsbase.ui b/src/plugins/grass/qgsgrasstoolsbase.ui
index 87fc0d28507..4b246d196bc 100644
--- a/src/plugins/grass/qgsgrasstoolsbase.ui
+++ b/src/plugins/grass/qgsgrasstoolsbase.ui
@@ -15,9 +15,16 @@
-
- 0
-
+ -
+
+
+ <html><head/><body><p>No mapset is open. You can open a GRASS mapset from the browser using the mapset item's context menu action <span style=" font-style:italic;">Open mapset</span>.</p></body></html>
+
+
+ true
+
+
+
-
@@ -154,6 +161,8 @@
+ mTabWidget
+ mMessageLabel
diff --git a/src/providers/grass/CMakeLists.txt b/src/providers/grass/CMakeLists.txt
index a179eaaa413..38f1261684d 100644
--- a/src/providers/grass/CMakeLists.txt
+++ b/src/providers/grass/CMakeLists.txt
@@ -23,6 +23,7 @@ MACRO(ADD_GRASSLIB GRASS_BUILD_VERSION)
SET(GRASS_MINOR_VERSION ${GRASS_MINOR_VERSION${GRASS_BUILD_VERSION}})
QT4_WRAP_CPP(GRASS_LIBRARY_MOC_SRCS
+ ../qgsgrass.h
../qgsgrassprovider.h
../qgsgrassimport.h
../qgsgrassoptions.h
diff --git a/src/providers/grass/qgsgrass.cpp b/src/providers/grass/qgsgrass.cpp
index eb775d5f0c6..278ca315fa7 100644
--- a/src/providers/grass/qgsgrass.cpp
+++ b/src/providers/grass/qgsgrass.cpp
@@ -30,13 +30,14 @@
#include "qgsgrass.h"
-#include "qgslogger.h"
#include "qgsapplication.h"
+#include "qgsconfig.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsfield.h"
-#include "qgsrectangle.h"
-#include "qgsconfig.h"
#include "qgslocalec.h"
+#include "qgslogger.h"
+#include "qgsproject.h"
+#include "qgsrectangle.h"
#include
#include
@@ -518,6 +519,12 @@ bool QgsGrass::isValidGrassBaseDir( const QString& gisBase )
return false;
}
+QgsGrass *QgsGrass::instance()
+{
+ static QgsGrass sInstance;
+ return &sInstance;
+}
+
bool QgsGrass::activeMode()
{
init();
@@ -833,10 +840,12 @@ QString GRASS_LIB_EXPORT QgsGrass::openMapset( const QString& gisdbase,
mMapsetLock = lock;
- return NULL;
+ saveMapset();
+ emit QgsGrass::instance()->mapsetChanged();
+ return QString::null;
}
-QString QgsGrass::closeMapset()
+QString GRASS_LIB_EXPORT QgsGrass::closeMapset()
{
QgsDebugMsg( "entered." );
@@ -894,7 +903,24 @@ QString QgsGrass::closeMapset()
}
}
- return NULL;
+ saveMapset();
+ emit QgsGrass::instance()->mapsetChanged();
+ return QString::null;
+}
+
+void GRASS_LIB_EXPORT QgsGrass::saveMapset()
+{
+ QgsDebugMsg( "entered." );
+
+ // Save working mapset in project file
+ QgsProject::instance()->writeEntry( "GRASS", "/WorkingGisdbase",
+ QgsProject::instance()->writePath( getDefaultGisdbase() ) );
+
+ QgsProject::instance()->writeEntry( "GRASS", "/WorkingLocation",
+ getDefaultLocation() );
+
+ QgsProject::instance()->writeEntry( "GRASS", "/WorkingMapset",
+ getDefaultMapset() );
}
QStringList GRASS_LIB_EXPORT QgsGrass::locations( const QString& gisdbase )
@@ -2268,6 +2294,11 @@ void GRASS_LIB_EXPORT QgsGrass::putEnv( QString name, QString value )
putenv( envChar );
}
+void GRASS_LIB_EXPORT QgsGrass::warning( const QString &message )
+{
+ QMessageBox::warning( 0, QObject::tr( "Warning" ), message );
+}
+
void GRASS_LIB_EXPORT QgsGrass::warning( QgsGrass::Exception &e )
{
QMessageBox::warning( 0, QObject::tr( "Warning" ), e.what() );
diff --git a/src/providers/grass/qgsgrass.h b/src/providers/grass/qgsgrass.h
index 494fa7d9eaa..4ad5133d82d 100644
--- a/src/providers/grass/qgsgrass.h
+++ b/src/providers/grass/qgsgrass.h
@@ -128,8 +128,9 @@ class GRASS_LIB_EXPORT QgsGrassObject
/*!
Methods for C library initialization and error handling.
*/
-class QgsGrass
+class GRASS_LIB_EXPORT QgsGrass : public QObject
{
+ Q_OBJECT
public:
static GRASS_LIB_EXPORT jmp_buf jumper; // used to get back from fatal error
@@ -154,6 +155,9 @@ class QgsGrass
int red1, red2, green1, green2, blue1, blue2;
};
+ /** Get singleton instance of this class. Used as signals proxy between provider and plugin. */
+ static QgsGrass* instance();
+
//! Get info about the mode
/** QgsGrass may be running in active or passive mode.
* Active mode means that GISRC is set up and GISRC file is available,
@@ -202,18 +206,23 @@ class QgsGrass
//! Get last error message
static GRASS_LIB_EXPORT QString errorMessage( void );
- /** \brief Open existing GRASS mapset
- * \return NULL string or error message
+ /** Open existing GRASS mapset.
+ * Emits signal mapsetChanged().
+ * \return Empty string or error message
*/
static GRASS_LIB_EXPORT QString openMapset( const QString& gisdbase,
const QString& location, const QString& mapset );
/** \brief Close mapset if it was opened from QGIS.
- * Delete GISRC, lock and temporary directory
- * \return NULL string or error message
+ * Delete GISRC, lock and temporary directory.
+ * Emits signal mapsetChanged().
+ * \return Empty string or error message
*/
static GRASS_LIB_EXPORT QString closeMapset();
+ /** \brief Save current mapset to project file. */
+ static GRASS_LIB_EXPORT void saveMapset();
+
//! Check if given directory contains a GRASS installation
static GRASS_LIB_EXPORT bool isValidGrassBaseDir( const QString& gisBase );
@@ -444,6 +453,9 @@ class QgsGrass
return QgsApplication::libexecPath() + "grass/modules";
}
+ /** Show warning dialog with message */
+ static GRASS_LIB_EXPORT void warning( const QString &message );
+
/** Show warning dialog with exception message */
static GRASS_LIB_EXPORT void warning( QgsGrass::Exception &e );
@@ -455,6 +467,10 @@ class QgsGrass
// Sleep miliseconds (for debugging)
static GRASS_LIB_EXPORT void sleep( int ms );
+ signals:
+ /** Signal emited after mapset was opened */
+ void mapsetChanged();
+
private:
static int initialized; // Set to 1 after initialization
static bool active; // is active mode
diff --git a/src/providers/grass/qgsgrassprovidermodule.cpp b/src/providers/grass/qgsgrassprovidermodule.cpp
index f1c4794081b..062c5dfd71d 100644
--- a/src/providers/grass/qgsgrassprovidermodule.cpp
+++ b/src/providers/grass/qgsgrassprovidermodule.cpp
@@ -342,7 +342,12 @@ QVector QgsGrassMapsetItem::createChildren()
QList QgsGrassMapsetItem::actions()
{
- return QgsGrassItemActions::instance()->actions();
+ QList list = QgsGrassItemActions::instance()->actions();
+ // TODO: check mapset ownership
+ QAction* actionOpen = new QAction( QgsApplication::getThemeIcon( "grass_open_mapset.png" ), tr( "Open mapset" ), this );
+ connect( actionOpen, SIGNAL( triggered() ), SLOT( openMapset() ) );
+ list.append( actionOpen );
+ return list;
}
bool QgsGrassMapsetItem::handleDrop( const QMimeData * data, Qt::DropAction )
@@ -614,6 +619,16 @@ void QgsGrassMapsetItem::onImportFinished( QgsGrassImport* import )
refresh();
}
+void QgsGrassMapsetItem::openMapset()
+{
+ QgsDebugMsg( "entered" );
+ QString error = QgsGrass::openMapset( mGisdbase, mLocation, name() );
+ if ( !error.isEmpty() )
+ {
+ QgsGrass::warning( error );
+ }
+}
+
//----------------------- QgsGrassObjectItemBase ------------------------------
QgsGrassObjectItemBase::QgsGrassObjectItemBase( QgsGrassObject grassObject ) :
diff --git a/src/providers/grass/qgsgrassprovidermodule.h b/src/providers/grass/qgsgrassprovidermodule.h
index 9bc1987498d..0b36612b831 100644
--- a/src/providers/grass/qgsgrassprovidermodule.h
+++ b/src/providers/grass/qgsgrassprovidermodule.h
@@ -65,6 +65,7 @@ class QgsGrassMapsetItem : public QgsDirectoryItem
public slots:
void onImportFinished( QgsGrassImport* import );
+ void openMapset();
private:
bool objectInImports( QgsGrassObject grassObject );