Skip to content
Permalink
Browse files

[GRASS] close mapset button in dock widget

  • Loading branch information
blazek committed Aug 20, 2015
1 parent 71bd8b4 commit acbf2834f93b57481728b75a9d2e1de61bc6dd5c
@@ -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 */
@@ -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 );
@@ -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() )
@@ -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() )
{
@@ -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 );
@@ -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
@@ -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" ) );
@@ -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();

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

0 comments on commit acbf283

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