Skip to content
Permalink
Browse files

[processing] Port aggregates widget wrapper to c++

And add a TON of tests

Fixes #36843
  • Loading branch information
nyalldawson committed Jun 2, 2020
1 parent 4fdfa94 commit d5a340f88696cb97be4aecd8696c5f6d478402a4
@@ -0,0 +1,12 @@
# The following has been generated automatically from src/gui/processing/qgsprocessingaggregatewidgets.h
# monkey patching scoped based enum
QgsAggregateMappingModel.ColumnDataIndex.SourceExpression.__doc__ = "Expression"
QgsAggregateMappingModel.ColumnDataIndex.Aggregate.__doc__ = "Aggregate name"
QgsAggregateMappingModel.ColumnDataIndex.Delimiter.__doc__ = "Delimeter"
QgsAggregateMappingModel.ColumnDataIndex.DestinationName.__doc__ = "Destination field name"
QgsAggregateMappingModel.ColumnDataIndex.DestinationType.__doc__ = "Destination field QVariant::Type casted to (int)"
QgsAggregateMappingModel.ColumnDataIndex.DestinationLength.__doc__ = "Destination field length"
QgsAggregateMappingModel.ColumnDataIndex.DestinationPrecision.__doc__ = "Destination field precision"
QgsAggregateMappingModel.ColumnDataIndex.__doc__ = 'The ColumnDataIndex enum represents the column index for the view\n\n' + '* ``SourceExpression``: ' + QgsAggregateMappingModel.ColumnDataIndex.SourceExpression.__doc__ + '\n' + '* ``Aggregate``: ' + QgsAggregateMappingModel.ColumnDataIndex.Aggregate.__doc__ + '\n' + '* ``Delimiter``: ' + QgsAggregateMappingModel.ColumnDataIndex.Delimiter.__doc__ + '\n' + '* ``DestinationName``: ' + QgsAggregateMappingModel.ColumnDataIndex.DestinationName.__doc__ + '\n' + '* ``DestinationType``: ' + QgsAggregateMappingModel.ColumnDataIndex.DestinationType.__doc__ + '\n' + '* ``DestinationLength``: ' + QgsAggregateMappingModel.ColumnDataIndex.DestinationLength.__doc__ + '\n' + '* ``DestinationPrecision``: ' + QgsAggregateMappingModel.ColumnDataIndex.DestinationPrecision.__doc__
# --
QgsAggregateMappingModel.ColumnDataIndex.baseClass = QgsAggregateMappingModel
@@ -0,0 +1,221 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/processing/qgsprocessingaggregatewidgets.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsAggregateMappingModel: QAbstractTableModel
{
%Docstring
The QgsAggregateMappingModel holds mapping information for defining sets of aggregates of
fields from a QgsFields object.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgsprocessingaggregatewidgets.h"
%End
public:

enum class ColumnDataIndex
{
SourceExpression,
Aggregate,
Delimiter,
DestinationName,
DestinationType,
DestinationLength,
DestinationPrecision,
};


struct Aggregate
{
QString source;

QString aggregate;

QString delimiter;

QgsField field;

};

QgsAggregateMappingModel( const QgsFields &sourceFields = QgsFields(),
QObject *parent = 0 );
%Docstring
Constructs a QgsAggregateMappingModel from a set of ``sourceFields``.
A ``parent`` object can be also specified.
%End

QgsFields sourceFields() const;
%Docstring
Returns a list of source fields
%End

QList<QgsAggregateMappingModel::Aggregate> mapping() const;
%Docstring
Returns a list of Aggregate objects representing the current status of the model
%End

void setMapping( const QList<QgsAggregateMappingModel::Aggregate> &mapping );
%Docstring
Sets the ``mapping`` to show in the model.
%End

void appendField( const QgsField &field, const QString &source = QString(), const QString &aggregate = QString() );
%Docstring
Appends a new ``field`` to the model, with an optional ``source`` and ``aggregate``
%End

bool removeField( const QModelIndex &index );
%Docstring
Removes the field at ``index`` from the model, returns ``True`` on success
%End

bool moveUp( const QModelIndex &index );
%Docstring
Moves down the field at ``index``
%End

bool moveDown( const QModelIndex &index );
%Docstring
Moves up the field at ``index``
%End

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 setBaseExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
%Docstring
Sets the base expression context ``generator``, which will generate the expression
contexts for expression based widgets used by the model.
%End

virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;

virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;

virtual QVariant data( const QModelIndex &index, int role ) const;

virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const;

virtual Qt::ItemFlags flags( const QModelIndex &index ) const;

virtual bool setData( const QModelIndex &index, const QVariant &value, int role );


};

