Skip to content

Commit acbf283

Browse files
committedAug 20, 2015
[GRASS] close mapset button in dock widget
1 parent 71bd8b4 commit acbf283

File tree

7 files changed

+33
-27
lines changed

7 files changed

+33
-27
lines changed
 

‎src/plugins/grass/qgsgrassplugin.cpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ QgsGrassPlugin::~QgsGrassPlugin()
9090
//if ( mTools )
9191
// mTools->closeTools();
9292
if ( mEdit )
93+
{
9394
mEdit->closeEdit();
94-
QString err = QgsGrass::closeMapset();
95+
}
96+
QgsGrass::instance()->closeMapsetWarn();
9597
}
9698

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

184186
// Add actions to a GRASS plugin menu
185187
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mOpenMapsetAction );
@@ -527,19 +529,6 @@ void QgsGrassPlugin::openMapset()
527529
}
528530
}
529531

530-
void QgsGrassPlugin::closeMapset()
531-
{
532-
// QgsDebugMsg("entered.");
533-
534-
QString err = QgsGrass::closeMapset();
535-
536-
if ( !err.isNull() )
537-
{
538-
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot close mapset. %1" ).arg( err ) );
539-
return;
540-
}
541-
}
542-
543532
void QgsGrassPlugin::newMapset()
544533
{
545534
if ( !QgsGrassNewMapset::isRunning() )
@@ -585,14 +574,9 @@ void QgsGrassPlugin::projectRead()
585574
return;
586575
}
587576

588-
QString err = QgsGrass::closeMapset();
589-
if ( !err.isNull() )
590-
{
591-
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot close current mapset. %1" ).arg( err ) );
592-
return;
593-
}
577+
QgsGrass::instance()->closeMapsetWarn();
594578

595-
err = QgsGrass::openMapset( gisdbase, location, mapset );
579+
QString err = QgsGrass::openMapset( gisdbase, location, mapset );
596580

597581
if ( !err.isNull() )
598582
{
@@ -610,7 +594,7 @@ void QgsGrassPlugin::newProject()
610594
void QgsGrassPlugin::unload()
611595
{
612596
// Close mapset
613-
QString err = QgsGrass::closeMapset();
597+
QgsGrass::instance()->closeMapsetWarn();
614598

615599
// remove the GUI
616600
qGisInterface->removePluginMenu( tr( "&GRASS" ), mOpenMapsetAction );

‎src/plugins/grass/qgsgrassplugin.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ class QgsGrassPlugin : public QObject, public QgisPlugin
9999
void newMapset();
100100
//! Open existing mapset
101101
void openMapset();
102-
//! Close mapset
103-
void closeMapset();
104102
//! Current mapset changed (opened/closed)
105103
void mapsetChanged();
106104
//! Create new vector

‎src/plugins/grass/qgsgrasstools.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,12 @@ QgsGrassTools::QgsGrassTools( QgisInterface *iface, QWidget * parent, const char
149149
, mModelProxy( 0 )
150150
{
151151
Q_UNUSED( name );
152-
setupUi( this );
153152
QgsDebugMsg( "QgsGrassTools()" );
153+
setupUi( this );
154+
QPushButton * closeMapsetButton = new QPushButton( QgsApplication::getThemeIcon( "mActionFileExit.png" ), tr( "Close mapset" ), this );
155+
mTabWidget->setCornerWidget( closeMapsetButton );
156+
connect( closeMapsetButton, SIGNAL( clicked() ), QgsGrass::instance(), SLOT( closeMapsetWarn() ) );
157+
154158
qRegisterMetaType<QgsDetailedItemData>();
155159

156160
setWindowTitle( tr( "GRASS Tools" ) );

‎src/plugins/grass/qgsgrasstools.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class QgsGrassTools: public QDockWidget, private Ui::QgsGrassToolsBase
9595
void on_mDebugButton_clicked();
9696
void on_mCloseDebugButton_clicked();
9797
void on_mViewModeButton_clicked();
98+
9899
signals:
99100
void regionChanged();
100101

‎src/plugins/grass/qgsgrasstoolsbase.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</property>
3333
<widget class="QWidget" name="mModulesTreeTab">
3434
<attribute name="title">
35-
<string>Modules Tree</string>
35+
<string>Modules</string>
3636
</attribute>
3737
<layout class="QVBoxLayout" name="verticalLayout">
3838
<item>

‎src/providers/grass/qgsgrass.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,20 @@ QString QgsGrass::closeMapset()
922922
return QString::null;
923923
}
924924

925+
bool QgsGrass::closeMapsetWarn()
926+
{
927+
QgsDebugMsg( "entered" );
928+
929+
QString err = QgsGrass::closeMapset();
930+
931+
if ( !err.isNull() )
932+
{
933+
warning( tr( "Cannot close mapset. %1" ).arg( err ) );
934+
return false;
935+
}
936+
return true;
937+
}
938+
925939
void QgsGrass::saveMapset()
926940
{
927941
QgsDebugMsg( "entered." );

‎src/providers/grass/qgsgrass.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
217217
/** \brief Close mapset if it was opened from QGIS.
218218
* Delete GISRC, lock and temporary directory.
219219
* Emits signal mapsetChanged().
220+
* \param showError show error dialog on error
220221
* \return Empty string or error message
221222
*/
222223
static QString closeMapset();
@@ -503,6 +504,10 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
503504
// Sleep miliseconds (for debugging)
504505
static void sleep( int ms );
505506

507+
public slots:
508+
/** Close mapset and show warning if closing failed */
509+
bool closeMapsetWarn();
510+
506511
signals:
507512
/** Signal emitted after mapset was opened */
508513
void mapsetChanged();

0 commit comments

Comments
 (0)
Please sign in to comment.