Skip to content

Commit

Permalink
Make sure attribute table doesn't use deleted field formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent c6dc31a commit afacbb1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions python/core/qgsfieldformatterregistry.sip
Expand Up @@ -28,6 +28,7 @@ class QgsFieldFormatterRegistry : QObject
void removeFieldFormatter( QgsFieldFormatter* formatter );
void removeFieldFormatter( const QString& id );
QgsFieldFormatter* fieldFormatter( const QString& id ) const;
QgsFieldFormatter* fallbackFieldFormatter() const;
signals:
void fieldFormatterAdded( QgsFieldFormatter* formatter );
void fieldFormatterRemoved( QgsFieldFormatter* formatter );
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsfieldformatterregistry.cpp
Expand Up @@ -68,3 +68,8 @@ QgsFieldFormatter* QgsFieldFormatterRegistry::fieldFormatter( const QString& id
{
return mFieldFormatters.value( id, mFallbackFieldFormatter );
}

QgsFieldFormatter* QgsFieldFormatterRegistry::fallbackFieldFormatter() const
{
return mFallbackFieldFormatter;
}
6 changes: 6 additions & 0 deletions src/core/qgsfieldformatterregistry.h
Expand Up @@ -69,6 +69,12 @@ class CORE_EXPORT QgsFieldFormatterRegistry : public QObject
*/
QgsFieldFormatter* fieldFormatter( const QString& id ) const;

/**
* Returns a basic fallback field formatter which can be used
* to represent any field in an unspectacular manner.
*/
QgsFieldFormatter* fallbackFieldFormatter() const;

signals:

/**
Expand Down
6 changes: 3 additions & 3 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -269,10 +269,10 @@ void QgsAttributeTableModel::layerDeleted()

void QgsAttributeTableModel::fieldFormatterRemoved( QgsFieldFormatter* fieldFormatter )
{
for ( QVector<QgsFieldFormatter*>::Iterator it = mFieldFormatters.begin(); it != mFieldFormatters.end(); ++it )
for ( int i = 0; i < mFieldFormatters.size(); ++i )
{
if ( it.value() == fieldFormatter )
it.setValue( QgsApplication::fieldFormatterRegistry()->defaultFormatter() );
if ( mFieldFormatters.at( i ) == fieldFormatter )
mFieldFormatters[i] = QgsApplication::fieldFormatterRegistry()->fallbackFieldFormatter();
}
}

Expand Down

0 comments on commit afacbb1

Please sign in to comment.