Skip to content
Permalink
Browse files

[GRASS] check if there is input vector for G_OPT_DB_COLUMN

  • Loading branch information
blazek committed Sep 3, 2015
1 parent bd8b800 commit 7ac8f41bd258e9020c74dadfe16fdad866e270a4
@@ -219,7 +219,14 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions(

if ( promptElem.attribute( "prompt" ) == "dbcolumn" )
{
mErrors << tr( "Option '%1' should be configured as field" ).arg( so->key() );
// G_OPT_DB_COLUMN may be also used for new columns (v.in.db) so we check also if there is at least one input vector
// but a vector input may also exist (v.random).
QList<QDomNode> vectorNodes = QgsGrassModuleParam::nodesByType( descDocElem, G_OPT_V_INPUT, "old" );
QgsDebugMsg( QString( "vectorNodes.size() = %1" ).arg( vectorNodes.size() ) );
if ( !vectorNodes.isEmpty() )
{
mErrors << tr( "Option '%1' should be configured as field" ).arg( so->key() );
}
}
}
}
@@ -124,7 +124,7 @@ QStringList QgsGrassModuleParam::options()
return QStringList();
}

QString QgsGrassModuleParam::getDescPrompt( QDomElement descDomElement )
QString QgsGrassModuleParam::getDescPrompt( QDomElement descDomElement, const QString & name )
{
QDomNode gispromptNode = descDomElement.namedItem( "gisprompt" );

@@ -133,7 +133,7 @@ QString QgsGrassModuleParam::getDescPrompt( QDomElement descDomElement )
QDomElement gispromptElement = gispromptNode.toElement();
if ( !gispromptElement.isNull() )
{
return gispromptElement.attribute( "prompt" );
return gispromptElement.attribute( name );
}
}
return QString();
@@ -164,7 +164,7 @@ QDomNode QgsGrassModuleParam::nodeByKey( QDomElement descDomElement, QString key
return QDomNode();
}

QList<QDomNode> QgsGrassModuleParam::nodesByType( QDomElement descDomElement, STD_OPT optionType )
QList<QDomNode> QgsGrassModuleParam::nodesByType( QDomElement descDomElement, STD_OPT optionType, const QString & age )
{
// TODO: never tested
QList<QDomNode> nodes;
@@ -182,15 +182,19 @@ QList<QDomNode> QgsGrassModuleParam::nodesByType( QDomElement descDomElement, ST
typeMap.insert( "dbname", G_OPT_DB_DATABASE );
typeMap.insert( "dbcolumn", G_OPT_DB_COLUMN );
#endif
typeMap.insert( "vector", G_OPT_V_INPUT );

QDomNode n = descDomElement.firstChild();

while ( !n.isNull() )
{
QString prompt = getDescPrompt( n.toElement() );
QString prompt = getDescPrompt( n.toElement(), "prompt" );
if ( typeMap.value( prompt ) == optionType )
{
nodes << n;
if ( age.isEmpty() || getDescPrompt( n.toElement(), "age" ) == age )
{
nodes << n;
}
}

n = n.nextSibling();
@@ -110,15 +110,17 @@ class QgsGrassModuleParam

QStringList errors() { return mErrors; }

/** Get gisprompt tag prompt attribute */
static QString getDescPrompt( QDomElement descDomElement );
/** Get gisprompt attribute
* @paream name gisprompt tag attribute name (age, element, prompt)
*/
static QString getDescPrompt( QDomElement descDomElement, const QString & name );

//! Find element in GRASS module description by key, if not found, returned element is null
static QDomNode nodeByKey( QDomElement descDocElement, QString key );

/** Find list of elements in GRASS module description by option type.
* Option type is identified by gisprompt prompt. Only few types are supported */
static QList<QDomNode> nodesByType( QDomElement descDomElement, STD_OPT optionType );
static QList<QDomNode> nodesByType( QDomElement descDomElement, STD_OPT optionType, const QString & age = QString() );

protected:

@@ -538,7 +540,7 @@ class QgsGrassModuleField : public QgsGrassModuleGroupBoxItem
// ! Field type (integer,double,string,datetime)
QString mType;

//! Combobox for QGIS layer fields
//! Combobox for QGIS layer fieldsnviz
QComboBox *mFieldComboBox;
};

0 comments on commit 7ac8f41

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