QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsnumericformatguiregistry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsnumericformatguiregistry.cpp
3  -------------------------------
4  begin : January 2020
5  copyright : (C) 2020 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 #include "qgis.h"
20 #include "qgsnumericformatwidget.h"
21 
23 class QgsBasicNumericFormatConfigurationWidgetFactory : public QgsNumericFormatConfigurationWidgetFactory
24 {
25  public:
26 
27  QgsNumericFormatWidget *create( const QgsNumericFormat *format ) const
28  {
29  return new QgsBasicNumericFormatWidget( format );
30  }
31 };
32 
33 class QgsBearingNumericFormatConfigurationWidgetFactory : public QgsNumericFormatConfigurationWidgetFactory
34 {
35  public:
36 
37  QgsNumericFormatWidget *create( const QgsNumericFormat *format ) const
38  {
39  return new QgsBearingNumericFormatWidget( format );
40  }
41 };
42 
43 class QgsCurrencyNumericFormatConfigurationWidgetFactory : public QgsNumericFormatConfigurationWidgetFactory
44 {
45  public:
46 
47  QgsNumericFormatWidget *create( const QgsNumericFormat *format ) const
48  {
49  return new QgsCurrencyNumericFormatWidget( format );
50  }
51 };
52 
53 class QgsPercentageNumericFormatConfigurationWidgetFactory : public QgsNumericFormatConfigurationWidgetFactory
54 {
55  public:
56 
57  QgsNumericFormatWidget *create( const QgsNumericFormat *format ) const
58  {
59  return new QgsPercentageNumericFormatWidget( format );
60  }
61 };
62 
63 class QgsScientificNumericFormatConfigurationWidgetFactory : public QgsNumericFormatConfigurationWidgetFactory
64 {
65  public:
66 
67  QgsNumericFormatWidget *create( const QgsNumericFormat *format ) const
68  {
69  return new QgsScientificNumericFormatWidget( format );
70  }
71 };
72 
73 class QgsFractionNumericFormatConfigurationWidgetFactory : public QgsNumericFormatConfigurationWidgetFactory
74 {
75  public:
76 
77  QgsNumericFormatWidget *create( const QgsNumericFormat *format ) const
78  {
79  return new QgsFractionNumericFormatWidget( format );
80  }
81 };
83 
85 {
86  addFormatConfigurationWidgetFactory( QStringLiteral( "basic" ), new QgsBasicNumericFormatConfigurationWidgetFactory() );
87  addFormatConfigurationWidgetFactory( QStringLiteral( "bearing" ), new QgsBearingNumericFormatConfigurationWidgetFactory() );
88  addFormatConfigurationWidgetFactory( QStringLiteral( "currency" ), new QgsCurrencyNumericFormatConfigurationWidgetFactory() );
89  addFormatConfigurationWidgetFactory( QStringLiteral( "percentage" ), new QgsPercentageNumericFormatConfigurationWidgetFactory() );
90  addFormatConfigurationWidgetFactory( QStringLiteral( "scientific" ), new QgsScientificNumericFormatConfigurationWidgetFactory() );
91  addFormatConfigurationWidgetFactory( QStringLiteral( "fraction" ), new QgsFractionNumericFormatConfigurationWidgetFactory() );
92 }
93 
95 {
96  qDeleteAll( mFormatConfigurationWidgetFactories );
97 }
98 
100 {
101  mFormatConfigurationWidgetFactories.insert( id, factory );
102 }
103 
105 {
106  delete mFormatConfigurationWidgetFactories.value( id );
107  mFormatConfigurationWidgetFactories.remove( id );
108 }
109 
111 {
112  if ( !format )
113  return nullptr;
114 
115  if ( !mFormatConfigurationWidgetFactories.contains( format->id() ) )
116  return nullptr;
117 
118  return mFormatConfigurationWidgetFactories.value( format->id() )->create( format );
119 }
QgsNumericFormatGuiRegistry::~QgsNumericFormatGuiRegistry
~QgsNumericFormatGuiRegistry()
Definition: qgsnumericformatguiregistry.cpp:94
qgis.h
QgsNumericFormatGuiRegistry::QgsNumericFormatGuiRegistry
QgsNumericFormatGuiRegistry()
Constructor.
Definition: qgsnumericformatguiregistry.cpp:84
QgsNumericFormat
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
Definition: qgsnumericformat.h:218
QgsNumericFormatWidget
Base class for widgets which allow control over the properties of QgsNumericFormat subclasses.
Definition: qgsnumericformatwidget.h:33
QgsNumericFormatGuiRegistry::removeFormatConfigurationWidgetFactory
void removeFormatConfigurationWidgetFactory(const QString &id)
Removes the configuration widget factory for customizing numeric formats with the specified id.
Definition: qgsnumericformatguiregistry.cpp:104
QgsPercentageNumericFormatWidget
A widget which allow control over the properties of a QgsPercentageNumericFormat.
Definition: qgsnumericformatwidget.h:211
QgsNumericFormat::id
virtual QString id() const =0
Returns a unique id for this numeric format.
QgsBasicNumericFormatWidget
A widget which allow control over the properties of a QgsBasicNumericFormat.
Definition: qgsnumericformatwidget.h:81
qgsnumericformatguiregistry.h
QgsBearingNumericFormatWidget
A widget which allow control over the properties of a QgsBearingNumericFormat.
Definition: qgsnumericformatwidget.h:113
QgsFractionNumericFormatWidget
A widget which allow control over the properties of a QgsFractionNumericFormat.
Definition: qgsnumericformatwidget.h:276
QgsNumericFormatConfigurationWidgetFactory::create
virtual QgsNumericFormatWidget * create(const QgsNumericFormat *format) const =0
Create a new configuration widget for a format.
QgsNumericFormatGuiRegistry::formatConfigurationWidget
QgsNumericFormatWidget * formatConfigurationWidget(const QgsNumericFormat *format) const
Returns a new configuration widget for an format.
Definition: qgsnumericformatguiregistry.cpp:110
qgsnumericformatwidget.h
QgsScientificNumericFormatWidget
A widget which allow control over the properties of a QgsScientificNumericFormat.
Definition: qgsnumericformatwidget.h:245
QgsNumericFormatGuiRegistry::addFormatConfigurationWidgetFactory
void addFormatConfigurationWidgetFactory(const QString &id, QgsNumericFormatConfigurationWidgetFactory *factory)
Add a new configuration widget factory for customizing a numeric format with the specified id.
Definition: qgsnumericformatguiregistry.cpp:99
QgsCurrencyNumericFormatWidget
A widget which allow control over the properties of a QgsCurrencyNumericFormat.
Definition: qgsnumericformatwidget.h:178
QgsNumericFormatConfigurationWidgetFactory
Interface base class for factories for numeric format configuration widgets.
Definition: qgsnumericformatguiregistry.h:36