Skip to content

Commit 7ac8f41

Browse files
committedSep 3, 2015
[GRASS] check if there is input vector for G_OPT_DB_COLUMN
1 parent bd8b800 commit 7ac8f41

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed
 

‎src/plugins/grass/qgsgrassmoduleoptions.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,14 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions(
219219

220220
if ( promptElem.attribute( "prompt" ) == "dbcolumn" )
221221
{
222-
mErrors << tr( "Option '%1' should be configured as field" ).arg( so->key() );
222+
// 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
223+
// but a vector input may also exist (v.random).
224+
QList<QDomNode> vectorNodes = QgsGrassModuleParam::nodesByType( descDocElem, G_OPT_V_INPUT, "old" );
225+
QgsDebugMsg( QString( "vectorNodes.size() = %1" ).arg( vectorNodes.size() ) );
226+
if ( !vectorNodes.isEmpty() )
227+
{
228+
mErrors << tr( "Option '%1' should be configured as field" ).arg( so->key() );
229+
}
223230
}
224231
}
225232
}

‎src/plugins/grass/qgsgrassmoduleparam.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ QStringList QgsGrassModuleParam::options()
124124
return QStringList();
125125
}
126126

127-
QString QgsGrassModuleParam::getDescPrompt( QDomElement descDomElement )
127+
QString QgsGrassModuleParam::getDescPrompt( QDomElement descDomElement, const QString & name )
128128
{
129129
QDomNode gispromptNode = descDomElement.namedItem( "gisprompt" );
130130

@@ -133,7 +133,7 @@ QString QgsGrassModuleParam::getDescPrompt( QDomElement descDomElement )
133133
QDomElement gispromptElement = gispromptNode.toElement();
134134
if ( !gispromptElement.isNull() )
135135
{
136-
return gispromptElement.attribute( "prompt" );
136+
return gispromptElement.attribute( name );
137137
}
138138
}
139139
return QString();
@@ -164,7 +164,7 @@ QDomNode QgsGrassModuleParam::nodeByKey( QDomElement descDomElement, QString key
164164
return QDomNode();
165165
}
166166

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

186187
QDomNode n = descDomElement.firstChild();
187188

188189
while ( !n.isNull() )
189190
{
190-
QString prompt = getDescPrompt( n.toElement() );
191+
QString prompt = getDescPrompt( n.toElement(), "prompt" );
191192
if ( typeMap.value( prompt ) == optionType )
192193
{
193-
nodes << n;
194+
if ( age.isEmpty() || getDescPrompt( n.toElement(), "age" ) == age )
195+
{
196+
nodes << n;
197+
}
194198
}
195199

196200
n = n.nextSibling();

‎src/plugins/grass/qgsgrassmoduleparam.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,17 @@ class QgsGrassModuleParam
110110

111111
QStringList errors() { return mErrors; }
112112

113-
/** Get gisprompt tag prompt attribute */
114-
static QString getDescPrompt( QDomElement descDomElement );
113+
/** Get gisprompt attribute
114+
* @paream name gisprompt tag attribute name (age, element, prompt)
115+
*/
116+
static QString getDescPrompt( QDomElement descDomElement, const QString & name );
115117

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

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

123125
protected:
124126

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

541-
//! Combobox for QGIS layer fields
543+
//! Combobox for QGIS layer fieldsnviz
542544
QComboBox *mFieldComboBox;
543545
};
544546

0 commit comments

Comments
 (0)
Please sign in to comment.