QGIS API Documentation 4.3.0-Master (dc0ce6e99ce)
Loading...
Searching...
No Matches
qgsfieldformatterregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsfieldformatterregistry.cpp - QgsFieldFormatterRegistry
3
4 ---------------------
5 begin : 2.12.2016
6 copyright : (C) 2016 by Matthias Kuhn
7 email : matthias@opengis.ch
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
18
23#include "qgsfieldformatter.h"
27#include "qgsreadwritelocker.h"
31
32#include "moc_qgsfieldformatterregistry.cpp"
33
49
51{
52 const QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );
53 qDeleteAll( mFieldFormatters );
54}
55
57{
59 mFieldFormatters.insert( formatter->id(), formatter );
60 locker.unlock();
61 emit fieldFormatterAdded( formatter );
62}
63
68
70{
71 const QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );
72 if ( QgsFieldFormatter *formatter = mFieldFormatters.take( id ) )
73 {
74 emit fieldFormatterRemoved( formatter );
75 delete formatter;
76 }
77}
78
80{
81 const QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Read );
82 return mFieldFormatters.value( id, mFallbackFieldFormatter.get() );
83}
84
86{
87 return mFallbackFieldFormatter.get();
88}
Field formatter for a checkbox field.
Field formatter for a date time field.
Field formatter for an Enumeration field.
void fieldFormatterRemoved(QgsFieldFormatter *formatter)
Will be emitted just before a field formatter is removed and deleted.
QgsFieldFormatter * fallbackFieldFormatter() const
Returns a basic fallback field formatter which can be used to represent any field in an unspectacular...
void fieldFormatterAdded(QgsFieldFormatter *formatter)
Will be emitted after a new field formatter has been added.
void removeFieldFormatter(QgsFieldFormatter *formatter)
Remove a field formatter from the registry.
QgsFieldFormatterRegistry(QObject *parent=nullptr)
You should not normally need to create your own field formatter registry.
void addFieldFormatter(QgsFieldFormatter *formatter)
They will take precedence in order of adding them.
QgsFieldFormatter * fieldFormatter(const QString &id) const
Gets a field formatter by its id.
A field formatter helps to handle and display values for a field.
virtual QString id() const =0
Returns a unique id for this field formatter.
Field formatter for a key value field.
Field formatter for a list field.
Field formatter for a range (double) field with precision and locale.
A convenience class that simplifies locking and unlocking QReadWriteLocks.
@ Write
Lock for write.
void unlock()
Unlocks the lock.
Field formatter for a relation reference field.
Field formatter for a ValueMap field.
Field formatter for a value relation field.