Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[GRASS] forgotten QgsGrassModuleOption moved to new file
  • Loading branch information
blazek committed Aug 31, 2015
1 parent 075c50d commit 9a12012
Show file tree
Hide file tree
Showing 2 changed files with 236 additions and 236 deletions.
236 changes: 0 additions & 236 deletions src/plugins/grass/qgsgrassmodule.cpp
Expand Up @@ -1065,239 +1065,3 @@ void QgsGrassModule::setDirectLibraryPath( QProcessEnvironment & environment )
QgsDebugMsg( pathVariable + "=" + lp );
}

/******************* QgsGrassModuleOption ****************************/

QgsGrassModuleOption::QgsGrassModuleOption( QgsGrassModule *module, QString key,
QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode,
bool direct, QWidget * parent )
: QgsGrassModuleGroupBoxItem( module, key, qdesc, gdesc, gnode, direct, parent )
, mControlType( NoControl )
, mValueType( String )
, mOutputType( None )
, mHaveLimits( false )
, mMin( INT_MAX )
, mMax( INT_MIN )
, mComboBox( 0 )
, mIsOutput( false )
, mValidator( 0 )
, mLayout( 0 )
, mUsesRegion( false )
{
QgsDebugMsg( "called." );
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Minimum );

if ( mHidden )
hide();

mLayout = new QVBoxLayout();

// Is it output?
QDomNode promptNode = gnode.namedItem( "gisprompt" );
if ( !promptNode.isNull() )
{
QDomElement promptElem = promptNode.toElement();
QString element = promptElem.attribute( "element" );
QString age = promptElem.attribute( "age" );

if ( age == "new" )
{
mOutputElement = element;
mIsOutput = true;

if ( element == "vector" )
{
mOutputType = Vector;
}
else if ( element == "cell" )
{
mOutputType = Raster;
}
}
}

// 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() && valuesNode.childNodes().count() > 1 )
{
setLayout( mLayout );
// predefined values -> ComboBox or CheckBox

// one or many?
if ( gelem.attribute( "multiple" ) == "yes" )
{
mControlType = CheckBoxes;
}
else
{
mControlType = ComboBox;
mComboBox = new QComboBox( this );
mLayout->addWidget( mComboBox );
}

// List of values to be excluded
QStringList exclude = qdesc.attribute( "exclude" ).split( ',', QString::SkipEmptyParts );

QDomNode valueNode = valuesElem.firstChild();

while ( !valueNode.isNull() )
{
QDomElement valueElem = valueNode.toElement();

if ( !valueElem.isNull() && valueElem.tagName() == "value" )
{

QDomNode n = valueNode.namedItem( "name" );
if ( !n.isNull() )
{
QDomElement e = n.toElement();
QString val = e.text().trimmed();

if ( exclude.contains( val ) == 0 )
{
n = valueNode.namedItem( "description" );
QString desc;
if ( !n.isNull() )
{
e = n.toElement();
desc = e.text().trimmed();
}
else
{
desc = val;
}
desc.replace( 0, 1, desc.left( 1 ).toUpper() );

if ( mControlType == ComboBox )
{
mComboBox->addItem( desc );
if ( mAnswer.length() > 0 && desc == mAnswer )
{
mComboBox->setCurrentIndex( mComboBox->count() - 1 );
}
}
else
{
QgsGrassModuleCheckBox *cb = new QgsGrassModuleCheckBox( desc, this );
mCheckBoxes.push_back( cb );
mLayout->addWidget( cb );
}

mValues.push_back( val );
}
}
}

valueNode = valueNode.nextSibling();
}
}
else // No values
{
// Line edit
mControlType = LineEdit;

if ( gelem.attribute( "type" ) == "integer" )
{
mValueType = Integer;
}
else if ( gelem.attribute( "type" ) == "float" )
{
mValueType = Double;
}

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().trimmed();
minMax = val.split( "-" );
if ( minMax.size() == 2 )
{
mHaveLimits = true;
mMin = minMax.at( 0 ).toDouble();
mMax = minMax.at( 1 ).toDouble();
}
}
}

QDomNode keydescNode = gnode.namedItem( "keydesc" );
if ( !keydescNode.isNull() )
{
// fixed number of line edits
// Example:
// <keydesc>
// <item order="1">rows</item>
// <item order="2">columns</item>
// </keydesc>

QDomNodeList keydescs = keydescNode.childNodes();
for ( int k = 0; k < keydescs.count(); k++ )
{
QDomNode nodeItem = keydescs.at( k );
QString itemDesc = nodeItem.toElement().text().trimmed();
//QString itemDesc = nodeItem.firstChild().toText().data();
QgsDebugMsg( "keydesc item = " + itemDesc );

addLineEdit();
}

setLayout( mLayout );
}
else if ( gelem.attribute( "multiple" ) == "yes" )
{
// variable number of line edits
// add/delete buttons for multiple options
QHBoxLayout *l = new QHBoxLayout( this );
QVBoxLayout *vl = new QVBoxLayout();
l->insertLayout( -1, mLayout );
l->insertLayout( -1, vl );

// TODO: how to keep both buttons on the top?
QPushButton *b = new QPushButton( "+", this );
connect( b, SIGNAL( clicked() ), this, SLOT( addLineEdit() ) );
vl->addWidget( b, 0, Qt::AlignTop );

b = new QPushButton( "-", this );
connect( b, SIGNAL( clicked() ), this, SLOT( removeLineEdit() ) );
vl->addWidget( b, 0, Qt::AlignTop );

// Don't enable this, it makes the group box expanding
// vl->addStretch();
}
else
{
// only one line edit
addLineEdit();
setLayout( mLayout );
}
}
}

mUsesRegion = false;
QString region = qdesc.attribute( "region" );
if ( region.length() > 0 )
{
if ( region == "yes" )
mUsesRegion = true;
}
else
{
QgsDebugMsg( "\n\n\n\n**************************" );
QgsDebugMsg( QString( "isOutput = %1" ).arg( isOutput() ) );
QgsDebugMsg( QString( "mOutputType = %1" ).arg( mOutputType ) );
if ( isOutput() && mOutputType == Raster )
mUsesRegion = true;
}
QgsDebugMsg( QString( "mUsesRegion = %1" ).arg( mUsesRegion ) );
}

0 comments on commit 9a12012

Please sign in to comment.