Skip to content

Commit

Permalink
Generic code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent 22c492e commit 1b5e577
Show file tree
Hide file tree
Showing 22 changed files with 53 additions and 87 deletions.
16 changes: 7 additions & 9 deletions python/core/qgsfieldformatterregistry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
};
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsattributetypedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++ )
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 );

Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsattributetypedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsfieldsproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsidentifyresultsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
5 changes: 0 additions & 5 deletions src/core/fieldformatter/qgsdatetimefieldformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
#include "qgsfield.h"
#include "qgsvectorlayer.h"

QgsDateTimeFieldFormatter::QgsDateTimeFieldFormatter()
{

}

QString QgsDateTimeFieldFormatter::id() const
{
return QStringLiteral( "DateTime" );
Expand Down
4 changes: 1 addition & 3 deletions src/core/fieldformatter/qgsdatetimefieldformatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 0 additions & 5 deletions src/core/fieldformatter/qgsfallbackfieldformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
***************************************************************************/
#include "qgsfallbackfieldformatter.h"

QgsFallbackFieldFormatter::QgsFallbackFieldFormatter()
{

}

QString QgsFallbackFieldFormatter::id() const
{
return QString();
Expand Down
4 changes: 1 addition & 3 deletions src/core/fieldformatter/qgsfallbackfieldformatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
class CORE_EXPORT QgsFallbackFieldFormatter : public QgsFieldFormatter
{
public:
QgsFallbackFieldFormatter();

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

#endif // QGSFALLBACKFIELDKIT_H
5 changes: 0 additions & 5 deletions src/core/fieldformatter/qgskeyvaluefieldformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

#include <QSettings>

QgsKeyValueFieldFormatter::QgsKeyValueFieldFormatter()
{

}

QString QgsKeyValueFieldFormatter::id() const
{
return QStringLiteral( "KeyValue" );
Expand Down
6 changes: 2 additions & 4 deletions src/core/fieldformatter/qgskeyvaluefieldformatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions src/core/fieldformatter/qgslistfieldformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

#include <QSettings>

QgsListFieldFormatter::QgsListFieldFormatter()
{

}

QString QgsListFieldFormatter::id() const
{
return QStringLiteral( "List" );
Expand Down
6 changes: 2 additions & 4 deletions src/core/fieldformatter/qgslistfieldformatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
#include "qgsrelationmanager.h"
#include "qgsvectorlayer.h"

QgsRelationReferenceFieldFormatter::QgsRelationReferenceFieldFormatter()
{

}

QString QgsRelationReferenceFieldFormatter::id() const
{
return QStringLiteral( "RelationReference" );
Expand Down
4 changes: 1 addition & 3 deletions src/core/fieldformatter/qgsrelationreferencefieldformatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 0 additions & 5 deletions src/core/fieldformatter/qgsvaluemapfieldformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

#include "qgsvectorlayer.h"

QgsValueMapFieldFormatter::QgsValueMapFieldFormatter()
{

}

QString QgsValueMapFieldFormatter::id() const
{
return QStringLiteral( "ValueMap" );
Expand Down
8 changes: 3 additions & 5 deletions src/core/fieldformatter/qgsvaluemapfieldformatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 13 additions & 8 deletions src/core/qgsfieldformatterregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
17 changes: 11 additions & 6 deletions src/core/qgsfieldformatterregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsattributetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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( "}" ) ) )
Expand Down

0 comments on commit 1b5e577

Please sign in to comment.