[GRASS] check if there is input vector for G_OPT_DB_COLUMN

This commit is contained in:
Radim Blazek 2015-09-03 11:04:37 +02:00
parent bd8b800dd3
commit 7ac8f41bd2
3 changed files with 23 additions and 10 deletions

View File

@ -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() );
}
}
}
}

View File

@ -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();

View File

@ -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;
};