Skip to content

Commit

Permalink
[processing] Add missing {string,integer,double} array types support …
Browse files Browse the repository at this point in the history
…in the aggregate algorithm
  • Loading branch information
nirvn committed Jan 30, 2022
1 parent 2918c1a commit a9d5ae2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions python/gui/auto_generated/qgsfieldmappingmodel.sip.in
Expand Up @@ -145,6 +145,7 @@ optionally specified through ``expressions`` which is a map from the original
field name to the corresponding expression.
%End


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

virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
Expand Down
4 changes: 3 additions & 1 deletion src/analysis/processing/qgsalgorithmaggregate.cpp
Expand Up @@ -93,11 +93,13 @@ bool QgsAggregateAlgorithm::prepareAlgorithm( const QVariantMap &parameters, Qgs
throw QgsProcessingException( QObject::tr( "Field name cannot be empty" ) );

const QVariant::Type type = static_cast< QVariant::Type >( aggregateDef.value( QStringLiteral( "type" ) ).toInt() );
const QString typeName = aggregateDef.value( QStringLiteral( "type_name" ) ).toString();
const QVariant::Type subType = static_cast< QVariant::Type >( aggregateDef.value( QStringLiteral( "sub_type" ) ).toInt() );

const int length = aggregateDef.value( QStringLiteral( "length" ), 0 ).toInt();
const int precision = aggregateDef.value( QStringLiteral( "precision" ), 0 ).toInt();

mFields.append( QgsField( name, type, QString(), length, precision ) );
mFields.append( QgsField( name, type, typeName, length, precision, QString(), subType ) );


const QString aggregateType = aggregateDef.value( QStringLiteral( "aggregate" ) ).toString();
Expand Down
5 changes: 3 additions & 2 deletions src/gui/processing/qgsprocessingaggregatewidgets.cpp
Expand Up @@ -140,7 +140,7 @@ QVariant QgsAggregateMappingModel::data( const QModelIndex &index, int role ) co
}
case ColumnDataIndex::DestinationType:
{
return static_cast<int>( agg.field.type() );
return agg.field.typeName();
}
case ColumnDataIndex::DestinationLength:
{
Expand Down Expand Up @@ -201,7 +201,7 @@ bool QgsAggregateMappingModel::setData( const QModelIndex &index, const QVariant
}
case ColumnDataIndex::DestinationType:
{
f.field.setType( static_cast<QVariant::Type>( value.toInt( ) ) );
QgsFieldMappingModel::setFieldTypeFromName( f.field, value.toString() );
break;
}
case ColumnDataIndex::DestinationLength:
Expand Down Expand Up @@ -268,6 +268,7 @@ void QgsAggregateMappingModel::setSourceFields( const QgsFields &sourceFields )
{
Aggregate aggregate;
aggregate.field = f;
aggregate.field.setTypeName( QgsFieldMappingModel::qgsFieldToTypeName( f ) );
aggregate.source = QgsExpression::quotedColumnRef( f.name() );

if ( f.isNumeric() )
Expand Down
8 changes: 6 additions & 2 deletions src/gui/processing/qgsprocessingaggregatewidgetwrapper.cpp
Expand Up @@ -107,8 +107,10 @@ QVariant QgsProcessingAggregatePanelWidget::value() const
QVariantMap def;
def.insert( QStringLiteral( "name" ), aggregate.field.name() );
def.insert( QStringLiteral( "type" ), static_cast< int >( aggregate.field.type() ) );
def.insert( QStringLiteral( "type_name" ), aggregate.field.typeName() );
def.insert( QStringLiteral( "length" ), aggregate.field.length() );
def.insert( QStringLiteral( "precision" ), aggregate.field.precision() );
def.insert( QStringLiteral( "sub_type" ), static_cast< int >( aggregate.field.subType() ) );
def.insert( QStringLiteral( "input" ), aggregate.source );
def.insert( QStringLiteral( "aggregate" ), aggregate.aggregate );
def.insert( QStringLiteral( "delimiter" ), aggregate.delimiter );
Expand All @@ -131,9 +133,11 @@ void QgsProcessingAggregatePanelWidget::setValue( const QVariant &value )
const QVariantMap map = field.toMap();
const QgsField f( map.value( QStringLiteral( "name" ) ).toString(),
static_cast< QVariant::Type >( map.value( QStringLiteral( "type" ), QVariant::Invalid ).toInt() ),
QVariant::typeToName( static_cast< QVariant::Type >( map.value( QStringLiteral( "type" ), QVariant::Invalid ).toInt() ) ),
map.value( QStringLiteral( "type_name" ), QVariant::typeToName( static_cast< QVariant::Type >( map.value( QStringLiteral( "type" ), QVariant::Invalid ).toInt() ) ) ).toString(),
map.value( QStringLiteral( "length" ), 0 ).toInt(),
map.value( QStringLiteral( "precision" ), 0 ).toInt() );
map.value( QStringLiteral( "precision" ), 0 ).toInt(),
QString(),
static_cast< QVariant::Type >( map.value( QStringLiteral( "sub_type" ), QVariant::Invalid ).toInt() ) );

QgsAggregateMappingModel::Aggregate aggregate;
aggregate.field = f;
Expand Down
13 changes: 11 additions & 2 deletions src/gui/qgsfieldmappingmodel.h
Expand Up @@ -149,6 +149,7 @@ class GUI_EXPORT QgsFieldMappingModel: public QAbstractTableModel
void setDestinationFields( const QgsFields &destinationFields,
const QMap<QString, QString> &expressions = QMap<QString, QString>() );


// QAbstractItemModel interface
int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
Expand Down Expand Up @@ -182,9 +183,17 @@ class GUI_EXPORT QgsFieldMappingModel: public QAbstractTableModel

QgsFieldConstraints::Constraints fieldConstraints( const QgsField &field ) const;

const QString qgsFieldToTypeName( const QgsField &field );
/**
* Returns the field type name matching the \a field settings.
* \since QGIS 3.14
*/
static const QString qgsFieldToTypeName( const QgsField &field );

void setFieldTypeFromName( QgsField &field, const QString &name );
/**
* Sets the \a field type and subtype based on the type \a name provided.
* \since QGIS 3.14
*/
static void setFieldTypeFromName( QgsField &field, const QString &name );

bool moveUpOrDown( const QModelIndex &index, bool up = true );

Expand Down

0 comments on commit a9d5ae2

Please sign in to comment.