QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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
47 QgsPlot() = default;
48
49 virtual ~QgsPlot();
50
54 virtual bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
55
59 virtual bool readXml( const QDomElement &element, const QgsReadWriteContext &context );
60
61 private:
62
63
64};
65
74class CORE_EXPORT QgsPlotAxis
75{
76 public:
77
80
81 QgsPlotAxis( const QgsPlotAxis &other ) = delete;
82 QgsPlotAxis &operator=( const QgsPlotAxis &other ) = delete;
83
87 bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
88
92 bool readXml( const QDomElement &element, const QgsReadWriteContext &context );
93
99 double gridIntervalMinor() const { return mGridIntervalMinor; }
100
106 void setGridIntervalMinor( double interval ) { mGridIntervalMinor = interval; }
107
113 double gridIntervalMajor() const { return mGridIntervalMajor; }
114
120 void setGridIntervalMajor( double interval ) { mGridIntervalMajor = interval; }
121
127 double labelInterval() const { return mLabelInterval; }
128
134 void setLabelInterval( double interval ) { mLabelInterval = interval; }
135
141 QgsLineSymbol *gridMajorSymbol();
142
150 void setGridMajorSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
151
157 QgsLineSymbol *gridMinorSymbol();
158
166 void setGridMinorSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
167
173 QgsTextFormat textFormat() const;
174
180 void setTextFormat( const QgsTextFormat &format );
181
187 QgsNumericFormat *numericFormat() const;
188
196 void setNumericFormat( QgsNumericFormat *format SIP_TRANSFER );
197
206 QString labelSuffix() const;
207
216 void setLabelSuffix( const QString &suffix );
217
226 Qgis::PlotAxisSuffixPlacement labelSuffixPlacement() const;
227
236 void setLabelSuffixPlacement( Qgis::PlotAxisSuffixPlacement placement );
237
238 private:
239
240#ifdef SIP_RUN
241 QgsPlotAxis( const QgsPlotAxis &other );
242#endif
243
244 double mGridIntervalMinor = 1;
245 double mGridIntervalMajor = 5;
246
247 double mLabelInterval = 1;
248
249 QString mLabelSuffix;
251
252 std::unique_ptr< QgsNumericFormat > mNumericFormat;
253
254 std::unique_ptr< QgsLineSymbol > mGridMajorSymbol;
255 std::unique_ptr< QgsLineSymbol > mGridMinorSymbol;
256
257 QgsTextFormat mLabelTextFormat;
258
259};
260
272class CORE_EXPORT Qgs2DPlot : public QgsPlot
273{
274 public:
275
279 Qgs2DPlot();
280
281 ~Qgs2DPlot() override;
282
283 Qgs2DPlot( const Qgs2DPlot &other ) = delete;
284 Qgs2DPlot &operator=( const Qgs2DPlot &other ) = delete;
285
286 bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
287 bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) override;
288
292 void render( QgsRenderContext &context );
293
305 virtual void renderContent( QgsRenderContext &context, const QRectF &plotArea );
306
312 QSizeF size() const;
313
319 void setSize( QSizeF size );
320
325 QRectF interiorPlotArea( QgsRenderContext &context ) const;
326
334 void calculateOptimisedIntervals( QgsRenderContext &context );
335
341 double xMinimum() const { return mMinX; }
342
348 void setXMinimum( double minimum ) { mMinX = minimum; }
349
355 double yMinimum() const { return mMinY; }
356
362 void setYMinimum( double minimum ) { mMinY = minimum; }
363
369 double xMaximum() const { return mMaxX; }
370
376 void setXMaximum( double maximum ) { mMaxX = maximum; }
377
383 double yMaximum() const { return mMaxY; }
384
390 void setYMaximum( double maximum ) { mMaxY = maximum; }
391
397 QgsPlotAxis &xAxis() { return mXAxis; }
398
404 const QgsPlotAxis &xAxis() const SIP_SKIP { return mXAxis; }
405
411 QgsPlotAxis &yAxis() { return mYAxis; }
412
418 const QgsPlotAxis &yAxis() const SIP_SKIP { return mYAxis; }
419
425 QgsFillSymbol *chartBackgroundSymbol();
426
434 void setChartBackgroundSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
435
441 QgsFillSymbol *chartBorderSymbol();
442
450 void setChartBorderSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
451
457 const QgsMargins &margins() const;
458
464 void setMargins( const QgsMargins &margins );
465
466 private:
467
468#ifdef SIP_RUN
469 Qgs2DPlot( const Qgs2DPlot &other );
470#endif
471
472 QSizeF mSize;
473
474 double mMinX = 0;
475 double mMinY = 0;
476 double mMaxX = 10;
477 double mMaxY = 10;
478
479 std::unique_ptr< QgsFillSymbol > mChartBackgroundSymbol;
480 std::unique_ptr< QgsFillSymbol > mChartBorderSymbol;
481
482 QgsMargins mMargins;
483
484 QgsPlotAxis mXAxis;
485 QgsPlotAxis mYAxis;
486};
487
496class CORE_EXPORT QgsPlotDefaultSettings
497{
498 public:
499
503 static QgsNumericFormat *axisLabelNumericFormat() SIP_FACTORY;
504
510 static QgsLineSymbol *axisGridMajorSymbol() SIP_FACTORY;
511
517 static QgsLineSymbol *axisGridMinorSymbol() SIP_FACTORY;
518
524 static QgsFillSymbol *chartBackgroundSymbol() SIP_FACTORY;
525
531 static QgsFillSymbol *chartBorderSymbol() SIP_FACTORY;
532
533};
534
535#endif // QGSPLOT_H
PlotAxisSuffixPlacement
Placement options for suffixes in the labels for axis of plots.
Definition qgis.h:3095
@ EveryLabel
Place suffix after every value label.
Base class for 2-dimensional plot/chart/graphs.
Definition qgsplot.h:273
double yMaximum() const
Returns the maximum value of the y axis.
Definition qgsplot.h:383
QgsPlotAxis & xAxis()
Returns a reference to the plot's x axis.
Definition qgsplot.h:397
void setXMinimum(double minimum)
Sets the minimum value of the x axis.
Definition qgsplot.h:348
const QgsPlotAxis & xAxis() const
Returns a reference to the plot's x axis.
Definition qgsplot.h:404
Qgs2DPlot & operator=(const Qgs2DPlot &other)=delete
~Qgs2DPlot() override
double xMaximum() const
Returns the maximum value of the x axis.
Definition qgsplot.h:369
void setYMaximum(double maximum)
Sets the maximum value of the y axis.
Definition qgsplot.h:390
double xMinimum() const
Returns the minimum value of the x axis.
Definition qgsplot.h:341
QgsPlotAxis & yAxis()
Returns a reference to the plot's y axis.
Definition qgsplot.h:411
double yMinimum() const
Returns the minimum value of the y axis.
Definition qgsplot.h:355
Qgs2DPlot(const Qgs2DPlot &other)=delete
const QgsPlotAxis & yAxis() const
Returns a reference to the plot's y axis.
Definition qgsplot.h:418
void setXMaximum(double maximum)
Sets the maximum value of the x axis.
Definition qgsplot.h:376
void setYMinimum(double minimum)
Sets the minimum value of the y axis.
Definition qgsplot.h:362
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:75
double gridIntervalMinor() const
Returns the interval of minor grid lines for the axis.
Definition qgsplot.h:99
double gridIntervalMajor() const
Returns the interval of major grid lines for the axis.
Definition qgsplot.h:113
void setGridIntervalMajor(double interval)
Sets the interval of major grid lines for the axis.
Definition qgsplot.h:120
void setGridIntervalMinor(double interval)
Sets the interval of minor grid lines for the axis.
Definition qgsplot.h:106
void setLabelInterval(double interval)
Sets the interval of labels for the axis.
Definition qgsplot.h:134
double labelInterval() const
Returns the interval of labels for the axis.
Definition qgsplot.h:127
QgsPlotAxis & operator=(const QgsPlotAxis &other)=delete
QgsPlotAxis(const QgsPlotAxis &other)=delete
Manages default settings for plot objects.
Definition qgsplot.h:497
Base class for plot/chart/graphs.
Definition qgsplot.h:44
QgsPlot()=default
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