QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
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
211 QString labelSuffix() const;
212
221 void setLabelSuffix( const QString &suffix );
222
231 Qgis::PlotAxisSuffixPlacement labelSuffixPlacement() const;
232
241 void setLabelSuffixPlacement( Qgis::PlotAxisSuffixPlacement placement );
242
243 private:
244
245#ifdef SIP_RUN
246 QgsPlotAxis( const QgsPlotAxis &other );
247#endif
248
249 double mGridIntervalMinor = 1;
250 double mGridIntervalMajor = 5;
251
252 double mLabelInterval = 1;
253
254 QString mLabelSuffix;
256
257 std::unique_ptr< QgsNumericFormat > mNumericFormat;
258
259 std::unique_ptr< QgsLineSymbol > mGridMajorSymbol;
260 std::unique_ptr< QgsLineSymbol > mGridMinorSymbol;
261
262 QgsTextFormat mLabelTextFormat;
263
264};
265
277class CORE_EXPORT Qgs2DPlot : public QgsPlot
278{
279 public:
280
284 Qgs2DPlot();
285
286 ~Qgs2DPlot() override;
287
289 Qgs2DPlot( const Qgs2DPlot &other ) = delete;
291 Qgs2DPlot &operator=( const Qgs2DPlot &other ) = delete;
292
293 bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
294 bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) override;
295
299 void render( QgsRenderContext &context );
300
312 virtual void renderContent( QgsRenderContext &context, const QRectF &plotArea );
313
319 QSizeF size() const;
320
326 void setSize( QSizeF size );
327
332 QRectF interiorPlotArea( QgsRenderContext &context ) const;
333
341 void calculateOptimisedIntervals( QgsRenderContext &context );
342
348 double xMinimum() const { return mMinX; }
349
355 void setXMinimum( double minimum ) { mMinX = minimum; }
356
362 double yMinimum() const { return mMinY; }
363
369 void setYMinimum( double minimum ) { mMinY = minimum; }
370
376 double xMaximum() const { return mMaxX; }
377
383 void setXMaximum( double maximum ) { mMaxX = maximum; }
384
390 double yMaximum() const { return mMaxY; }
391
397 void setYMaximum( double maximum ) { mMaxY = maximum; }
398
404 QgsPlotAxis &xAxis() { return mXAxis; }
405
411 const QgsPlotAxis &xAxis() const SIP_SKIP { return mXAxis; }
412
418 QgsPlotAxis &yAxis() { return mYAxis; }
419
425 const QgsPlotAxis &yAxis() const SIP_SKIP { return mYAxis; }
426
432 QgsFillSymbol *chartBackgroundSymbol();
433
441 void setChartBackgroundSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
442
448 QgsFillSymbol *chartBorderSymbol();
449
457 void setChartBorderSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
458
464 const QgsMargins &margins() const;
465
471 void setMargins( const QgsMargins &margins );
472
473 private:
474
475#ifdef SIP_RUN
476 Qgs2DPlot( const Qgs2DPlot &other );
477#endif
478
479 QSizeF mSize;
480
481 double mMinX = 0;
482 double mMinY = 0;
483 double mMaxX = 10;
484 double mMaxY = 10;
485
486 std::unique_ptr< QgsFillSymbol > mChartBackgroundSymbol;
487 std::unique_ptr< QgsFillSymbol > mChartBorderSymbol;
488
489 QgsMargins mMargins;
490
491 QgsPlotAxis mXAxis;
492 QgsPlotAxis mYAxis;
493};
494
503class CORE_EXPORT QgsPlotDefaultSettings
504{
505 public:
506
510 static QgsNumericFormat *axisLabelNumericFormat() SIP_FACTORY;
511
517 static QgsLineSymbol *axisGridMajorSymbol() SIP_FACTORY;
518
524 static QgsLineSymbol *axisGridMinorSymbol() SIP_FACTORY;
525
531 static QgsFillSymbol *chartBackgroundSymbol() SIP_FACTORY;
532
538 static QgsFillSymbol *chartBorderSymbol() SIP_FACTORY;
539
540};
541
542#endif // QGSPLOT_H
PlotAxisSuffixPlacement
Placement options for suffixes in the labels for axis of plots.
Definition qgis.h:2680
@ EveryLabel
Place suffix after every value label.
Base class for 2-dimensional plot/chart/graphs.
Definition qgsplot.h:278
double yMaximum() const
Returns the maximum value of the y axis.
Definition qgsplot.h:390
QgsPlotAxis & xAxis()
Returns a reference to the plot's x axis.
Definition qgsplot.h:404
void setXMinimum(double minimum)
Sets the minimum value of the x axis.
Definition qgsplot.h:355
const QgsPlotAxis & xAxis() const
Returns a reference to the plot's x axis.
Definition qgsplot.h:411
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:376
void setYMaximum(double maximum)
Sets the maximum value of the y axis.
Definition qgsplot.h:397
double xMinimum() const
Returns the minimum value of the x axis.
Definition qgsplot.h:348
QgsPlotAxis & yAxis()
Returns a reference to the plot's y axis.
Definition qgsplot.h:418
double yMinimum() const
Returns the minimum value of the y axis.
Definition qgsplot.h:362
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:425
void setXMaximum(double maximum)
Sets the maximum value of the x axis.
Definition qgsplot.h:383
void setYMinimum(double minimum)
Sets the minimum value of the y axis.
Definition qgsplot.h:369
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
A line symbol type, for rendering LineString and MultiLineString geometries.
The QgsMargins class defines the four margins of a rectangle.
Definition qgsmargins.h:37
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:504
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.
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:76