QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgsplotregistry.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsplotregistry.h
3 -----------------
4 begin : June 2025
5 copyright : (C) 2025 by Mathieu Pellerin
6 email : mathieu at opengis dot ch
7 ***************************************************************************/
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#ifndef QGSPLOTREGISTRY_H
17#define QGSPLOTREGISTRY_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgsapplication.h"
22#include "qgsplot.h"
24
26
35class CORE_EXPORT QgsPlotAbstractMetadata
36{
37 public:
38
42 QgsPlotAbstractMetadata( const QString &type, const QString &visibleName )
43 : mType( type )
44 , mVisibleName( visibleName )
45 {}
46
47 virtual ~QgsPlotAbstractMetadata() = default;
48
52 QString type() const { return mType; }
53
57 QString visibleName() const { return mVisibleName; }
58
59 /*
60 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
61 * the case.
62 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
63 *
64 * "
65 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
66 * In this case it isn't because it has already been seen when being returned by createPlot()
67 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
68 * by Python so the /Factory/ on create() would be correct.)
69 *
70 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
71 * "
72 */
73
78
83
89 virtual QgsPlotWidget *createPlotWidget( QWidget *parent = nullptr ) = 0 SIP_TRANSFERBACK;
90
91 private:
92
93 QString mType;
94 QString mVisibleName;
95};
96
98typedef std::function<QgsPlot *()> QgsPlotCreateFunc SIP_SKIP;
100typedef std::function<QgsPlotWidget *( QWidget *parent )> QgsPlotWidgetCreateFunc SIP_SKIP;
101
102#ifndef SIP_RUN
103
111class CORE_EXPORT QgsPlotMetadata : public QgsPlotAbstractMetadata
112{
113 public:
114
118 QgsPlotMetadata( const QString &type, const QString &visibleName,
119 const QgsPlotCreateFunc &pfCreate,
120 const QgsPlotDataGathererCreateFunc &pdgfCreate = nullptr,
121 const QgsPlotWidgetCreateFunc &pwfCreate = nullptr )
123 , mCreateFunc( pfCreate )
124 , mDataGathererCreateFunc( pdgfCreate )
125 , mWidgetCreateFunc( pwfCreate )
126 {}
127
132
137
142
146 void setWidgetCreateFunction( QgsPlotWidgetCreateFunc function ) SIP_SKIP { mWidgetCreateFunc = std::move( function ); }
147
148 QgsPlot *createPlot() override { return mCreateFunc ? mCreateFunc() : nullptr; }
150 QgsPlotWidget *createPlotWidget( QWidget *parent = nullptr ) override { return mWidgetCreateFunc ? mWidgetCreateFunc( parent ) : nullptr; }
151
152 protected:
156
157};
158
159#endif
160
171class CORE_EXPORT QgsPlotRegistry : public QObject
172{
173 Q_OBJECT
174
175 public:
176
185 QgsPlotRegistry( QObject *parent = nullptr );
186 ~QgsPlotRegistry() override;
187
192 bool populate();
193
194 QgsPlotRegistry( const QgsPlotRegistry &rh ) = delete;
196
201 QgsPlotAbstractMetadata *plotMetadata( const QString &type ) const;
202
208
212 bool removePlotType( const QString &type );
213
214 /*
215 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
216 * the case.
217 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
218 *
219 * "
220 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
221 * In this case it isn't because it has already been seen when being returned by createPlot()
222 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
223 * by Python so the /Factory/ on create() would be correct.)
224 *
225 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
226 * "
227 */
228
232 QgsPlot *createPlot( const QString &type ) const SIP_TRANSFERBACK;
233
237 QMap<QString, QString> plotTypes() const;
238
239 signals:
240
245 void plotAdded( const QString &type, const QString &name );
246
251 void plotAboutToBeRemoved( const QString &type );
252
253 private:
254
255#ifdef SIP_RUN
256 QgsPlotRegistry( const QgsPlotRegistry &rh );
257#endif
258
259 QMap<QString, QgsPlotAbstractMetadata *> mMetadata;
260
261};
262
263#endif //QGSPLOTREGISTRY_H
264
265
266
Stores metadata about a plot class.
QgsPlotAbstractMetadata(const QString &type, const QString &visibleName)
Constructor for QgsPlotAbstractMetadata with the specified class type.
QString visibleName() const
Returns a translated, user visible name for the plot class.
QString type() const
Returns the unique type code for the plot class.
virtual ~QgsPlotAbstractMetadata()=default
virtual QgsPlotWidget * createPlotWidget(QWidget *parent=nullptr)=0
Creates a widget for configuring plot of this type.
virtual QgsVectorLayerAbstractPlotDataGatherer * createPlotDataGatherer(QgsPlot *plot=nullptr)=0
Creates a plot data gatherer of this class.
virtual QgsPlot * createPlot()=0
Creates a plot of this class.
QgsPlotWidget * createPlotWidget(QWidget *parent=nullptr) override
Creates a widget for configuring plot of this type.
void setWidgetCreateFunction(QgsPlotWidgetCreateFunc function)
Sets the classes' plot widget creation function.
QgsPlotCreateFunc mCreateFunc
QgsPlotDataGathererCreateFunc mDataGathererCreateFunc
QgsPlotWidgetCreateFunc mWidgetCreateFunc
QgsPlotCreateFunc createFunction() const
Returns the classes' plot creation function.
QgsPlotDataGathererCreateFunc createPlotDataGathererFunction() const
Returns the classes' plot data gatherer creation function.
QgsPlot * createPlot() override
Creates a plot of this class.
QgsVectorLayerAbstractPlotDataGatherer * createPlotDataGatherer(QgsPlot *plot=nullptr) override
Creates a plot data gatherer of this class.
QgsPlotMetadata(const QString &type, const QString &visibleName, const QgsPlotCreateFunc &pfCreate, const QgsPlotDataGathererCreateFunc &pdgfCreate=nullptr, const QgsPlotWidgetCreateFunc &pwfCreate=nullptr)
Constructor for QgsPlotMetadata with the specified class type.
QgsPlotWidgetCreateFunc widgetCreateFunction() const
Returns the classes' plot widget creation function.
QgsPlot * createPlot(const QString &type) const
Creates a new instance of a plot given the type.
QMap< QString, QString > plotTypes() const
Returns a map of available plot types to translated name.
bool removePlotType(const QString &type)
Removes a new a plot type from the registry.
QgsPlotRegistry(QObject *parent=nullptr)
Creates a new empty plot registry.
bool addPlotType(QgsPlotAbstractMetadata *metadata)
Registers a new plot type.
void plotAdded(const QString &type, const QString &name)
Emitted whenever a new plot type is added to the registry, with the specified type and visible name.
QgsPlotRegistry(const QgsPlotRegistry &rh)=delete
bool populate()
Populates the registry with standard plot types.
QgsPlotAbstractMetadata * plotMetadata(const QString &type) const
Returns the metadata for the specified plot type.
QgsPlotRegistry & operator=(const QgsPlotRegistry &rh)=delete
void plotAboutToBeRemoved(const QString &type)
Emitted whenever a plot type is about to be remove from the registry, with the specified type and vis...
Base class for widgets which allow control over the properties of plots.
Base class for plot/chart/graphs.
Definition qgsplot.h:48
An abstract vector layer plot data gatherer base class.
#define SIP_EXTERNAL
Definition qgis_sip.h:124
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_TRANSFERBACK
Definition qgis_sip.h:48
std::function< QgsVectorLayerAbstractPlotDataGatherer *(QgsPlot *plot)> QgsPlotDataGathererCreateFunc
std::function< QgsPlot *()> QgsPlotCreateFunc
Plot creation function.
std::function< QgsPlotWidget *(QWidget *parent)> QgsPlotWidgetCreateFunc