Skip to content

Commit

Permalink
[GRASS] plugin: removed add raster/vector layer actions, substituted …
Browse files Browse the repository at this point in the history
…by QGIS browser
  • Loading branch information
blazek committed May 21, 2015
1 parent 4d62566 commit 7765d8d
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 178 deletions.
2 changes: 0 additions & 2 deletions src/plugins/grass/qgsgrass_plugin.qrc
@@ -1,8 +1,6 @@
<RCC>
<qresource prefix="/images/themes/default/grass">
<file alias="grass_add_map.png">themes/default/grass_add_map.png</file>
<file alias="grass_add_raster.png">themes/default/grass_add_raster.png</file>
<file alias="grass_add_vector.png">themes/default/grass_add_vector.png</file>
<file alias="grass_add_vertex.png">themes/default/grass_add_vertex.png</file>
<file alias="grass_browser_raster_layer.png">themes/default/grass_browser_raster_layer.png</file>
<file alias="grass_browser_vector_layer.png">themes/default/grass_browser_vector_layer.png</file>
Expand Down
170 changes: 0 additions & 170 deletions src/plugins/grass/qgsgrassplugin.cpp
Expand Up @@ -77,8 +77,6 @@ QgsGrassPlugin::QgsGrassPlugin( QgisInterface * theQgisInterFace )
, mOpenMapsetAction( 0 )
, mNewMapsetAction( 0 )
, mCloseMapsetAction( 0 )
, mAddVectorAction( 0 )
, mAddRasterAction( 0 )
, mOpenToolsAction( 0 )
, mEditRegionAction( 0 )
, mEditAction( 0 )
Expand Down Expand Up @@ -162,12 +160,6 @@ void QgsGrassPlugin::initGui()
mCloseMapsetAction = new QAction( QIcon(), tr( "Close Mapset" ), this );
mCloseMapsetAction->setObjectName( "mCloseMapsetAction" );

mAddVectorAction = new QAction( QIcon(), tr( "Add GRASS Vector Layer" ), this );
mAddVectorAction->setObjectName( "mAddVectorAction" );
mAddVectorAction->setWhatsThis( tr( "Adds a GRASS vector layer to the map canvas" ) );
mAddRasterAction = new QAction( QIcon(), tr( "Add GRASS raster layer" ), this );
mAddRasterAction->setObjectName( "mAddRasterAction" );
mAddRasterAction->setWhatsThis( tr( "Adds a GRASS raster layer to the map canvas" ) );
mOpenToolsAction = new QAction( QIcon(), tr( "Open GRASS Tools" ), this );
mOpenToolsAction->setObjectName( "mOpenToolsAction" );
mOpenToolsAction->setWhatsThis( tr( "Open GRASS tools" ) );
Expand All @@ -187,8 +179,6 @@ void QgsGrassPlugin::initGui()
mNewVectorAction->setObjectName( "mNewVectorAction" );

// Connect the action
connect( mAddVectorAction, SIGNAL( triggered() ), this, SLOT( addVector() ) );
connect( mAddRasterAction, SIGNAL( triggered() ), this, SLOT( addRaster() ) );
connect( mOpenToolsAction, SIGNAL( triggered() ), this, SLOT( openTools() ) );
connect( mEditAction, SIGNAL( triggered() ), this, SLOT( edit() ) );
connect( mNewVectorAction, SIGNAL( triggered() ), this, SLOT( newVector() ) );
Expand All @@ -202,8 +192,6 @@ void QgsGrassPlugin::initGui()
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mOpenMapsetAction );
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mNewMapsetAction );
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mCloseMapsetAction );
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mAddVectorAction );
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mAddRasterAction );
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mNewVectorAction );
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mEditAction );
qGisInterface->addPluginToMenu( tr( "&GRASS" ), mOpenToolsAction );
Expand All @@ -219,8 +207,6 @@ void QgsGrassPlugin::initGui()
mToolBarPointer->addAction( mNewMapsetAction );
mToolBarPointer->addAction( mCloseMapsetAction );
mToolBarPointer->addSeparator();
mToolBarPointer->addAction( mAddVectorAction );
mToolBarPointer->addAction( mAddRasterAction );
mToolBarPointer->addAction( mNewVectorAction );
mToolBarPointer->addAction( mEditAction );
mToolBarPointer->addAction( mOpenToolsAction );
Expand Down Expand Up @@ -312,156 +298,6 @@ void QgsGrassPlugin::saveMapset()
QgsGrass::getDefaultMapset() );
}

