Skip to content

Commit

Permalink
[GRASS] fixed cheking region for empty options
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Aug 31, 2015
1 parent 7b8d3e7 commit 2e000ab
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 39 deletions.
100 changes: 61 additions & 39 deletions src/plugins/grass/qgsgrassmoduleoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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()
{
}
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/grass/qgsgrassmoduleoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 2e000ab

Please sign in to comment.