Skip to content
Permalink
Browse files

Generic code cleanup

  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent 22c492e commit 1b5e577fd3d38ebe02ed7860687e8a039cc700a6
@@ -20,17 +20,15 @@ class QgsFieldFormatterRegistry : QObject
%End
public:

QgsFieldFormatterRegistry();
QgsFieldFormatterRegistry( QObject* parent /TransferThis/ );
~QgsFieldFormatterRegistry();

void addFieldFormatter( QgsFieldFormatter* kit /Transfer/ );

void removeFieldFormatter( QgsFieldFormatter* kit );

QgsFieldFormatter* fieldKit( const QString& id ) const;
void addFieldFormatter( QgsFieldFormatter* formatter /Transfer/ );

void removeFieldFormatter( QgsFieldFormatter* formatter );
void removeFieldFormatter( const QString& id );
QgsFieldFormatter* fieldFormatter( const QString& id ) const;
signals:
void fieldKitAdded( QgsFieldFormatter* kit );

void fieldKitRemoved( QgsFieldFormatter* kit );
void fieldFormatterAdded( QgsFieldFormatter* formatter );
void fieldFormatterRemoved( QgsFieldFormatter* formatter );
};
@@ -6399,7 +6399,7 @@ QVariant QgisAppFieldValueConverter::convert( int idx, const QVariant& value )
return value;
}
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, mLayer->fields().field( idx ).name() );
QgsFieldFormatter* fieldKit = QgsApplication::fieldKitRegistry()->fieldKit( setup.type() );
QgsFieldFormatter* fieldKit = QgsApplication::fieldKitRegistry()->fieldFormatter( setup.type() );
return fieldKit->representValue( mLayer, idx, setup.config(), QVariant(), value );
}

@@ -142,7 +142,7 @@ const QVariantMap QgsAttributeTypeDialog::editorWidgetConfig()
return QVariantMap();
}