// Slot called when the "Add GRASS vector layer" menu item is triggered
void QgsGrassPlugin::addVector()
{
// QgsDebugMsg("entered.");
QString uri;

QgsGrassSelect *sel = new QgsGrassSelect( qGisInterface->mainWindow(), QgsGrassSelect::VECTOR );
if ( sel->exec() )
{
uri = sel->gisdbase + "/" + sel->location + "/" + sel->mapset + "/" + sel->map + "/" + sel->layer;
}
// QgsDebugMsg(QString("plugin URI: %1").arg(uri));
if ( uri.length() == 0 )
{
// QgsDebugMsg("Nothing was selected");
return;
}
else
{
// QgsDebugMsg("Add new vector layer");

// create vector name: vector layer
QString name = sel->map;

QString field;
QString type;

if ( !sel->layer.startsWith( "topo_" ) )
{
QRegExp rx( "(\\d+)_(.+)" );
if ( rx.indexIn( sel->layer ) != -1 )
{
field = rx.cap( 1 );
type = rx.cap( 2 );
}
}

// Set location
QgsGrass::setLocation( sel->gisdbase, sel->location );

/* Open vector */
try
{
//Vect_set_open_level( 2 );
struct Map_info map;
int level = Vect_open_old_head( &map, sel->map.toUtf8().data(),
sel->mapset.toUtf8().data() );

if ( level == 1 )
{
QgsDebugMsg( "Cannot open vector on level 2" );
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open vector %1 in mapset %2 on level 2 (topology not available, try to rebuild topology using v.build module)." ).arg( sel->map ).arg( sel->mapset ) );
Vect_close( &map );
return;
}
else if ( level < 1 )
{
QgsDebugMsg( "Cannot open vector" );
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open vector %1 in mapset %2" ).arg( sel->map ).arg( sel->mapset ) );
return;
}

if ( level >= 2 )
{
if ( !sel->layer.startsWith( "topo_" ) )
{
// Count layers
int cnt = 0;
int ncidx = Vect_cidx_get_num_fields( &map );

for ( int i = 0; i < ncidx; i++ )
{
int field = Vect_cidx_get_field_number( &map, i );

if ( Vect_cidx_get_type_count( &map, field, GV_POINT | GV_LINE | GV_AREA ) > 0 ||
( field > 1 && Vect_cidx_get_type_count( &map, field, GV_BOUNDARY ) ) )
{
cnt++;
}
}

if ( cnt > 1 )
{
name.append( " " + field );

// No need to ad type, the type is obvious from the legend
}
}
else
{
name.append( " " + sel->layer );
}
}

Vect_close( &map );
}
catch ( QgsGrass::Exception &e )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( e.what() ) );
}

qGisInterface->addVectorLayer( uri, name, "grass" );
}
}

// Slot called when the "Add GRASS raster layer" menu item is triggered
void QgsGrassPlugin::addRaster()
{
// QgsDebugMsg("entered.");
QString uri;

QgsGrassSelect *sel = new QgsGrassSelect( qGisInterface->mainWindow(), QgsGrassSelect::RASTER );
if ( sel->exec() )
{
QString element;
if ( sel->selectedType == QgsGrassSelect::RASTER )
{
element = "cellhd";
}
else // GROUP
{
element = "group";
}

uri = sel->gisdbase + "/" + sel->location + "/" + sel->mapset + "/" + element + "/" + sel->map;
}

// QgsDebugMsg(QString("plugin URI: %1").arg(uri));

if ( uri.length() == 0 )
{
// QgsDebugMsg("Nothing was selected");
return;
}
else
{

// QgsDebugMsg("Add new raster layer");

// create raster name
int pos = uri.lastIndexOf( '/' );
pos = uri.lastIndexOf( '/', pos - 1 );
QString name = uri.right( uri.length() - pos - 1 );
name.replace( '/', ' ' );

//qGisInterface->addRasterLayer( uri, sel->map );
qGisInterface->addRasterLayer( uri, sel->map, "grassraster" );
}
}

// Open tools
void QgsGrassPlugin::openTools()
{
Expand Down Expand Up @@ -859,8 +695,6 @@ void QgsGrassPlugin::unload()
qGisInterface->removePluginMenu( tr( "&GRASS" ), mOpenMapsetAction );
qGisInterface->removePluginMenu( tr( "&GRASS" ), mNewMapsetAction );
qGisInterface->removePluginMenu( tr( "&GRASS" ), mCloseMapsetAction );
qGisInterface->removePluginMenu( tr( "&GRASS" ), mAddVectorAction );
qGisInterface->removePluginMenu( tr( "&GRASS" ), mAddRasterAction );
qGisInterface->removePluginMenu( tr( "&GRASS" ), mOpenToolsAction );
qGisInterface->removePluginMenu( tr( "&GRASS" ), mRegionAction );
qGisInterface->removePluginMenu( tr( "&GRASS" ), mEditRegionAction );
Expand All @@ -870,8 +704,6 @@ void QgsGrassPlugin::unload()
delete mOpenMapsetAction;
delete mNewMapsetAction;
delete mCloseMapsetAction;
delete mAddVectorAction;
delete mAddRasterAction;
delete mOpenToolsAction;
delete mRegionAction;
delete mEditRegionAction;
Expand Down Expand Up @@ -904,8 +736,6 @@ void QgsGrassPlugin::setCurrentTheme( QString theThemeName )
mNewMapsetAction->setIcon( getThemeIcon( "grass_new_mapset.png" ) );
mCloseMapsetAction->setIcon( getThemeIcon( "grass_close_mapset.png" ) );

mAddVectorAction->setIcon( getThemeIcon( "grass_add_vector.png" ) );
mAddRasterAction->setIcon( getThemeIcon( "grass_add_raster.png" ) );
mOpenToolsAction->setIcon( getThemeIcon( "grass_tools.png" ) );

mRegionAction->setIcon( getThemeIcon( "grass_region.png" ) );
Expand Down
6 changes: 0 additions & 6 deletions src/plugins/grass/qgsgrassplugin.h
Expand Up @@ -85,10 +85,6 @@ class QgsGrassPlugin : public QObject, public QgisPlugin
public slots:
//! init the gui
virtual void initGui() override;
//! Show the dialog box for new vector
void addVector();
//! Show the dialog box for new raster
void addRaster();
//! Start vector editing
void edit();
//! unload the plugin
Expand Down Expand Up @@ -164,8 +160,6 @@ class QgsGrassPlugin : public QObject, public QgisPlugin
QAction *mOpenMapsetAction;
QAction *mNewMapsetAction;
QAction *mCloseMapsetAction;
QAction *mAddVectorAction;
QAction *mAddRasterAction;
QAction *mOpenToolsAction;
QAction *mEditRegionAction;
QAction *mEditAction;
Expand Down
Binary file removed src/plugins/grass/themes/default/grass_add_raster.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 7765d8d

Please sign in to comment.