Skip to content
Permalink
Browse files

Ensure that accessing QgsFieldFormatterRegistry is thread safe

(cherry picked from commit 344bc5f)
  • Loading branch information
nyalldawson committed Dec 21, 2020
1 parent 1da434b commit 4eebcc7813d2b467fc91cc08a09c7d27f33dd467
@@ -9,6 +9,7 @@




class QgsFieldFormatterRegistry : QObject
{
%Docstring
@@ -26,7 +26,7 @@
#include "qgsrangefieldformatter.h"
#include "qgscheckboxfieldformatter.h"
#include "qgsfallbackfieldformatter.h"

#include "qgsreadwritelocker.h"

QgsFieldFormatterRegistry::QgsFieldFormatterRegistry( QObject *parent )
: QObject( parent )
@@ -45,13 +45,16 @@ QgsFieldFormatterRegistry::QgsFieldFormatterRegistry( QObject *parent )

QgsFieldFormatterRegistry::~QgsFieldFormatterRegistry()
{
QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );
qDeleteAll( mFieldFormatters );
delete mFallbackFieldFormatter;
}

void QgsFieldFormatterRegistry::addFieldFormatter( QgsFieldFormatter *formatter )
{
QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );
mFieldFormatters.insert( formatter->id(), formatter );
locker.unlock();
emit fieldFormatterAdded( formatter );
}

@@ -62,6 +65,7 @@ void QgsFieldFormatterRegistry::removeFieldFormatter( QgsFieldFormatter *formatt

void QgsFieldFormatterRegistry::removeFieldFormatter( const QString &id )
{
QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );
if ( QgsFieldFormatter *formatter = mFieldFormatters.take( id ) )
{
emit fieldFormatterRemoved( formatter );
@@ -71,6 +75,7 @@ void QgsFieldFormatterRegistry::removeFieldFormatter( const QString &id )

QgsFieldFormatter *QgsFieldFormatterRegistry::fieldFormatter( const QString &id ) const
{
QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Read );
return mFieldFormatters.value( id, mFallbackFieldFormatter );
}

@@ -23,6 +23,8 @@
#include "qgis_sip.h"
#include "qgis_core.h"

#include <QReadWriteLock>

class QgsFieldFormatter;
class QgsVectorLayer;

@@ -94,6 +96,7 @@ class CORE_EXPORT QgsFieldFormatterRegistry : public QObject
private:
QHash<QString, QgsFieldFormatter *> mFieldFormatters;
QgsFieldFormatter *mFallbackFieldFormatter = nullptr;
mutable QReadWriteLock mLock;
};

#endif // QGSFIELDKITREGISTRY_H

0 comments on commit 4eebcc7

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