QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 QgsGeographicCoordinateNumericFormatConfigurationWidgetFactory : public QgsNumericFormatConfigurationWidgetFactory
44 {
45  public:
46 
47  QgsNumericFormatWidget *create( const QgsNumericFormat *format ) const
48  {
49  return new QgsGeographicCoordinateNumericFormatWidget( format );
50  }
51 };
52 
53 class QgsCurrencyNumericFormatConfigurationWidgetFactory : public QgsNumericFormatConfigurationWidgetFactory
54 {
55  public:
56 
57  QgsNumericFormatWidget *create( const QgsNumericFormat *format ) const
58  {
59  return new QgsCurrencyNumericFormatWidget( format );
60  }
61 };
62 
63 class QgsPercentageNumericFormatConfigurationWidgetFactory : public QgsNumericFormatConfigurationWidgetFactory
64 {
65  public:
66 
67  QgsNumericFormatWidget *create( const QgsNumericFormat *format ) const
68  {
69  return new QgsPercentageNumericFormatWidget( format );
70  }
71 };
72 
73 class QgsScientificNumericFormatConfigurationWidgetFactory : public QgsNumericFormatConfigurationWidgetFactory
74 {
75  public:
76 
77  QgsNumericFormatWidget *create( const QgsNumericFormat *format ) const
78  {
79  return new QgsScientificNumericFormatWidget( format );
80  }
81 };
82 
83 class QgsFractionNumericFormatConfigurationWidgetFactory : public QgsNumericFormatConfigurationWidgetFactory
84 {
85  public:
86 
87  QgsNumericFormatWidget *create( const QgsNumericFormat *format ) const
88  {
89  return new QgsFractionNumericFormatWidget( format );
90  }
91 };
93 
95 {
96  addFormatConfigurationWidgetFactory( QStringLiteral( "basic" ), new QgsBasicNumericFormatConfigurationWidgetFactory() );
97  addFormatConfigurationWidgetFactory( QStringLiteral( "bearing" ), new QgsBearingNumericFormatConfigurationWidgetFactory() );
98  addFormatConfigurationWidgetFactory( QStringLiteral( "currency" ), new QgsCurrencyNumericFormatConfigurationWidgetFactory() );
99  addFormatConfigurationWidgetFactory( QStringLiteral( "percentage" ), new QgsPercentageNumericFormatConfigurationWidgetFactory() );
100  addFormatConfigurationWidgetFactory( QStringLiteral( "scientific" ), new QgsScientificNumericFormatConfigurationWidgetFactory() );
101  addFormatConfigurationWidgetFactory( QStringLiteral( "fraction" ), new QgsFractionNumericFormatConfigurationWidgetFactory() );
102  addFormatConfigurationWidgetFactory( QStringLiteral( "geographiccoordinate" ), new QgsGeographicCoordinateNumericFormatConfigurationWidgetFactory() );
103 }
104 
106 {
107  qDeleteAll( mFormatConfigurationWidgetFactories );
108 }
109 
111 {
112  mFormatConfigurationWidgetFactories.insert( id, factory );
113 }
114 
116 {
117  delete mFormatConfigurationWidgetFactories.value( id );
118  mFormatConfigurationWidgetFactories.remove( id );
119 }
120 
122 {
123  if ( !format )
124  return nullptr;
125 
126  if ( !mFormatConfigurationWidgetFactories.contains( format->id() ) )
127  return nullptr;
128 
129  return mFormatConfigurationWidgetFactories.value( format->id() )->create( format );
130 }
QgsNumericFormatGuiRegistry::~QgsNumericFormatGuiRegistry
~QgsNumericFormatGuiRegistry()
Definition: qgsnumericformatguiregistry.cpp:105
qgis.h
QgsNumericFormatGuiRegistry::QgsNumericFormatGuiRegistry
QgsNumericFormatGuiRegistry()
Constructor.
Definition: qgsnumericformatguiregistry.cpp:94
QgsNumericFormat
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
Definition: qgsnumericformat.h:259
QgsNumericFormatWidget
Base class for widgets which allow control over the properties of QgsNumericFormat subclasses.
Definition: qgsnumericformatwidget.h:32
QgsNumericFormatGuiRegistry::removeFormatConfigurationWidgetFactory
void removeFormatConfigurationWidgetFactory(const QString &id)
Removes the configuration widget factory for customizing numeric formats with the specified id.
Definition: qgsnumericformatguiregistry.cpp:115
QgsPercentageNumericFormatWidget
A widget which allow control over the properties of a QgsPercentageNumericFormat.
Definition: qgsnumericformatwidget.h:272
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:80
QgsGeographicCoordinateNumericFormatWidget
A widget which allow control over the properties of a QgsGeographicCoordinateNumericFormat.
Definition: qgsnumericformatwidget.h:175
qgsnumericformatguiregistry.h
QgsBearingNumericFormatWidget
A widget which allow control over the properties of a QgsBearingNumericFormat.
Definition: qgsnumericformatwidget.h:112
QgsFractionNumericFormatWidget
A widget which allow control over the properties of a QgsFractionNumericFormat.
Definition: qgsnumericformatwidget.h:337
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:121
qgsnumericformatwidget.h
QgsScientificNumericFormatWidget
A widget which allow control over the properties of a QgsScientificNumericFormat.
Definition: qgsnumericformatwidget.h:306
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:110
QgsCurrencyNumericFormatWidget
A widget which allow control over the properties of a QgsCurrencyNumericFormat.
Definition: qgsnumericformatwidget.h:239
QgsNumericFormatConfigurationWidgetFactory
Interface base class for factories for numeric format configuration widgets.
Definition: qgsnumericformatguiregistry.h:35