QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 : [email protected]
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 #include "qgsfieldformatter.h"
19 
25 #include "qgslistfieldformatter.h"
26 #include "qgsrangefieldformatter.h"
29 #include "qgsreadwritelocker.h"
30 
32  : QObject( parent )
33 {
42 
43  mFallbackFieldFormatter = new QgsFallbackFieldFormatter();
44 }
45 
47 {
48  const QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );
49  qDeleteAll( mFieldFormatters );
50  delete mFallbackFieldFormatter;
51 }
52 
54 {
56  mFieldFormatters.insert( formatter->id(), formatter );
57  locker.unlock();
59 }
60 
62 {
64 }
65 
67 {
68  const QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );
69  if ( QgsFieldFormatter *formatter = mFieldFormatters.take( id ) )
70  {
72  delete formatter;
73  }
74 }
75 
77 {
78  const QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Read );
79  return mFieldFormatters.value( id, mFallbackFieldFormatter );
80 }
81 
83 {
84  return mFallbackFieldFormatter;
85 }
formatter
Definition: qgsbasicnumericformat.cpp:24
qgsreadwritelocker.h
QgsReadWriteLocker::Read
@ Read
Lock for read.
Definition: qgsreadwritelocker.h:75
qgsvaluerelationfieldformatter.h
QgsListFieldFormatter
Field formatter for a list field.
Definition: qgslistfieldformatter.h:31
QgsFieldFormatterRegistry::QgsFieldFormatterRegistry
QgsFieldFormatterRegistry(QObject *parent=nullptr)
You should not normally need to create your own field formatter registry.
Definition: qgsfieldformatterregistry.cpp:31
qgskeyvaluefieldformatter.h
qgsfieldformatterregistry.h
QgsFieldFormatterRegistry::fieldFormatterRemoved
void fieldFormatterRemoved(QgsFieldFormatter *formatter)
Will be emitted just before a field formatter is removed and deleted.
QgsFallbackFieldFormatter
A default fallback field formatter in case no specialized field formatter is defined.
Definition: qgsfallbackfieldformatter.h:30
QgsReadWriteLocker::unlock
void unlock()
Unlocks the lock.
Definition: qgsreadwritelocker.cpp:45
QgsReadWriteLocker
The QgsReadWriteLocker class is a convenience class that simplifies locking and unlocking QReadWriteL...
Definition: qgsreadwritelocker.h:40
qgsfallbackfieldformatter.h
QgsRangeFieldFormatter
Field formatter for a range (double) field with precision and locale.
Definition: qgsrangefieldformatter.h:28
QgsCheckBoxFieldFormatter
Field formatter for a checkbox field.
Definition: qgscheckboxfieldformatter.h:29
qgsvaluemapfieldformatter.h
QgsReadWriteLocker::Write
@ Write
Lock for write.
Definition: qgsreadwritelocker.h:76
qgsrangefieldformatter.h
QgsKeyValueFieldFormatter
Field formatter for a key value field.
Definition: qgskeyvaluefieldformatter.h:34
QgsFieldFormatterRegistry::removeFieldFormatter
void removeFieldFormatter(QgsFieldFormatter *formatter)
Remove a field formatter from the registry.
Definition: qgsfieldformatterregistry.cpp:61
QgsRelationReferenceFieldFormatter
Field formatter for a relation reference field.
Definition: qgsrelationreferencefieldformatter.h:31
qgsdatetimefieldformatter.h
qgsrelationreferencefieldformatter.h
QgsFieldFormatterRegistry::fieldFormatterAdded
void fieldFormatterAdded(QgsFieldFormatter *formatter)
Will be emitted after a new field formatter has been added.
QgsFieldFormatterRegistry::~QgsFieldFormatterRegistry
~QgsFieldFormatterRegistry() override
Definition: qgsfieldformatterregistry.cpp:46
QgsValueMapFieldFormatter
Field formatter for a ValueMap field.
Definition: qgsvaluemapfieldformatter.h:40
QgsFieldFormatterRegistry::fallbackFieldFormatter
QgsFieldFormatter * fallbackFieldFormatter() const
Returns a basic fallback field formatter which can be used to represent any field in an unspectacular...
Definition: qgsfieldformatterregistry.cpp:82
QgsFieldFormatterRegistry::fieldFormatter
QgsFieldFormatter * fieldFormatter(const QString &id) const
Gets a field formatter by its id.
Definition: qgsfieldformatterregistry.cpp:76
QgsValueRelationFieldFormatter
Field formatter for a value relation field.
Definition: qgsvaluerelationfieldformatter.h:37
QgsFieldFormatterRegistry::addFieldFormatter
void addFieldFormatter(QgsFieldFormatter *formatter)
They will take precedence in order of adding them.
Definition: qgsfieldformatterregistry.cpp:53
qgscheckboxfieldformatter.h
QgsDateTimeFieldFormatter
Field formatter for a date time field.
Definition: qgsdatetimefieldformatter.h:31
qgslistfieldformatter.h
QgsFieldFormatter
A field formatter helps to handle and display values for a field.
Definition: qgsfieldformatter.h:72
qgsfieldformatter.h