Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[GRASS] close mapset button in dock widget
  • Loading branch information
blazek committed Aug 20, 2015
1 parent 71bd8b4 commit acbf283
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 27 deletions.
30 changes: 7 additions & 23 deletions src/plugins/grass/qgsgrassplugin.cpp
Expand Up @@ -90,8 +90,10 @@ QgsGrassPlugin::~QgsGrassPlugin()
//if ( mTools )
// mTools->closeTools();
if ( mEdit )
{
mEdit->closeEdit();
QString err = QgsGrass::closeMapset();
}
QgsGrass::instance()->closeMapsetWarn();
}

/* Following functions return name, description, version, and type for the plugin */
Expand Down Expand Up @@ -179,7 +181,7 @@ void QgsGrassPlugin::initGui()
connect( mRegionAction, SIGNAL( toggled( bool ) ), this, SLOT( switchRegion( bool ) ) );
connect( mOpenMapsetAction, SIGNAL( triggered() ), this, SLOT( openMapset() ) );
connect( mNewMapsetAction, SIGNAL( triggered() ), this, SLOT( newMapset() ) );
connect( mCloseMapsetAction, SIGNAL( triggered() ), this, SLOT( closeMapset() ) );
connect( mCloseMapsetAction, SIGNAL( triggered() ), QgsGrass::instance(), SLOT( closeMapsetWarn() ) );

// Add actions to a GRASS plugin menu
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mOpenMapsetAction );
Expand Down Expand Up @@ -527,19 +529,6 @@ void QgsGrassPlugin::openMapset()
}
}

void QgsGrassPlugin::closeMapset()
{
// QgsDebugMsg("entered.");

QString err = QgsGrass::closeMapset();

if ( !err.isNull() )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot close mapset. %1" ).arg( err ) );
return;
}
}

void QgsGrassPlugin::newMapset()
{
if ( !QgsGrassNewMapset::isRunning() )
Expand Down Expand Up @@ -585,14 +574,9 @@ void QgsGrassPlugin::projectRead()
return;
}

QString err = QgsGrass::closeMapset();
if ( !err.isNull() )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot close current mapset. %1" ).arg( err ) );
return;
}
QgsGrass::instance()->closeMapsetWarn();

err = QgsGrass::openMapset( gisdbase, location, mapset );
QString err = QgsGrass::openMapset( gisdbase, location, mapset );

if ( !err.isNull() )
{
Expand All @@ -610,7 +594,7 @@ void QgsGrassPlugin::newProject()
void QgsGrassPlugin::unload()
{
// Close mapset
QString err = QgsGrass::closeMapset();
QgsGrass::instance()->closeMapsetWarn();

// remove the GUI
qGisInterface->removePluginMenu( tr( "&GRASS" ), mOpenMapsetAction );
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/grass/qgsgrassplugin.h
Expand Up @@ -99,8 +99,6 @@ class QgsGrassPlugin : public QObject, public QgisPlugin
void newMapset();
//! Open existing mapset
void openMapset();
//! Close mapset
void closeMapset();
//! Current mapset changed (opened/closed)
void mapsetChanged();
//! Create new vector
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/grass/qgsgrasstools.cpp
Expand Up @@ -149,8 +149,12 @@ QgsGrassTools::QgsGrassTools( QgisInterface *iface, QWidget * parent, const char
, mModelProxy( 0 )
{
Q_UNUSED( name );
setupUi( this );
QgsDebugMsg( "QgsGrassTools()" );
setupUi( this );
QPushButton * closeMapsetButton = new QPushButton( QgsApplication::getThemeIcon( "mActionFileExit.png" ), tr( "Close mapset" ), this );
mTabWidget->setCornerWidget( closeMapsetButton );
connect( closeMapsetButton, SIGNAL( clicked() ), QgsGrass::instance(), SLOT( closeMapsetWarn() ) );

qRegisterMetaType<QgsDetailedItemData>();

setWindowTitle( tr( "GRASS Tools" ) );
Expand Down
1 change: 1 addition & 0 deletions src/plugins/grass/qgsgrasstools.h
Expand Up @@ -95,6 +95,7 @@ class QgsGrassTools: public QDockWidget, private Ui::QgsGrassToolsBase
void on_mDebugButton_clicked();
void on_mCloseDebugButton_clicked();
void on_mViewModeButton_clicked();

signals:
void regionChanged();

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/grass/qgsgrasstoolsbase.ui
Expand Up @@ -32,7 +32,7 @@
</property>
<widget class="QWidget" name="mModulesTreeTab">
<attribute name="title">
<string>Modules Tree</string>
<string>Modules</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
Expand Down
14 changes: 14 additions & 0 deletions src/providers/grass/qgsgrass.cpp
Expand Up @@ -922,6 +922,20 @@ QString QgsGrass::closeMapset()
return QString::null;
}

bool QgsGrass::closeMapsetWarn()
{
QgsDebugMsg( "entered" );

QString err = QgsGrass::closeMapset();

if ( !err.isNull() )
{
warning( tr( "Cannot close mapset. %1" ).arg( err ) );
return false;
}
return true;
}

void QgsGrass::saveMapset()
{
QgsDebugMsg( "entered." );
Expand Down
5 changes: 5 additions & 0 deletions src/providers/grass/qgsgrass.h
Expand Up @@ -217,6 +217,7 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
/** \brief Close mapset if it was opened from QGIS.
* Delete GISRC, lock and temporary directory.
* Emits signal mapsetChanged().
* \param showError show error dialog on error
* \return Empty string or error message
*/
static QString closeMapset();
Expand Down Expand Up @@ -503,6 +504,10 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
// Sleep miliseconds (for debugging)
static void sleep( int ms );

public slots:
/** Close mapset and show warning if closing failed */
bool closeMapsetWarn();

signals:
/** Signal emitted after mapset was opened */
void mapsetChanged();
Expand Down

0 comments on commit acbf283

Please sign in to comment.