QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
28 class QgsLineSymbol;
29 class QgsFillSymbol;
30 class QgsRenderContext;
31 class QgsNumericFormat;
32 
33 
43 class 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 
77 class CORE_EXPORT QgsPlotAxis
78 {
79  public:
80 
81  QgsPlotAxis();
82  ~QgsPlotAxis();
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 
234 class 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
QgsPlotAxis::gridIntervalMajor
double gridIntervalMajor() const
Returns the interval of major grid lines for the axis.
Definition: qgsplot.h:118
Qgs2DPlot::setYMinimum
void setYMinimum(double minimum)
Sets the minimum value of the y axis.
Definition: qgsplot.h:326
Qgs2DPlot::setXMinimum
void setXMinimum(double minimum)
Sets the minimum value of the x axis.
Definition: qgsplot.h:312
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsPlotAxis::setLabelInterval
void setLabelInterval(double interval)
Sets the interval of labels for the axis.
Definition: qgsplot.h:139
Qgs2DPlot
Base class for 2-dimensional plot/chart/graphs.
Definition: qgsplot.h:234
Qgs2DPlot::yMinimum
double yMinimum() const
Returns the minimum value of the y axis.
Definition: qgsplot.h:319
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsNumericFormat
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
Definition: qgsnumericformat.h:259
QgsPlot::readXml
virtual bool readXml(const QDomElement &element, QgsReadWriteContext &context)
Reads the plot's properties from an XML element.
Definition: qgsplot.cpp:37
Qgs2DPlot::yMaximum
double yMaximum() const
Returns the maximum value of the y axis.
Definition: qgsplot.h:347
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
Qgs2DPlot::yAxis
const QgsPlotAxis & yAxis() const
Returns a reference to the plot's y axis.
Definition: qgsplot.h:383
qgis_sip.h
Qgs2DPlot::xMaximum
double xMaximum() const
Returns the maximum value of the x axis.
Definition: qgsplot.h:333
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:29
QgsMargins
The QgsMargins class defines the four margins of a rectangle.
Definition: qgsmargins.h:37
QgsPlot::writeXml
virtual bool writeXml(QDomElement &element, QDomDocument &document, QgsReadWriteContext &context) const
Writes the plot's properties into an XML element.
Definition: qgsplot.cpp:32
QgsPlotAxis::labelInterval
double labelInterval() const
Returns the interval of labels for the axis.
Definition: qgsplot.h:132
QgsPlotAxis::setGridIntervalMinor
void setGridIntervalMinor(double interval)
Sets the interval of minor grid lines for the axis.
Definition: qgsplot.h:111
Qgs2DPlot::setYMaximum
void setYMaximum(double maximum)
Sets the maximum value of the y axis.
Definition: qgsplot.h:354
QgsPlotAxis::setGridIntervalMajor
void setGridIntervalMajor(double interval)
Sets the interval of major grid lines for the axis.
Definition: qgsplot.h:125
Qgs2DPlot::xMinimum
double xMinimum() const
Returns the minimum value of the x axis.
Definition: qgsplot.h:305
Qgs2DPlot::xAxis
const QgsPlotAxis & xAxis() const
Returns a reference to the plot's x axis.
Definition: qgsplot.h:368
Qgs2DPlot::setXMaximum
void setXMaximum(double maximum)
Sets the maximum value of the x axis.
Definition: qgsplot.h:340
Qgs2DPlot::xAxis
QgsPlotAxis & xAxis()
Returns a reference to the plot's x axis.
Definition: qgsplot.h:361
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:29
QgsPlotAxis::gridIntervalMinor
double gridIntervalMinor() const
Returns the interval of minor grid lines for the axis.
Definition: qgsplot.h:104
qgstextformat.h
Qgs2DPlot::yAxis
QgsPlotAxis & yAxis()
Returns a reference to the plot's y axis.
Definition: qgsplot.h:375
QgsPlotAxis
Encapsulates the properties of a plot axis.
Definition: qgsplot.h:77
QgsPlot
Base class for plot/chart/graphs.
Definition: qgsplot.h:43
qgsmargins.h