Skip to content

Commit

Permalink
Adress PR review + model test + QgsExpression -> QString
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Apr 3, 2020
1 parent 4a33c75 commit a21800c
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 111 deletions.
20 changes: 11 additions & 9 deletions python/gui/auto_generated/qgsfieldmappingmodel.sip.in
Expand Up @@ -41,24 +41,19 @@ the mapping expression is editable.
{
QString originalName;
QgsField field;
QgsExpression expression;
QString expression;
};

QgsFieldMappingModel( const QgsFields &sourceFields = QgsFields(),
const QgsFields &destinationFields = QgsFields(),
const QMap<QString, QgsExpression> &expressions = QMap<QString, QgsExpression>(),
const QMap<QString, QString> &expressions = QMap<QString, QString>(),
QObject *parent = 0 );
%Docstring
Constructs a QgsFieldMappingModel from a set of ``sourceFields``
and ``destinationFields``, initial values for the expressions can be
optionally specified through ``expressions`` which is a map from the original
field name to the corresponding expression. A ``parent`` object
can be also specified.
%End

QgsExpressionContextGenerator *contextGenerator() const;
%Docstring
Returns the context generator with the source fields
%End

bool destinationEditable() const;
Expand Down Expand Up @@ -86,7 +81,7 @@ Returns a list of source fields
Returns a list of Field objects representing the current status of the model
%End

void appendField( const QgsField &field, const QgsExpression &expression = QgsExpression() );
void appendField( const QgsField &field, const QString &expression = QString() );
%Docstring
Appends a new ``field`` to the model, with an optional ``expression``
%End
Expand All @@ -109,10 +104,15 @@ Moves up the field at ``index``
void setSourceFields( const QgsFields &sourceFields );
%Docstring
Set source fields to ``sourceFields``
%End

QgsExpressionContextGenerator *contextGenerator() const;
%Docstring
Returns the context generator with the source fields
%End

void setDestinationFields( const QgsFields &destinationFields,
const QMap<QString, QgsExpression> &expressions = QMap<QString, QgsExpression>() );
const QMap<QString, QString> &expressions = QMap<QString, QString>() );
%Docstring
Set destination fields to ``destinationFields``, initial values for the expressions can be
optionally specified through ``expressions`` which is a map from the original
Expand All @@ -135,6 +135,8 @@ field name to the corresponding expression.
public:
};



/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
6 changes: 3 additions & 3 deletions python/gui/auto_generated/qgsfieldmappingwidget.sip.in
Expand Up @@ -26,7 +26,7 @@ for each set of "destination" fields an expression defines how to obtain the val
explicit QgsFieldMappingWidget( QWidget *parent = 0,
const QgsFields &sourceFields = QgsFields(),
const QgsFields &destinationFields = QgsFields(),
const QMap<QString, QgsExpression> &expressions = QMap<QString, QgsExpression>() );
const QMap<QString, QString> &expressions = QMap<QString, QString>() );
%Docstring
Constructs a QgsFieldMappingWidget from a set of ``sourceFields``
and ``destinationFields``, initial values for the expressions can be
Expand Down Expand Up @@ -66,7 +66,7 @@ Set source fields of the underlying mapping model to ``sourceFields``
%End

void setDestinationFields( const QgsFields &destinationFields,
const QMap<QString, QgsExpression> &expressions = QMap<QString, QgsExpression>() );
const QMap<QString, QString> &expressions = QMap<QString, QString>() );
%Docstring
Set destination fields to ``destinationFields`` in the underlying model,
initial values for the expressions can be optionally specified through
Expand All @@ -81,7 +81,7 @@ Scroll the fields view to ``index``

public slots:

void appendField( const QgsField &field, const QgsExpression &expression = QgsExpression() );
void appendField( const QgsField &field, const QString &expression = QString() );
%Docstring
Appends a new ``field`` to the model, with an optional ``expression``
%End
Expand Down
5 changes: 2 additions & 3 deletions python/plugins/processing/algs/qgis/ui/FieldsMappingPanel.py
Expand Up @@ -48,7 +48,6 @@
QgsVectorLayer,
QgsField,
QgsFields,
QgsExpression,
)

from processing.gui.wrappers import WidgetWrapper, DIALOG_STANDARD, DIALOG_MODELER
Expand Down Expand Up @@ -110,7 +109,7 @@ def value(self):
'type': f.field.type(),
'length': f.field.length(),
'precision': f.field.precision(),
'expression': f.expression.expression(),
'expression': f.expression,
})
return results

Expand All @@ -126,7 +125,7 @@ def setValue(self, value):
field_def.get('length', 0),
field_def.get('precision', 0))
try:
expressions[f.name()] = QgsExpression(field_def['expressions'])
expressions[f.name()] = field_def['expressions']
except AttributeError:
pass
destinationFields.append(f)
Expand Down

0 comments on commit a21800c

Please sign in to comment.