Skip to content
Permalink
Browse files

[GRASS] fixed cheking region for empty options

  • Loading branch information
blazek committed Aug 31, 2015
1 parent 7b8d3e7 commit 2e000abdac70cf24dc9a6f1e97565c24b28754cc
Showing with 67 additions and 39 deletions.
  1. +61 −39 src/plugins/grass/qgsgrassmoduleoptions.cpp
  2. +6 −0 src/plugins/grass/qgsgrassmoduleoptions.h
@@ -683,28 +683,14 @@ QStringList QgsGrassModuleStandardOptions::checkRegion()
if ( !item )
continue;

QgsGrassObject::Type mapType = QgsGrassObject::Vector;
switch ( item->type() )
QgsDebugMsg( "currentMap = " + item->currentMap() );
// The input may be empty, it means input is not used.
if ( item->currentMap().isEmpty() )
{
case QgsGrassModuleInput::Raster :
mapType = QgsGrassObject::Raster;
break;
case QgsGrassModuleInput::Vector :
mapType = QgsGrassObject::Vector;
break;
continue;
}

QStringList mm = item->currentMap().split( "@" );
QString map = mm.at( 0 );
QString mapset = QgsGrass::getDefaultMapset();
if ( mm.size() > 1 )
mapset = mm.at( 1 );
if ( !QgsGrass::mapRegion( mapType,
QgsGrass::getDefaultGisdbase(),
QgsGrass::getDefaultLocation(), mapset, map,
&window ) )
if ( !getCurrentMapRegion( item, &window ) )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot check region of map %1" ).arg( item->currentMap() ) );
continue;
}

@@ -868,31 +854,18 @@ bool QgsGrassModuleStandardOptions::inputRegion( struct Cell_head *window, QgsCo
else
{
if ( !all && !item->useRegion() )
{
continue;
}

QgsGrassObject::Type mapType = QgsGrassObject::Vector;

switch ( item->type() )
QgsDebugMsg( "currentMap = " + item->currentMap() );
// The input may be empty, it means input is not used.
if ( item->currentMap().isEmpty() )
{
case QgsGrassModuleInput::Raster :
mapType = QgsGrassObject::Raster;
break;
case QgsGrassModuleInput::Vector :
mapType = QgsGrassObject::Vector;
break;
continue;
}

QStringList mm = item->currentMap().split( "@" );
QString map = mm.at( 0 );
QString mapset = QgsGrass::getDefaultMapset();
if ( mm.size() > 1 )
mapset = mm.at( 1 );
if ( !QgsGrass::mapRegion( mapType,
QgsGrass::getDefaultGisdbase(),
QgsGrass::getDefaultLocation(), mapset, map,
&mapWindow ) )
if ( !getCurrentMapRegion( item, &mapWindow ) )
{
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot set region of map %1" ).arg( item->currentMap() ) );
return false;
}
}
@@ -962,6 +935,55 @@ bool QgsGrassModuleStandardOptions::usesRegion()
return false;
}

bool QgsGrassModuleStandardOptions::getCurrentMapRegion( QgsGrassModuleInput* input, struct Cell_head * window )
{
if ( !input )
{
return false;
}

QgsDebugMsg( "currentMap = " + input->currentMap() );
if ( input->currentMap().isEmpty() )
{
// The input may be empty, it means input is not used.
return false;
}

QgsGrassObject::Type mapType;

switch ( input->type() )
{
case QgsGrassModuleInput::Raster :
mapType = QgsGrassObject::Raster;
break;
case QgsGrassModuleInput::Vector :
mapType = QgsGrassObject::Vector;
break;
default:
// should not happen
QgsGrass::warning( "getCurrentMapRegion mapType not supported" );
return false;
}

QStringList mm = input->currentMap().split( "@" );
QString map = mm.value( 0 );
QString mapset = QgsGrass::getDefaultMapset();
if ( mm.size() > 1 )
{
mapset = mm.value( 1 );
}
if ( !QgsGrass::mapRegion( mapType,
QgsGrass::getDefaultGisdbase(),
QgsGrass::getDefaultLocation(), mapset, map,
window ) )
{
QgsGrass::warning( tr( "Cannot get region of map %1" ).arg( input->currentMap() ) );
return false;
}
return true;
}


QgsGrassModuleStandardOptions::~QgsGrassModuleStandardOptions()
{
}
@@ -47,6 +47,7 @@ class QgsGrassModuleOptions
RegionInput = 1, // intersection of input maps extent and highest input resolution
RegionCurrent = 0 // current map canvas extent and resolution
};

//! Constructor
QgsGrassModuleOptions(
QgsGrassTools *tools, QgsGrassModule *module,
@@ -183,6 +184,11 @@ class QgsGrassModuleStandardOptions: public QWidget, public QgsGrassModuleOption
*/
QDomDocument readInterfaceDescription( const QString & xname, QStringList & errors );

/** Get region for currently selected map. It will show warning dialog if region could not be read.
* @return true if region was successfully read
*/
bool getCurrentMapRegion( QgsGrassModuleInput * param, struct Cell_head *window );

//! Name of module executable
QString mXName;

0 comments on commit 2e000ab

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