Skip to content

Commit

Permalink
[GRASS] check if there is input vector for G_OPT_DB_COLUMN
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Sep 3, 2015
1 parent bd8b800 commit 7ac8f41
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/plugins/grass/qgsgrassmoduleoptions.cpp
Expand Up @@ -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() );
}
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/plugins/grass/qgsgrassmoduleparam.cpp
Expand Up @@ -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" );

Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
10 changes: 6 additions & 4 deletions src/plugins/grass/qgsgrassmoduleparam.h
Expand Up @@ -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:

Expand Down Expand Up @@ -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;
};

Expand Down

0 comments on commit 7ac8f41

Please sign in to comment.