QGIS API Documentation 3.27.0-Master (1d7a28cfd2)
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, QgsReadWriteContext &context ) const;
58
62 virtual bool readXml( const QDomElement &element, 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, QgsReadWriteContext &context ) const;
93
97 bool readXml( const QDomElement &element, 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, QgsReadWriteContext &context ) const override;
251 bool readXml( const QDomElement &element, 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
377
383 const QgsPlotAxis &yAxis() const SIP_SKIP { return mYAxis; }
384
390 QgsFillSymbol *chartBackgroundSymbol();
391
399 void setChartBackgroundSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
400
406 QgsFillSymbol *chartBorderSymbol();
407
415 void setChartBorderSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
416
422 const QgsMargins &margins() const;
423
429 void setMargins( const QgsMargins &margins );
430
431 private:
432
433#ifdef SIP_RUN
434 Qgs2DPlot( const Qgs2DPlot &other );
435#endif
436
437 QSizeF mSize;
438
439 double mMinX = 0;
440 double mMinY = 0;
441 double mMaxX = 10;
442 double mMaxY = 10;
443
444 std::unique_ptr< QgsFillSymbol > mChartBackgroundSymbol;
445 std::unique_ptr< QgsFillSymbol > mChartBorderSymbol;
446
447 QgsMargins mMargins;
448
449 QgsPlotAxis mXAxis;
450 QgsPlotAxis mYAxis;
451};
452
453#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:383
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.
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