QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgsplotregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsplotregistry.cpp
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
17#include "qgsconfig.h"
18#include "qgsplotregistry.h"
19
20#include "qgsbarchartplot.h"
21#include "qgslinechartplot.h"
22#include "qgspiechartplot.h"
23#include "qgsplot.h"
24
25#include "moc_qgsplotregistry.cpp"
26
28 : QObject( parent )
29{
30}
31
33{
34 qDeleteAll( mMetadata );
35}
36
38{
39 if ( !mMetadata.isEmpty() )
40 return false;
41
42 addPlotType( new QgsPlotMetadata( QLatin1String( "bar" ), QObject::tr( "Bar chart" ), QgsBarChartPlot::create, QgsBarChartPlot::createDataGatherer ) );
43 addPlotType( new QgsPlotMetadata( QLatin1String( "line" ), QObject::tr( "Line chart" ), QgsLineChartPlot::create, QgsLineChartPlot::createDataGatherer ) );
44 addPlotType( new QgsPlotMetadata( QLatin1String( "pie" ), QObject::tr( "Pie chart" ), QgsPieChartPlot::create, QgsPieChartPlot::createDataGatherer ) );
45
46 return true;
47}
48
50{
51 return mMetadata.value( type );
52}
53
55{
56 if ( !metadata || mMetadata.contains( metadata->type() ) )
57 return false;
58
59 mMetadata[metadata->type()] = metadata;
60 emit plotAdded( metadata->type(), metadata->visibleName() );
61 return true;
62}
63
64bool QgsPlotRegistry::removePlotType( const QString &type )
65{
66 if ( !mMetadata.contains( type ) )
67 return false;
68
69 emit plotAboutToBeRemoved( type );
70 delete mMetadata.take( type );
71 return true;
72}
73
74QgsPlot *QgsPlotRegistry::createPlot( const QString &type ) const
75{
76 if ( !mMetadata.contains( type ) )
77 return nullptr;
78
79 return mMetadata[type]->createPlot();
80}
81
82QMap<QString, QString> QgsPlotRegistry::plotTypes() const
83{
84 QMap<QString, QString> types;
85 for ( auto it = mMetadata.constBegin(); it != mMetadata.constEnd(); ++it )
86 {
87 types.insert( it.key(), it.value()->visibleName() );
88 }
89
90 return types;
91}
static QgsVectorLayerAbstractPlotDataGatherer * createDataGatherer(QgsPlot *plot)
Returns a new data gatherer for a given bar chart plot.
static QgsBarChartPlot * create()
Returns a new bar chart.
static QgsVectorLayerAbstractPlotDataGatherer * createDataGatherer(QgsPlot *plot)
Returns a new data gatherer for a given line chart plot.
static QgsLineChartPlot * create()
Returns a new line chart.
static QgsPieChartPlot * create()
Returns a new pie chart.
static QgsVectorLayerAbstractPlotDataGatherer * createDataGatherer(QgsPlot *plot)
Returns a new data gatherer for a given pie chart plot.
Stores metadata about a plot class.
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.
Convenience metadata class that uses static functions to create plots.
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.
bool populate()
Populates the registry with standard plot types.
~QgsPlotRegistry() override
QgsPlotAbstractMetadata * plotMetadata(const QString &type) const
Returns the metadata for the specified plot type.
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 plot/chart/graphs.
Definition qgsplot.h:48