class QgsAggregateMappingWidget : QgsPanelWidget
{
%Docstring
The QgsAggregateMappingWidget class creates a mapping for defining sets of aggregates of
fields from a QgsFields object.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgsprocessingaggregatewidgets.h"
%End
public:

explicit QgsAggregateMappingWidget( QWidget *parent = 0,
const QgsFields &sourceFields = QgsFields() );
%Docstring
Constructs a QgsAggregateMappingWidget from a set of ``sourceFields``. A ``parent`` object
can also be specified.
%End

QgsAggregateMappingModel *model() const;
%Docstring
Returns the underlying mapping model
%End

QList<QgsAggregateMappingModel::Aggregate> mapping() const;
%Docstring
Returns a list of Aggregate objects representing the current status of the underlying mapping model
%End

void setMapping( const QList<QgsAggregateMappingModel::Aggregate> &mapping );
%Docstring
Sets the ``mapping`` to show in the model.
%End

QItemSelectionModel *selectionModel();
%Docstring
Returns the selection model
%End

void setSourceFields( const QgsFields &sourceFields );
%Docstring
Set source fields of the underlying mapping model to ``sourceFields``
%End

void scrollTo( const QModelIndex &index ) const;
%Docstring
Scroll the fields view to ``index``
%End

void registerExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
%Docstring
Register an expression context ``generator`` class that will be used to retrieve
an expression context for the widget.
%End

signals:

void changed();
%Docstring
Emitted when the aggregates defined in the widget are changed.
%End

public slots:

void appendField( const QgsField &field, const QString &source = QString(), const QString &aggregate = QString() );
%Docstring
Appends a new ``field`` to the model, with an optional ``source`` and ``aggregate``
%End

bool removeSelectedFields( );
%Docstring
Removes the currently selected field from the model
%End

bool moveSelectedFieldsUp( );
%Docstring
Moves up currently selected field
%End

bool moveSelectedFieldsDown( );
%Docstring
Moves down currently selected field
%End

public:
};


/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/processing/qgsprocessingaggregatewidgets.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -66,7 +66,7 @@ Returns ``True`` if the destination fields are editable
Sets the destination fields editable state to ``editable``
%End

const QMap<QVariant::Type, QString> dataTypes() const;
static const QMap<QVariant::Type, QString> dataTypes();
%Docstring
Returns a static map of supported data types
%End
@@ -8,6 +8,7 @@




class QgsFieldMappingWidget : QgsPanelWidget
{
%Docstring
@@ -121,12 +122,12 @@ Removes the currently selected field from the model

bool moveSelectedFieldsUp( );
%Docstring
Moves down currently selected field
Moves up currently selected field
%End

bool moveSelectedFieldsDown( );
%Docstring
Moves up the currently selected field
Moves down the currently selected field
%End

public:
@@ -316,6 +316,7 @@
%Include auto_generated/numericformats/qgsnumericformatselectorwidget.sip
%Include auto_generated/numericformats/qgsnumericformatwidget.sip
%Include auto_generated/numericformats/qgsnumericformatguiregistry.sip
%Include auto_generated/processing/qgsprocessingaggregatewidgets.sip
%Include auto_generated/processing/qgsprocessingalgorithmconfigurationwidget.sip
%Include auto_generated/processing/qgsprocessingalgorithmdialogbase.sip
%Include auto_generated/processing/qgsprocessinggui.sip
@@ -75,9 +75,6 @@ def initAlgorithm(self, config=None):

self.addParameter(QgsProcessingParameterAggregate(self.AGGREGATES,
description=self.tr('Aggregates'), parentLayerParameterName='INPUT'))
self.parameterDefinition(self.AGGREGATES).setMetadata({
'widget_wrapper': 'processing.algs.qgis.ui.AggregatesPanel.AggregatesWidgetWrapper'
})

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT,
self.tr('Aggregated')))

0 comments on commit d5a340f

Please sign in to comment.
You can’t perform that action at this time.