QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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  ***************************************************************************/
17 #include "qgsfieldformatter.h"
18 
24 #include "qgslistfieldformatter.h"
25 #include "qgsrangefieldformatter.h"
28 
29 
31  : QObject( parent )
32 {
41 
42  mFallbackFieldFormatter = new QgsFallbackFieldFormatter();
43 }
44 
46 {
47  qDeleteAll( mFieldFormatters );
48  delete mFallbackFieldFormatter;
49 }
50 
52 {
53  mFieldFormatters.insert( formatter->id(), formatter );
54  emit fieldFormatterAdded( formatter );
55 }
56 
58 {
59  removeFieldFormatter( formatter->id() );
60 }
61 
63 {
64  if ( QgsFieldFormatter *formatter = mFieldFormatters.take( id ) )
65  {
66  emit fieldFormatterRemoved( formatter );
67  delete formatter;
68  }
69 }
70 
72 {
73  return mFieldFormatters.value( id, mFallbackFieldFormatter );
74 }
75 
77 {
78  return mFallbackFieldFormatter;
79 }
Field formatter for a key value field.
Field formatter for a ValueMap field.
void removeFieldFormatter(QgsFieldFormatter *formatter)
Remove a field formatter from the registry.
Field formatter for a list field.
A default fallback field formatter in case no specialized field formatter is defined.
virtual QString id() const =0
Returns a unique id for this field formatter.
void addFieldFormatter(QgsFieldFormatter *formatter)
They will take precedence in order of adding them.
Field formatter for a checkbox field.
void fieldFormatterAdded(QgsFieldFormatter *formatter)
Will be emitted after a new field formatter has been added.
Field formatter for a value relation field.
QgsFieldFormatter * fieldFormatter(const QString &id) const
Gets a field formatter by its id.
void fieldFormatterRemoved(QgsFieldFormatter *formatter)
Will be emitted just before a field formatter is removed and deleted.
A field formatter helps to handle and display values for a field.
QgsFieldFormatterRegistry(QObject *parent=nullptr)
You should not normally need to create your own field formatter registry.
Field formatter for a relation reference field.
Field formatter for a date time field.
QgsFieldFormatter * fallbackFieldFormatter() const
Returns a basic fallback field formatter which can be used to represent any field in an unspectacular...
Field formatter for a range (double) field with precision and locale.