QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgsplot.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsplot.h
3 ---------------
4 begin : March 2022
5 copyright : (C) 2022 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#ifndef QGSPLOT_H
18#define QGSPLOT_H
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
22#include "qgstextformat.h"
23#include "qgsmargins.h"
24
25#include <QSizeF>
26#include <memory>
27
28class QgsLineSymbol;
29class QgsFillSymbol;
32
33
43class CORE_EXPORT QgsPlot
44{
45 public:
46
50 QgsPlot() = default;
51
52 virtual ~QgsPlot();
53
57 virtual bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
58
62 virtual bool readXml( const QDomElement &element, const QgsReadWriteContext &context );
63
64 private:
65
66
67};
68
77class CORE_EXPORT QgsPlotAxis
78{
79 public:
80
83
85 QgsPlotAxis( const QgsPlotAxis &other ) = delete;
87 QgsPlotAxis &operator=( const QgsPlotAxis &other ) = delete;
88
92 bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
93
97 bool readXml( const QDomElement &element, const QgsReadWriteContext &context );
98
104 double gridIntervalMinor() const { return mGridIntervalMinor; }
105
111 void setGridIntervalMinor( double interval ) { mGridIntervalMinor = interval; }
112
118 double gridIntervalMajor() const { return mGridIntervalMajor; }
119
125 void setGridIntervalMajor( double interval ) { mGridIntervalMajor = interval; }
126
132 double labelInterval() const { return mLabelInterval; }
133
139 void setLabelInterval( double interval ) { mLabelInterval = interval; }
140
146 QgsLineSymbol *gridMajorSymbol();
147
155 void setGridMajorSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
156
162 QgsLineSymbol *gridMinorSymbol();
163
171 void setGridMinorSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
172
178 QgsTextFormat textFormat() const;
179
185 void setTextFormat( const QgsTextFormat &format );
186
192 QgsNumericFormat *numericFormat() const;
193
201 void setNumericFormat( QgsNumericFormat *format SIP_TRANSFER );
202
203 private:
204
205#ifdef SIP_RUN
206 QgsPlotAxis( const QgsPlotAxis &other );
207#endif
208
209 double mGridIntervalMinor = 1;
210 double mGridIntervalMajor = 5;
211
212 double mLabelInterval = 1;
213
214 std::unique_ptr< QgsNumericFormat > mNumericFormat;
215
216 std::unique_ptr< QgsLineSymbol > mGridMajorSymbol;
217 std::unique_ptr< QgsLineSymbol > mGridMinorSymbol;
218
219 QgsTextFormat mLabelTextFormat;
220
221};
222
234class CORE_EXPORT Qgs2DPlot : public QgsPlot
235{
236 public:
237
241 Qgs2DPlot();
242
243 ~Qgs2DPlot() override;
244
246 Qgs2DPlot( const Qgs2DPlot &other ) = delete;
248 Qgs2DPlot &operator=( const Qgs2DPlot &other ) = delete;
249
250 bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
251 bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) override;
252
256 void render( QgsRenderContext &context );
257
269 virtual void renderContent( QgsRenderContext &context, const QRectF &plotArea );
270
276 QSizeF size() const;
277
283 void setSize( QSizeF size );
284
289 QRectF interiorPlotArea( QgsRenderContext &context ) const;
290
298 void calculateOptimisedIntervals( QgsRenderContext &context );
299
305 double xMinimum() const { return mMinX; }
306
312 void setXMinimum( double minimum ) { mMinX = minimum; }
313
319 double yMinimum() const { return mMinY; }
320
326 void setYMinimum( double minimum ) { mMinY = minimum; }
327
333 double xMaximum() const { return mMaxX; }
334
340 void setXMaximum( double maximum ) { mMaxX = maximum; }
341
347 double yMaximum() const { return mMaxY; }
348
354 void setYMaximum( double maximum ) { mMaxY = maximum; }
355
361 QgsPlotAxis &xAxis() { return mXAxis; }
362
368 const QgsPlotAxis &xAxis() const SIP_SKIP { return mXAxis; }
369
375 QgsPlotAxis &yAxis() { return mYAxis; }
376
382 const QgsPlotAxis &yAxis() const SIP_SKIP { return mYAxis; }
383
389 QgsFillSymbol *chartBackgroundSymbol();
390
398 void setChartBackgroundSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
399
405 QgsFillSymbol *chartBorderSymbol();
406
414 void setChartBorderSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
415
421 const QgsMargins &margins() const;
422
428 void setMargins( const QgsMargins &margins );
429
430 private:
431
432#ifdef SIP_RUN
433 Qgs2DPlot( const Qgs2DPlot &other );
434#endif
435
436 QSizeF mSize;
437
438 double mMinX = 0;
439 double mMinY = 0;
440 double mMaxX = 10;
441 double mMaxY = 10;
442
443 std::unique_ptr< QgsFillSymbol > mChartBackgroundSymbol;
444 std::unique_ptr< QgsFillSymbol > mChartBorderSymbol;
445
446 QgsMargins mMargins;
447
448 QgsPlotAxis mXAxis;
449 QgsPlotAxis mYAxis;
450};
451
460class CORE_EXPORT QgsPlotDefaultSettings
461{
462 public:
463
467 static QgsNumericFormat *axisLabelNumericFormat() SIP_FACTORY;
468
474 static QgsLineSymbol *axisGridMajorSymbol() SIP_FACTORY;
475
481 static QgsLineSymbol *axisGridMinorSymbol() SIP_FACTORY;
482
488 static QgsFillSymbol *chartBackgroundSymbol() SIP_FACTORY;
489
495 static QgsFillSymbol *chartBorderSymbol() SIP_FACTORY;
496
497};
498
499#endif // QGSPLOT_H
Base class for 2-dimensional plot/chart/graphs.
Definition: qgsplot.h:235
double yMaximum() const
Returns the maximum value of the y axis.
Definition: qgsplot.h:347
QgsPlotAxis & xAxis()
Returns a reference to the plot's x axis.
Definition: qgsplot.h:361
void setXMinimum(double minimum)
Sets the minimum value of the x axis.
Definition: qgsplot.h:312
const QgsPlotAxis & xAxis() const
Returns a reference to the plot's x axis.
Definition: qgsplot.h:368
Qgs2DPlot & operator=(const Qgs2DPlot &other)=delete
Qgs2DPlot cannot be copied.
~Qgs2DPlot() override
double xMaximum() const
Returns the maximum value of the x axis.
Definition: qgsplot.h:333
void setYMaximum(double maximum)
Sets the maximum value of the y axis.
Definition: qgsplot.h:354
double xMinimum() const
Returns the minimum value of the x axis.
Definition: qgsplot.h:305
QgsPlotAxis & yAxis()
Returns a reference to the plot's y axis.
Definition: qgsplot.h:375
double yMinimum() const
Returns the minimum value of the y axis.
Definition: qgsplot.h:319
Qgs2DPlot(const Qgs2DPlot &other)=delete
Qgs2DPlot cannot be copied.
const QgsPlotAxis & yAxis() const
Returns a reference to the plot's y axis.
Definition: qgsplot.h:382
void setXMaximum(double maximum)
Sets the maximum value of the x axis.
Definition: qgsplot.h:340
void setYMinimum(double minimum)
Sets the minimum value of the y axis.
Definition: qgsplot.h:326
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:30
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:30
The QgsMargins class defines the four margins of a rectangle.
Definition: qgsmargins.h:38
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
Encapsulates the properties of a plot axis.
Definition: qgsplot.h:78
double gridIntervalMinor() const
Returns the interval of minor grid lines for the axis.
Definition: qgsplot.h:104
double gridIntervalMajor() const
Returns the interval of major grid lines for the axis.
Definition: qgsplot.h:118
void setGridIntervalMajor(double interval)
Sets the interval of major grid lines for the axis.
Definition: qgsplot.h:125
void setGridIntervalMinor(double interval)
Sets the interval of minor grid lines for the axis.
Definition: qgsplot.h:111
void setLabelInterval(double interval)
Sets the interval of labels for the axis.
Definition: qgsplot.h:139
double labelInterval() const
Returns the interval of labels for the axis.
Definition: qgsplot.h:132
QgsPlotAxis & operator=(const QgsPlotAxis &other)=delete
QgsPlotAxis cannot be copied.
QgsPlotAxis(const QgsPlotAxis &other)=delete
QgsPlotAxis cannot be copied.
Manages default settings for plot objects.
Definition: qgsplot.h:461
Base class for plot/chart/graphs.
Definition: qgsplot.h:44
QgsPlot()=default
Constructor for QgsPlot.
virtual ~QgsPlot()
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
Container for all settings relating to text rendering.
Definition: qgstextformat.h:41
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76