Skip to content

Commit

Permalink
input number validators
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@4995 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 10, 2006
1 parent 547d624 commit e7dcb81
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
47 changes: 42 additions & 5 deletions src/plugins/grass/qgsgrassmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
//Added by qt3to4:
#include <QVBoxLayout>
#include <QGridLayout>
#include <QIntValidator>
#include <QDoubleValidator>

#include "qgis.h"
#include "qgsapplication.h"
Expand Down Expand Up @@ -789,7 +791,7 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
QWidget * parent)
: Q3GroupBox ( 1, Qt::Vertical, parent ),
QgsGrassModuleItem ( module, key, qdesc, gdesc, gnode ),
mIsOutput(false)
mIsOutput(false), mValueType(String)
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassModuleOption::QgsGrassModuleOption" << std::endl;
Expand Down Expand Up @@ -823,14 +825,17 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
// String without options
if ( !mHidden )
{

QDomElement gelem = gnode.toElement();

// Predefined values ?
QDomNode valuesNode = gnode.namedItem ( "values" );
QDomElement valuesElem = valuesNode.toElement(); // null if valuesNode is null

if ( !valuesNode.isNull() ) // predefined values -> ComboBox or CheckBox
if ( !valuesNode.isNull() && valuesNode.childNodes().count() > 1 )
{
// predefined values -> ComboBox or CheckBox

// one or many?
QDomElement gelem = gnode.toElement();
if ( gelem.attribute("multiple") == "yes" ) {
mControlType = CheckBoxes;
} else {
Expand All @@ -841,7 +846,6 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
// List of values to be excluded
QStringList exclude = QStringList::split ( ',', qdesc.attribute("exclude") );

QDomElement valuesElem = valuesNode.toElement();
QDomNode valueNode = valuesElem.firstChild();

while( !valueNode.isNull() ) {
Expand Down Expand Up @@ -893,6 +897,39 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
QString def = e.text().stripWhiteSpace();
mLineEdit->setText ( def );
}

QStringList minMax;
if ( valuesNode.childNodes().count() == 1 )
{
QDomNode valueNode = valuesElem.firstChild();

QDomNode n = valueNode.namedItem ( "name" );
if ( !n.isNull() ) {
QDomElement e = n.toElement();
QString val = e.text().stripWhiteSpace();
minMax = val.split("-");
}
}
if ( gelem.attribute("type") == "integer" )
{
mValueType = Integer;
if ( minMax.size() == 2 ) {
mValidator = new QIntValidator( minMax.at(0).toInt(),
minMax.at(1).toInt(), this );
} else {
mValidator = new QIntValidator( this );
}
mLineEdit->setValidator ( mValidator );
} else if ( gelem.attribute("type") == "float" ) {
mValueType = Double;
if ( minMax.size() == 2 ) {
mValidator = new QDoubleValidator( minMax.at(0).toDouble(),
minMax.at(1).toDouble(), 10, this );
} else {
mValidator = new QDoubleValidator( this );
}
mLineEdit->setValidator ( mValidator );
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/grass/qgsgrassmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class QDomElement;
class QComboBox;
class QLineEdit;
class QPixmap;
class QValidator;

#include <vector>
#include <q3groupbox.h>
Expand Down Expand Up @@ -303,6 +304,9 @@ class QgsGrassModuleOption: public Q3GroupBox, public QgsGrassModuleItem

//! Control option
enum ControlType { LineEdit, ComboBox, SpinBox, CheckBoxes };

//! Control option
enum ValueType { Double, Integer, String };

//! Retruns list of options which will be passed to module
virtual QStringList options();
Expand All @@ -317,6 +321,9 @@ class QgsGrassModuleOption: public Q3GroupBox, public QgsGrassModuleItem
private:
//! Control type
ControlType mControlType;

//! Value type
ValueType mValueType;

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

//! Output element
QString mOutputElement;

//! Line input validator
QValidator *mValidator;
};
/********************** QgsGrassModuleFlag ************************/
/*! \class QgsGrassModuleFlag
Expand Down

0 comments on commit e7dcb81

Please sign in to comment.