Skip to content

Commit 2e000ab

Browse files
committedAug 31, 2015
[GRASS] fixed cheking region for empty options
1 parent 7b8d3e7 commit 2e000ab

File tree

2 files changed

+67
-39
lines changed

2 files changed

+67
-39
lines changed
 

‎src/plugins/grass/qgsgrassmoduleoptions.cpp

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -683,28 +683,14 @@ QStringList QgsGrassModuleStandardOptions::checkRegion()
683683
if ( !item )
684684
continue;
685685

686-
QgsGrassObject::Type mapType = QgsGrassObject::Vector;
687-
switch ( item->type() )
686+
QgsDebugMsg( "currentMap = " + item->currentMap() );
687+
// The input may be empty, it means input is not used.
688+
if ( item->currentMap().isEmpty() )
688689
{
689-
case QgsGrassModuleInput::Raster :
690-
mapType = QgsGrassObject::Raster;
691-
break;
692-
case QgsGrassModuleInput::Vector :
693-
mapType = QgsGrassObject::Vector;
694-
break;
690+
continue;
695691
}
696-
697-
QStringList mm = item->currentMap().split( "@" );
698-
QString map = mm.at( 0 );
699-
QString mapset = QgsGrass::getDefaultMapset();
700-
if ( mm.size() > 1 )
701-
mapset = mm.at( 1 );
702-
if ( !QgsGrass::mapRegion( mapType,
703-
QgsGrass::getDefaultGisdbase(),
704-
QgsGrass::getDefaultLocation(), mapset, map,
705-
&window ) )
692+
if ( !getCurrentMapRegion( item, &window ) )
706693
{
707-
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot check region of map %1" ).arg( item->currentMap() ) );
708694
continue;
709695
}
710696

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

873-
QgsGrassObject::Type mapType = QgsGrassObject::Vector;
874-
875-
switch ( item->type() )
861+
QgsDebugMsg( "currentMap = " + item->currentMap() );
862+
// The input may be empty, it means input is not used.
863+
if ( item->currentMap().isEmpty() )
876864
{
877-
case QgsGrassModuleInput::Raster :
878-
mapType = QgsGrassObject::Raster;
879-
break;
880-
case QgsGrassModuleInput::Vector :
881-
mapType = QgsGrassObject::Vector;
882-
break;
865+
continue;
883866
}
884-
885-
QStringList mm = item->currentMap().split( "@" );
886-
QString map = mm.at( 0 );
887-
QString mapset = QgsGrass::getDefaultMapset();
888-
if ( mm.size() > 1 )
889-
mapset = mm.at( 1 );
890-
if ( !QgsGrass::mapRegion( mapType,
891-
QgsGrass::getDefaultGisdbase(),
892-
QgsGrass::getDefaultLocation(), mapset, map,
893-
&mapWindow ) )
867+
if ( !getCurrentMapRegion( item, &mapWindow ) )
894868
{
895-
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot set region of map %1" ).arg( item->currentMap() ) );
896869
return false;
897870
}
898871
}
@@ -962,6 +935,55 @@ bool QgsGrassModuleStandardOptions::usesRegion()
962935
return false;
963936
}
964937

938+
bool QgsGrassModuleStandardOptions::getCurrentMapRegion( QgsGrassModuleInput* input, struct Cell_head * window )
939+
{
940+
if ( !input )
941+
{
942+
return false;
943+
}
944+
945+
QgsDebugMsg( "currentMap = " + input->currentMap() );
946+
if ( input->currentMap().isEmpty() )
947+
{
948+
// The input may be empty, it means input is not used.
949+
return false;
950+
}
951+
952+
QgsGrassObject::Type mapType;
953+
954+
switch ( input->type() )
955+
{
956+
case QgsGrassModuleInput::Raster :
957+
mapType = QgsGrassObject::Raster;
958+
break;
959+
case QgsGrassModuleInput::Vector :
960+
mapType = QgsGrassObject::Vector;
961+
break;
962+
default:
963+
// should not happen
964+
QgsGrass::warning( "getCurrentMapRegion mapType not supported" );
965+
return false;
966+
}
967+
968+
QStringList mm = input->currentMap().split( "@" );
969+
QString map = mm.value( 0 );
970+
QString mapset = QgsGrass::getDefaultMapset();
971+
if ( mm.size() > 1 )
972+
{
973+
mapset = mm.value( 1 );
974+
}
975+
if ( !QgsGrass::mapRegion( mapType,
976+
QgsGrass::getDefaultGisdbase(),
977+
QgsGrass::getDefaultLocation(), mapset, map,
978+
window ) )
979+
{
980+
QgsGrass::warning( tr( "Cannot get region of map %1" ).arg( input->currentMap() ) );
981+
return false;
982+
}
983+
return true;
984+
}
985+
986+
965987
QgsGrassModuleStandardOptions::~QgsGrassModuleStandardOptions()
966988
{
967989
}

‎src/plugins/grass/qgsgrassmoduleoptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class QgsGrassModuleOptions
4747
RegionInput = 1, // intersection of input maps extent and highest input resolution
4848
RegionCurrent = 0 // current map canvas extent and resolution
4949
};
50+
5051
//! Constructor
5152
QgsGrassModuleOptions(
5253
QgsGrassTools *tools, QgsGrassModule *module,
@@ -183,6 +184,11 @@ class QgsGrassModuleStandardOptions: public QWidget, public QgsGrassModuleOption
183184
*/
184185
QDomDocument readInterfaceDescription( const QString & xname, QStringList & errors );
185186

187+
/** Get region for currently selected map. It will show warning dialog if region could not be read.
188+
* @return true if region was successfully read
189+
*/
190+
bool getCurrentMapRegion( QgsGrassModuleInput * param, struct Cell_head *window );
191+
186192
//! Name of module executable
187193
QString mXName;
188194

0 commit comments

Comments
 (0)
Please sign in to comment.