62
62
// Added by qt3to4:
63
63
#include < QVBoxLayout>
64
64
#include < QGridLayout>
65
+ #include < QIntValidator>
66
+ #include < QDoubleValidator>
65
67
66
68
#include " qgis.h"
67
69
#include " qgsapplication.h"
@@ -789,7 +791,7 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
789
791
QWidget * parent)
790
792
: Q3GroupBox ( 1 , Qt::Vertical, parent ),
791
793
QgsGrassModuleItem ( module , key, qdesc, gdesc, gnode ),
792
- mIsOutput(false )
794
+ mIsOutput(false ), mValueType(String)
793
795
{
794
796
#ifdef QGISDEBUG
795
797
std::cerr << " QgsGrassModuleOption::QgsGrassModuleOption" << std::endl;
@@ -823,14 +825,17 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
823
825
// String without options
824
826
if ( !mHidden )
825
827
{
826
-
828
+ QDomElement gelem = gnode.toElement ();
829
+
827
830
// Predefined values ?
828
831
QDomNode valuesNode = gnode.namedItem ( " values" );
832
+ QDomElement valuesElem = valuesNode.toElement (); // null if valuesNode is null
829
833
830
- if ( !valuesNode.isNull () ) // predefined values -> ComboBox or CheckBox
834
+ if ( !valuesNode.isNull () && valuesNode. childNodes (). count () > 1 )
831
835
{
836
+ // predefined values -> ComboBox or CheckBox
837
+
832
838
// one or many?
833
- QDomElement gelem = gnode.toElement ();
834
839
if ( gelem.attribute (" multiple" ) == " yes" ) {
835
840
mControlType = CheckBoxes;
836
841
} else {
@@ -841,7 +846,6 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
841
846
// List of values to be excluded
842
847
QStringList exclude = QStringList::split ( ' ,' , qdesc.attribute (" exclude" ) );
843
848
844
- QDomElement valuesElem = valuesNode.toElement ();
845
849
QDomNode valueNode = valuesElem.firstChild ();
846
850
847
851
while ( !valueNode.isNull () ) {
@@ -893,6 +897,39 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
893
897
QString def = e.text ().stripWhiteSpace ();
894
898
mLineEdit ->setText ( def );
895
899
}
900
+
901
+ QStringList minMax;
902
+ if ( valuesNode.childNodes ().count () == 1 )
903
+ {
904
+ QDomNode valueNode = valuesElem.firstChild ();
905
+
906
+ QDomNode n = valueNode.namedItem ( " name" );
907
+ if ( !n.isNull () ) {
908
+ QDomElement e = n.toElement ();
909
+ QString val = e.text ().stripWhiteSpace ();
910
+ minMax = val.split (" -" );
911
+ }
912
+ }
913
+ if ( gelem.attribute (" type" ) == " integer" )
914
+ {
915
+ mValueType = Integer;
916
+ if ( minMax.size () == 2 ) {
917
+ mValidator = new QIntValidator ( minMax.at (0 ).toInt (),
918
+ minMax.at (1 ).toInt (), this );
919
+ } else {
920
+ mValidator = new QIntValidator ( this );
921
+ }
922
+ mLineEdit ->setValidator ( mValidator );
923
+ } else if ( gelem.attribute (" type" ) == " float" ) {
924
+ mValueType = Double;
925
+ if ( minMax.size () == 2 ) {
926
+ mValidator = new QDoubleValidator ( minMax.at (0 ).toDouble (),
927
+ minMax.at (1 ).toDouble (), 10 , this );
928
+ } else {
929
+ mValidator = new QDoubleValidator ( this );
930
+ }
931
+ mLineEdit ->setValidator ( mValidator );
932
+ }
896
933
}
897
934
}
898
935
}
0 commit comments