Skip to content

Commit e94b215

Browse files
committedDec 15, 2015
[GRASS] add/remove mapset to/from search path browser actions
1 parent 5c55183 commit e94b215

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed
 

‎src/providers/grass/qgsgrass.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,52 @@ bool QgsGrass::isMapsetInSearchPath( QString mapset )
649649
return mMapsetSearchPath.contains( mapset );
650650
}
651651

652+
void QgsGrass::addMapsetToSearchPath( const QString & mapset, QString& error )
653+
{
654+
QgsDebugMsg( "entered" );
655+
QString cmd = gisbase() + "/bin/g.mapsets";
656+
QStringList arguments;
657+
658+
#if GRASS_VERSION_MAJOR < 7
659+
arguments << "addmapset=" + mapset;
660+
#else
661+
arguments << "operation=add" << "mapset=" + mapset;
662+
#endif
663+
664+
try
665+
{
666+
int timeout = -1; // What timeout to use? It can take long time on network or database
667+
runModule( getDefaultGisdbase(), getDefaultLocation(), getDefaultMapset(), cmd, arguments, timeout, false );
668+
}
669+
catch ( QgsGrass::Exception &e )
670+
{
671+
error = tr( "Cannot add mapset %1 to search path:" ).arg( mapset ) + " " + e.what();
672+
}
673+
}
674+
675+
void QgsGrass::removeMapsetFromSearchPath( const QString & mapset, QString& error )
676+
{
677+
QgsDebugMsg( "entered" );
678+
QString cmd = gisbase() + "/bin/g.mapsets";
679+
QStringList arguments;
680+
681+
#if GRASS_VERSION_MAJOR < 7
682+
arguments << "removemapset=" + mapset;
683+
#else
684+
arguments << "operation=remove" << "mapset=" + mapset;
685+
#endif
686+
687+
try
688+
{
689+
int timeout = -1; // What timeout to use? It can take long time on network or database
690+
runModule( getDefaultGisdbase(), getDefaultLocation(), getDefaultMapset(), cmd, arguments, timeout, false );
691+
}
692+
catch ( QgsGrass::Exception &e )
693+
{
694+
error = tr( "Cannot remove mapset %1 from search path:" ).arg( mapset ) + " " + e.what();
695+
}
696+
}
697+
652698
void QgsGrass::loadMapsetSearchPath()
653699
{
654700
QgsDebugMsg( "entered" );

‎src/providers/grass/qgsgrass.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
234234
* @return true if in search path */
235235
bool isMapsetInSearchPath( QString mapset );
236236

237+
/** Add mapset to search path of currently open mapset */
238+
void addMapsetToSearchPath( const QString & mapset, QString& error );
239+
240+
/** Add mapset to search path of currently open mapset */
241+
void removeMapsetFromSearchPath( const QString & mapset, QString& error );
242+
237243
//! Error codes returned by error()
238244
enum GERROR
239245
{

‎src/providers/grass/qgsgrassprovidermodule.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ QList<QAction*> QgsGrassItemActions::actions()
7070
list << openMapsetAction;
7171
}
7272

73+
if ( mGrassObject.type() == QgsGrassObject::Mapset && mGrassObject.locationIdentical( QgsGrass::getDefaultLocationObject() )
74+
&& mGrassObject.mapset() != QgsGrass::getDefaultMapset() )
75+
{
76+
if ( !QgsGrass::instance()->isMapsetInSearchPath( mGrassObject.mapset() ) )
77+
{
78+
QAction* openMapsetAction = new QAction( tr( "Add mapset to search path" ), this );
79+
connect( openMapsetAction, SIGNAL( triggered() ), SLOT( addMapsetToSearchPath() ) );
80+
list << openMapsetAction;
81+
}
82+
else
83+
{
84+
QAction* openMapsetAction = new QAction( tr( "Remove mapset from search path" ), this );
85+
connect( openMapsetAction, SIGNAL( triggered() ), SLOT( removeMapsetFromSearchPath() ) );
86+
list << openMapsetAction;
87+
}
88+
}
89+
7390
if (( mGrassObject.type() == QgsGrassObject::Raster || mGrassObject.type() == QgsGrassObject::Vector
7491
|| mGrassObject.type() == QgsGrassObject::Group ) && isMapsetOwner )
7592
{
@@ -138,6 +155,30 @@ void QgsGrassItemActions::openMapset()
138155
QgsGrass::saveMapset();
139156
}
140157

158+
void QgsGrassItemActions::addMapsetToSearchPath()
159+
{
160+
QgsDebugMsg( "entered" );
161+
QString error;
162+
QgsGrass::instance()->addMapsetToSearchPath( mGrassObject.mapset(), error );
163+
if ( !error.isEmpty() )
164+
{
165+
QgsGrass::warning( error );
166+
return;
167+
}
168+
}
169+
170+
void QgsGrassItemActions::removeMapsetFromSearchPath()
171+
{
172+
QgsDebugMsg( "entered" );
173+
QString error;
174+
QgsGrass::instance()->removeMapsetFromSearchPath( mGrassObject.mapset(), error );
175+
if ( !error.isEmpty() )
176+
{
177+
QgsGrass::warning( error );
178+
return;
179+
}
180+
}
181+
141182
void QgsGrassItemActions::renameGrassObject()
142183
{
143184
QgsDebugMsg( "Entered" );

‎src/providers/grass/qgsgrassprovidermodule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class QgsGrassItemActions : public QObject
4141
public slots:
4242
void newMapset();
4343
void openMapset();
44+
void addMapsetToSearchPath();
45+
void removeMapsetFromSearchPath();
4446
void renameGrassObject();
4547
void deleteGrassObject();
4648
void newPointLayer();

0 commit comments

Comments
 (0)
Please sign in to comment.