Skip to content

Commit e7dcb81

Browse files
author
rblazek
committedMar 10, 2006
input number validators
git-svn-id: http://svn.osgeo.org/qgis/trunk@4995 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 547d624 commit e7dcb81

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed
 

‎src/plugins/grass/qgsgrassmodule.cpp

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
//Added by qt3to4:
6363
#include <QVBoxLayout>
6464
#include <QGridLayout>
65+
#include <QIntValidator>
66+
#include <QDoubleValidator>
6567

6668
#include "qgis.h"
6769
#include "qgsapplication.h"
@@ -789,7 +791,7 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
789791
QWidget * parent)
790792
: Q3GroupBox ( 1, Qt::Vertical, parent ),
791793
QgsGrassModuleItem ( module, key, qdesc, gdesc, gnode ),
792-
mIsOutput(false)
794+
mIsOutput(false), mValueType(String)
793795
{
794796
#ifdef QGISDEBUG
795797
std::cerr << "QgsGrassModuleOption::QgsGrassModuleOption" << std::endl;
@@ -823,14 +825,17 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
823825
// String without options
824826
if ( !mHidden )
825827
{
826-
828+
QDomElement gelem = gnode.toElement();
829+
827830
// Predefined values ?
828831
QDomNode valuesNode = gnode.namedItem ( "values" );
832+
QDomElement valuesElem = valuesNode.toElement(); // null if valuesNode is null
829833

830-
if ( !valuesNode.isNull() ) // predefined values -> ComboBox or CheckBox
834+
if ( !valuesNode.isNull() && valuesNode.childNodes().count() > 1 )
831835
{
836+
// predefined values -> ComboBox or CheckBox
837+
832838
// one or many?
833-
QDomElement gelem = gnode.toElement();
834839
if ( gelem.attribute("multiple") == "yes" ) {
835840
mControlType = CheckBoxes;
836841
} else {
@@ -841,7 +846,6 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
841846
// List of values to be excluded
842847
QStringList exclude = QStringList::split ( ',', qdesc.attribute("exclude") );
843848

844-
QDomElement valuesElem = valuesNode.toElement();
845849
QDomNode valueNode = valuesElem.firstChild();
846850

847851
while( !valueNode.isNull() ) {
@@ -893,6 +897,39 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
893897
QString def = e.text().stripWhiteSpace();
894898
mLineEdit->setText ( def );
895899
}
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+
}
896933
}
897934
}
898935
}

‎src/plugins/grass/qgsgrassmodule.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class QDomElement;
3131
class QComboBox;
3232
class QLineEdit;
3333
class QPixmap;
34+
class QValidator;
3435

3536
#include <vector>
3637
#include <q3groupbox.h>
@@ -303,6 +304,9 @@ class QgsGrassModuleOption: public Q3GroupBox, public QgsGrassModuleItem
303304

304305
//! Control option
305306
enum ControlType { LineEdit, ComboBox, SpinBox, CheckBoxes };
307+
308+
//! Control option
309+
enum ValueType { Double, Integer, String };
306310

307311
//! Retruns list of options which will be passed to module
308312
virtual QStringList options();
@@ -317,6 +321,9 @@ class QgsGrassModuleOption: public Q3GroupBox, public QgsGrassModuleItem
317321
private:
318322
//! Control type
319323
ControlType mControlType;
324+
325+
//! Value type
326+
ValueType mValueType;
320327

321328
//! Combobox
322329
QComboBox *mComboBox;
@@ -335,6 +342,9 @@ class QgsGrassModuleOption: public Q3GroupBox, public QgsGrassModuleItem
335342

336343
//! Output element
337344
QString mOutputElement;
345+
346+
//! Line input validator
347+
QValidator *mValidator;
338348
};
339349
/********************** QgsGrassModuleFlag ************************/
340350
/*! \class QgsGrassModuleFlag

0 commit comments

Comments
 (0)
Please sign in to comment.