Skip to content
Permalink
Browse files

[GRASS] add/remove mapset to/from search path browser actions

  • Loading branch information
blazek committed Dec 15, 2015
1 parent 5c55183 commit e94b2155df695f85fb9efc9025af965f067823e6
@@ -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" );
@@ -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
{
@@ -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 )
{
@@ -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" );
@@ -41,6 +41,8 @@ class QgsGrassItemActions : public QObject
public slots:
void newMapset();
void openMapset();
void addMapsetToSearchPath();
void removeMapsetFromSearchPath();
void renameGrassObject();
void deleteGrassObject();
void newPointLayer();

0 comments on commit e94b215

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