@@ -683,28 +683,14 @@ QStringList QgsGrassModuleStandardOptions::checkRegion()
683
683
if ( !item )
684
684
continue ;
685
685
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 () )
688
689
{
689
- case QgsGrassModuleInput::Raster :
690
- mapType = QgsGrassObject::Raster;
691
- break ;
692
- case QgsGrassModuleInput::Vector :
693
- mapType = QgsGrassObject::Vector;
694
- break ;
690
+ continue ;
695
691
}
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 ) )
706
693
{
707
- QMessageBox::warning ( 0 , tr ( " Warning" ), tr ( " Cannot check region of map %1" ).arg ( item->currentMap () ) );
708
694
continue ;
709
695
}
710
696
@@ -868,31 +854,18 @@ bool QgsGrassModuleStandardOptions::inputRegion( struct Cell_head *window, QgsCo
868
854
else
869
855
{
870
856
if ( !all && !item->useRegion () )
857
+ {
871
858
continue ;
859
+ }
872
860
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 () )
876
864
{
877
- case QgsGrassModuleInput::Raster :
878
- mapType = QgsGrassObject::Raster;
879
- break ;
880
- case QgsGrassModuleInput::Vector :
881
- mapType = QgsGrassObject::Vector;
882
- break ;
865
+ continue ;
883
866
}
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 ) )
894
868
{
895
- QMessageBox::warning ( 0 , tr ( " Warning" ), tr ( " Cannot set region of map %1" ).arg ( item->currentMap () ) );
896
869
return false ;
897
870
}
898
871
}
@@ -962,6 +935,55 @@ bool QgsGrassModuleStandardOptions::usesRegion()
962
935
return false ;
963
936
}
964
937
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
+
965
987
QgsGrassModuleStandardOptions::~QgsGrassModuleStandardOptions ()
966
988
{
967
989
}
0 commit comments