Skip to content

Commit 2fc65a9

Browse files
committed
try to remove spaces and quotes to get a fieldname from an expression
1 parent dcbf893 commit 2fc65a9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/gui/qgsfieldexpressionwidget.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,19 @@ void QgsFieldExpressionWidget::setField( const QString &fieldName )
124124
QModelIndex idx = mFieldProxyModel->sourceFieldModel()->indexFromName( fieldName );
125125
if ( !idx.isValid() )
126126
{
127-
// new expression
128-
idx = mFieldProxyModel->sourceFieldModel()->setExpression( fieldName );
127+
// try to remove quotes and white spaces
128+
QString simpleFieldName = fieldName.trimmed();
129+
if ( simpleFieldName.startsWith( '"' ) && simpleFieldName.endsWith( '"' ) )
130+
{
131+
simpleFieldName.remove( 0, 1 ).chop( 1 );
132+
idx = mFieldProxyModel->sourceFieldModel()->indexFromName( simpleFieldName );
133+
}
134+
135+
if ( !idx.isValid() )
136+
{
137+
// new expression
138+
idx = mFieldProxyModel->sourceFieldModel()->setExpression( fieldName );
139+
}
129140
}
130141
QModelIndex proxyIndex = mFieldProxyModel->mapFromSource( idx );
131142
mCombo->setCurrentIndex( proxyIndex.row() );

0 commit comments

Comments
 (0)