void QgsAttributeTypeDialog::setWidgetType( const QString& type )
void QgsAttributeTypeDialog::setEditorWidgetType( const QString& type )
{
for ( int i = 0; i < selectionListWidget->count(); i++ )
{
@@ -181,7 +181,7 @@ void QgsAttributeTypeDialog::setWidgetType( const QString& type )
defaultExpressionChanged();
}

void QgsAttributeTypeDialog::setWidgetConfig( const QVariantMap& config )
void QgsAttributeTypeDialog::setEditorWidgetConfig( const QVariantMap& config )
{
mWidgetConfig = config;
}
@@ -311,7 +311,7 @@ void QgsAttributeTypeDialog::on_selectionListWidget_currentRowChanged( int index
{
const QString editType = selectionListWidget->item( index )->data( Qt::UserRole ).toString();

setWidgetType( editType );
setEditorWidgetType( editType );
}

void QgsAttributeTypeDialog::defaultExpressionChanged()
@@ -350,7 +350,7 @@ void QgsAttributeTypeDialog::defaultExpressionChanged()
return;
}

QgsFieldFormatter* fieldKit = QgsApplication::fieldKitRegistry()->fieldKit( editorWidgetType() );
QgsFieldFormatter* fieldKit = QgsApplication::fieldKitRegistry()->fieldFormatter( editorWidgetType() );

QString previewText = fieldKit->representValue( mLayer, mFieldIdx, editorWidgetConfig(), QVariant(), val );

@@ -43,11 +43,11 @@ class APP_EXPORT QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttribut

const QString editorWidgetText();

void setWidgetType( const QString& type );
void setEditorWidgetType( const QString& type );

const QVariantMap editorWidgetConfig();

void setWidgetConfig( const QVariantMap& config );
void setEditorWidgetConfig( const QVariantMap& config );

/**
* Setter for checkbox to label on top
@@ -577,8 +577,8 @@ void QgsFieldsProperties::attributeTypeDialog()
attributeTypeDialog.setConstraintExpressionEnforced( cfg.mConstraintStrength.value( QgsFieldConstraints::ConstraintExpression, QgsFieldConstraints::ConstraintStrengthHard ) == QgsFieldConstraints::ConstraintStrengthHard );
attributeTypeDialog.setDefaultValueExpression( mLayer->defaultValueExpression( index ) );

attributeTypeDialog.setWidgetConfig( cfg.mEditorWidgetConfig );
attributeTypeDialog.setWidgetType( cfg.mEditorWidgetType );
attributeTypeDialog.setEditorWidgetConfig( cfg.mEditorWidgetConfig );
attributeTypeDialog.setEditorWidgetType( cfg.mEditorWidgetType );

if ( !attributeTypeDialog.exec() )
return;
@@ -734,7 +734,7 @@ QString QgsIdentifyResultsDialog::representValue( QgsVectorLayer* vlayer, const
QMap<QString, QVariant>& layerCaches = mWidgetCaches[vlayer->id()];

QgsEditorWidgetFactory* factory = QgsEditorWidgetRegistry::instance()->factory( setup.type() );
QgsFieldFormatter* fieldKit = QgsApplication::fieldKitRegistry()->fieldKit( setup.type() );
QgsFieldFormatter* fieldKit = QgsApplication::fieldKitRegistry()->fieldFormatter( setup.type() );

int idx = vlayer->fields().lookupField( fieldName );

@@ -20,11 +20,6 @@
#include "qgsfield.h"
#include "qgsvectorlayer.h"

QgsDateTimeFieldFormatter::QgsDateTimeFieldFormatter()
{

}

QString QgsDateTimeFieldFormatter::id() const
{
return QStringLiteral( "DateTime" );
@@ -25,9 +25,7 @@
class CORE_EXPORT QgsDateTimeFieldFormatter : public QgsFieldFormatter
{
public:
QgsDateTimeFieldFormatter();

QString id() const override;
virtual QString id() const override;

virtual QString representValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;

@@ -15,11 +15,6 @@
***************************************************************************/
#include "qgsfallbackfieldformatter.h"

QgsFallbackFieldFormatter::QgsFallbackFieldFormatter()
{

}

QString QgsFallbackFieldFormatter::id() const
{
return QString();
@@ -21,9 +21,7 @@
class CORE_EXPORT QgsFallbackFieldFormatter : public QgsFieldFormatter
{
public:
QgsFallbackFieldFormatter();

QString id() const override;
virtual QString id() const override;
};

#endif // QGSFALLBACKFIELDKIT_H
@@ -17,11 +17,6 @@

#include <QSettings>

QgsKeyValueFieldFormatter::QgsKeyValueFieldFormatter()
{

}

QString QgsKeyValueFieldFormatter::id() const
{
return QStringLiteral( "KeyValue" );
@@ -21,10 +21,8 @@
class CORE_EXPORT QgsKeyValueFieldFormatter : public QgsFieldFormatter
{
public:
QgsKeyValueFieldFormatter();

QString id() const override;
QString representValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
virtual QString id() const override;
virtual QString representValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
};

#endif // QGSKEYVALUEFIELDKIT_H
@@ -17,11 +17,6 @@

#include <QSettings>

QgsListFieldFormatter::QgsListFieldFormatter()
{

}

QString QgsListFieldFormatter::id() const
{
return QStringLiteral( "List" );
@@ -21,11 +21,9 @@
class CORE_EXPORT QgsListFieldFormatter : public QgsFieldFormatter
{
public:
QgsListFieldFormatter();
virtual QString id() const override;

QString id() const override;

QString representValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
virtual QString representValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
};

#endif // QGSLISTFIELDKIT_H
@@ -22,11 +22,6 @@
#include "qgsrelationmanager.h"
#include "qgsvectorlayer.h"

QgsRelationReferenceFieldFormatter::QgsRelationReferenceFieldFormatter()
{

}

QString QgsRelationReferenceFieldFormatter::id() const
{
return QStringLiteral( "RelationReference" );
@@ -21,9 +21,7 @@
class CORE_EXPORT QgsRelationReferenceFieldFormatter : public QgsFieldFormatter
{
public:
QgsRelationReferenceFieldFormatter();

QString id() const override;
virtual QString id() const override;

virtual QString representValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;

@@ -17,11 +17,6 @@

#include "qgsvectorlayer.h"

QgsValueMapFieldFormatter::QgsValueMapFieldFormatter()
{

}

QString QgsValueMapFieldFormatter::id() const
{
return QStringLiteral( "ValueMap" );
@@ -23,13 +23,11 @@
class CORE_EXPORT QgsValueMapFieldFormatter : public QgsFieldFormatter
{
public:
QgsValueMapFieldFormatter();
virtual QString id() const override;

QString id() const override;
virtual QString representValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;

QString representValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;

QVariant sortValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
virtual QVariant sortValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const override;
};

#endif // QGSVALUEMAPFIELDKIT_H
@@ -44,22 +44,27 @@ QgsFieldFormatterRegistry::~QgsFieldFormatterRegistry()
delete mFallbackFieldFormatter;
}

void QgsFieldFormatterRegistry::addFieldFormatter( QgsFieldFormatter* kit )
void QgsFieldFormatterRegistry::addFieldFormatter( QgsFieldFormatter* formatter )
{
mFieldFormatters.insert( kit->id(), kit );
emit fieldKitAdded( kit );
mFieldFormatters.insert( formatter->id(), formatter );
emit fieldFormatterAdded( formatter );
}

void QgsFieldFormatterRegistry::removeFieldFormatter( QgsFieldFormatter* kit )
void QgsFieldFormatterRegistry::removeFieldFormatter( QgsFieldFormatter* formatter )
{
if ( mFieldFormatters.remove( kit->id() ) )
removeFieldFormatter( formatter->id() );
}

void QgsFieldFormatterRegistry::removeFieldFormatter( const QString& id )
{
if ( QgsFieldFormatter* formatter = mFieldFormatters.take( id ) )
{
emit fieldKitRemoved( kit );
delete kit;
emit fieldFormatterRemoved( formatter );
delete formatter;
}
}

QgsFieldFormatter* QgsFieldFormatterRegistry::fieldKit( const QString& id ) const
QgsFieldFormatter* QgsFieldFormatterRegistry::fieldFormatter( const QString& id ) const
{
return mFieldFormatters.value( id, mFallbackFieldFormatter );
}
@@ -41,7 +41,7 @@ class CORE_EXPORT QgsFieldFormatterRegistry : public QObject
*
* Use the one provided by `QgsApplication::fieldKitRegistry()` instead.
*/
QgsFieldFormatterRegistry( QObject* parent = nullptr );
explicit QgsFieldFormatterRegistry( QObject* parent = nullptr );
~QgsFieldFormatterRegistry();

/**
@@ -50,31 +50,36 @@ class CORE_EXPORT QgsFieldFormatterRegistry : public QObject
*
* Ownership is transferred to the registry.
*/
void addFieldFormatter( QgsFieldFormatter* kit );
void addFieldFormatter( QgsFieldFormatter* formatter );

/**
* Remove a field formatter from the registry.
* The field formatter will be deleted.
*/
void removeFieldFormatter( QgsFieldFormatter* kit );
void removeFieldFormatter( QgsFieldFormatter* formatter );

/**
* Remove the field formatter with the specified id.
*/
void removeFieldFormatter( const QString& id );

/**
* Get a field formatter by its id. If there is no such id registered,
* a default QgsFallbackFieldFormatter with a null id will be returned instead.
*/
QgsFieldFormatter* fieldKit( const QString& id ) const;
QgsFieldFormatter* fieldFormatter( const QString& id ) const;

signals:

/**
* Will be emitted after a new field formatter has been added.
*/
void fieldKitAdded( QgsFieldFormatter* kit );
void fieldFormatterAdded( QgsFieldFormatter* formatter );

/**
* Will be emitted just before a field formatter is removed and deleted.
*/
void fieldKitRemoved( QgsFieldFormatter* kit );
void fieldFormatterRemoved( QgsFieldFormatter* formatter );

private:
QHash<QString, QgsFieldFormatter*> mFieldFormatters;
@@ -343,7 +343,7 @@ void QgsAttributeTableModel::loadAttributes()
{
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( layer(), fields[idx].name() );
QgsEditorWidgetFactory* widgetFactory = QgsEditorWidgetRegistry::instance()->factory( setup.type() );
QgsFieldFormatter* fieldKit = QgsApplication::fieldKitRegistry()->fieldKit( setup.type() );
QgsFieldFormatter* fieldKit = QgsApplication::fieldKitRegistry()->fieldFormatter( setup.type() );

if ( widgetFactory )
{
@@ -3383,7 +3383,7 @@ QDomElement QgsWmsServer::createFeatureGML(
QString QgsWmsServer::replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, const QString& attributeVal )
{
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( vl, vl->fields().field( idx ).name() );
QgsFieldFormatter* fieldKit = QgsApplication::fieldKitRegistry()->fieldKit( setup.type() );
QgsFieldFormatter* fieldKit = QgsApplication::fieldKitRegistry()->fieldFormatter( setup.type() );
QString value( fieldKit->representValue( vl, idx, setup.config(), QVariant(), attributeVal ) );

if ( setup.config().value( QStringLiteral( "AllowMulti" ) ).toBool() && value.startsWith( QLatin1String( "{" ) ) && value.endsWith( QLatin1String( "}" ) ) )

0 comments on commit 1b5e577

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