QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
41 QgsPlotAbstractMetadata( const QString &type, const QString &visibleName )
42 : mType( type )
43 , mVisibleName( visibleName )
44 {}
45
46 virtual ~QgsPlotAbstractMetadata() = default;
47
51 QString type() const { return mType; }
52
56 QString visibleName() const { return mVisibleName; }
57
58 /*
59 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
60 * the case.
61 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
62 *
63 * "
64 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
65 * In this case it isn't because it has already been seen when being returned by createPlot()
66 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
67 * by Python so the /Factory/ on create() would be correct.)
68 *
69 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
70 * "
71 */
72
77
82
88 virtual QgsPlotWidget *createPlotWidget( QWidget *parent = nullptr ) = 0 SIP_TRANSFERBACK;
89
90 private:
91 QString mType;
92 QString mVisibleName;
93};
94
96typedef std::function<QgsPlot *()> QgsPlotCreateFunc SIP_SKIP;
98typedef std::function<QgsPlotWidget *( QWidget *parent )> QgsPlotWidgetCreateFunc SIP_SKIP;
99
100#ifndef SIP_RUN
101
109class CORE_EXPORT QgsPlotMetadata : public QgsPlotAbstractMetadata
110{
111 public:
116 const QString &type, const QString &visibleName, const QgsPlotCreateFunc &pfCreate, const QgsPlotDataGathererCreateFunc &pdgfCreate = nullptr, const QgsPlotWidgetCreateFunc &pwfCreate = nullptr
117 )
119 , mCreateFunc( pfCreate )
120 , mDataGathererCreateFunc( pdgfCreate )
121 , mWidgetCreateFunc( pwfCreate )
122 {}
123
128
133
138
142 void setWidgetCreateFunction( QgsPlotWidgetCreateFunc function ) SIP_SKIP { mWidgetCreateFunc = std::move( function ); }
143
144 QgsPlot *createPlot() override { return mCreateFunc ? mCreateFunc() : nullptr; }
146 QgsPlotWidget *createPlotWidget( QWidget *parent = nullptr ) override { return mWidgetCreateFunc ? mWidgetCreateFunc( parent ) : nullptr; }
147
148 protected:
152};
153
154#endif
155
166class CORE_EXPORT QgsPlotRegistry : public QObject
167{
168 Q_OBJECT
169
170 public:
179 QgsPlotRegistry( QObject *parent = nullptr );
180 ~QgsPlotRegistry() override;
181
186 bool populate();
187
188 QgsPlotRegistry( const QgsPlotRegistry &rh ) = delete;
190
195 QgsPlotAbstractMetadata *plotMetadata( const QString &type ) const;
196
202
206 bool removePlotType( const QString &type );
207
208 /*
209 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
210 * the case.
211 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
212 *
213 * "
214 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
215 * In this case it isn't because it has already been seen when being returned by createPlot()
216 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
217 * by Python so the /Factory/ on create() would be correct.)
218 *
219 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
220 * "
221 */
222
226 QgsPlot *createPlot( const QString &type ) const SIP_TRANSFERBACK;
227
231 QMap<QString, QString> plotTypes() const;
232
233 signals:
234
239 void plotAdded( const QString &type, const QString &name );
240
245 void plotAboutToBeRemoved( const QString &type );
246
247 private:
248#ifdef SIP_RUN
249 QgsPlotRegistry( const QgsPlotRegistry &rh );
250#endif
251
252 QMap<QString, QgsPlotAbstractMetadata *> mMetadata;
253};
254
255#endif //QGSPLOTREGISTRY_H
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:123
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_TRANSFERBACK
Definition qgis_sip.h:47
std::function< QgsVectorLayerAbstractPlotDataGatherer *(QgsPlot *plot)> QgsPlotDataGathererCreateFunc
std::function< QgsPlot *()> QgsPlotCreateFunc
Plot creation function.
std::function< QgsPlotWidget *(QWidget *parent)> QgsPlotWidgetCreateFunc