Skip to content
Permalink
Browse files

input number validators

git-svn-id: http://svn.osgeo.org/qgis/trunk@4995 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek
rblazek committed Mar 10, 2006
1 parent 547d624 commit e7dcb81c8061852d26ce2fdde57e376cb597e72c
Showing with 52 additions and 5 deletions.
  1. +42 −5 src/plugins/grass/qgsgrassmodule.cpp
  2. +10 −0 src/plugins/grass/qgsgrassmodule.h
@@ -62,6 +62,8 @@
//Added by qt3to4:
#include <QVBoxLayout>
#include <QGridLayout>
#include <QIntValidator>
#include <QDoubleValidator>

#include "qgis.h"
#include "qgsapplication.h"
@@ -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;
@@ -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 {
@@ -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() ) {
@@ -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 );
}
}
}
}
@@ -31,6 +31,7 @@ class QDomElement;
class QComboBox;
class QLineEdit;
class QPixmap;
class QValidator;

#include <vector>
#include <q3groupbox.h>
@@ -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();
@@ -317,6 +321,9 @@ class QgsGrassModuleOption: public Q3GroupBox, public QgsGrassModuleItem
private:
//! Control type
ControlType mControlType;

//! Value type
ValueType mValueType;

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

//! Output element
QString mOutputElement;

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

0 comments on commit e7dcb81

Please sign in to comment.
You can’t perform that action at this time.