QGIS API Documentation  3.21.0-Master (909859188c)
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 }
A widget which allow control over the properties of a QgsBasicNumericFormat.
A widget which allow control over the properties of a QgsBearingNumericFormat.
A widget which allow control over the properties of a QgsCurrencyNumericFormat.
A widget which allow control over the properties of a QgsFractionNumericFormat.
Interface base class for factories for numeric format configuration widgets.
virtual QgsNumericFormatWidget * create(const QgsNumericFormat *format) const =0
Create a new configuration widget for a format.
QgsNumericFormatWidget * formatConfigurationWidget(const QgsNumericFormat *format) const
Returns a new configuration widget for an format.
void addFormatConfigurationWidgetFactory(const QString &id, QgsNumericFormatConfigurationWidgetFactory *factory)
Add a new configuration widget factory for customizing a numeric format with the specified id.
void removeFormatConfigurationWidgetFactory(const QString &id)
Removes the configuration widget factory for customizing numeric formats with the specified id.
Base class for widgets which allow control over the properties of QgsNumericFormat subclasses.
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
virtual QString id() const =0
Returns a unique id for this numeric format.
A widget which allow control over the properties of a QgsPercentageNumericFormat.
A widget which allow control over the properties of a QgsScientificNumericFormat.