Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[GRASS] add/remove mapset to/from search path browser actions
  • Loading branch information
blazek committed Dec 15, 2015
1 parent 5c55183 commit e94b215
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/providers/grass/qgsgrass.cpp
Expand Up @@ -649,6 +649,52 @@ bool QgsGrass::isMapsetInSearchPath( QString mapset )
return mMapsetSearchPath.contains( mapset );
}

void QgsGrass::addMapsetToSearchPath( const QString & mapset, QString& error )
{
QgsDebugMsg( "entered" );
QString cmd = gisbase() + "/bin/g.mapsets";
QStringList arguments;

#if GRASS_VERSION_MAJOR < 7
arguments << "addmapset=" + mapset;
#else
arguments << "operation=add" << "mapset=" + mapset;
#endif

try
{
int timeout = -1; // What timeout to use? It can take long time on network or database
runModule( getDefaultGisdbase(), getDefaultLocation(), getDefaultMapset(), cmd, arguments, timeout, false );
}
catch ( QgsGrass::Exception &e )
{
error = tr( "Cannot add mapset %1 to search path:" ).arg( mapset ) + " " + e.what();
}
}

void QgsGrass::removeMapsetFromSearchPath( const QString & mapset, QString& error )
{
QgsDebugMsg( "entered" );
QString cmd = gisbase() + "/bin/g.mapsets";
QStringList arguments;

#if GRASS_VERSION_MAJOR < 7
arguments << "removemapset=" + mapset;
#else
arguments << "operation=remove" << "mapset=" + mapset;
#endif

try
{
int timeout = -1; // What timeout to use? It can take long time on network or database
runModule( getDefaultGisdbase(), getDefaultLocation(), getDefaultMapset(), cmd, arguments, timeout, false );
}
catch ( QgsGrass::Exception &e )
{
error = tr( "Cannot remove mapset %1 from search path:" ).arg( mapset ) + " " + e.what();
}
}

void QgsGrass::loadMapsetSearchPath()
{
QgsDebugMsg( "entered" );
Expand Down
6 changes: 6 additions & 0 deletions src/providers/grass/qgsgrass.h
Expand Up @@ -234,6 +234,12 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
* @return true if in search path */
bool isMapsetInSearchPath( QString mapset );

/** Add mapset to search path of currently open mapset */
void addMapsetToSearchPath( const QString & mapset, QString& error );

/** Add mapset to search path of currently open mapset */
void removeMapsetFromSearchPath( const QString & mapset, QString& error );

//! Error codes returned by error()
enum GERROR
{
Expand Down
41 changes: 41 additions & 0 deletions src/providers/grass/qgsgrassprovidermodule.cpp
Expand Up @@ -70,6 +70,23 @@ QList<QAction*> QgsGrassItemActions::actions()
list << openMapsetAction;
}

if ( mGrassObject.type() == QgsGrassObject::Mapset && mGrassObject.locationIdentical( QgsGrass::getDefaultLocationObject() )
&& mGrassObject.mapset() != QgsGrass::getDefaultMapset() )
{
if ( !QgsGrass::instance()->isMapsetInSearchPath( mGrassObject.mapset() ) )
{
QAction* openMapsetAction = new QAction( tr( "Add mapset to search path" ), this );
connect( openMapsetAction, SIGNAL( triggered() ), SLOT( addMapsetToSearchPath() ) );
list << openMapsetAction;
}
else
{
QAction* openMapsetAction = new QAction( tr( "Remove mapset from search path" ), this );
connect( openMapsetAction, SIGNAL( triggered() ), SLOT( removeMapsetFromSearchPath() ) );
list << openMapsetAction;
}
}

if (( mGrassObject.type() == QgsGrassObject::Raster || mGrassObject.type() == QgsGrassObject::Vector
|| mGrassObject.type() == QgsGrassObject::Group ) && isMapsetOwner )
{
Expand Down Expand Up @@ -138,6 +155,30 @@ void QgsGrassItemActions::openMapset()
QgsGrass::saveMapset();
}

void QgsGrassItemActions::addMapsetToSearchPath()
{
QgsDebugMsg( "entered" );
QString error;
QgsGrass::instance()->addMapsetToSearchPath( mGrassObject.mapset(), error );
if ( !error.isEmpty() )
{
QgsGrass::warning( error );
return;
}
}

void QgsGrassItemActions::removeMapsetFromSearchPath()
{
QgsDebugMsg( "entered" );
QString error;
QgsGrass::instance()->removeMapsetFromSearchPath( mGrassObject.mapset(), error );
if ( !error.isEmpty() )
{
QgsGrass::warning( error );
return;
}
}

void QgsGrassItemActions::renameGrassObject()
{
QgsDebugMsg( "Entered" );
Expand Down
2 changes: 2 additions & 0 deletions src/providers/grass/qgsgrassprovidermodule.h
Expand Up @@ -41,6 +41,8 @@ class QgsGrassItemActions : public QObject
public slots:
void newMapset();
void openMapset();
void addMapsetToSearchPath();
void removeMapsetFromSearchPath();
void renameGrassObject();
void deleteGrassObject();
void newPointLayer();
Expand Down

0 comments on commit e94b215

Please sign in to comment.