QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsdiagram.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdiagram.h
3  ---------------------
4  begin : March 2011
5  copyright : (C) 2011 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSDIAGRAM_H
16 #define QGSDIAGRAM_H
17 
18 #include "qgis_core.h"
19 #include "qgis.h"
20 #include <QPen>
21 #include <QBrush>
22 #include "qgsexpression.h" //for QMap with QgsExpression
23 
24 class QPainter;
25 class QPointF;
26 class QgsDiagramSettings;
28 class QgsFeature;
29 class QgsRenderContext;
31 class QgsFields;
32 class QgsAttributes;
33 
34 
39 class CORE_EXPORT QgsDiagram SIP_NODEFAULTCTORS
40 {
41  public:
42 
43 #ifdef SIP_RUN
45  if ( sipCpp->diagramName() == QLatin1String( "Pie" ) )
46  sipType = sipType_QgsPieDiagram;
47  else if ( sipCpp->diagramName() == QLatin1String( "Histogram" ) )
48  sipType = sipType_QgsHistogramDiagram;
49  else if ( sipCpp->diagramName() == QLatin1String( "Text" ) )
50  sipType = sipType_QgsTextDiagram;
51  else if ( sipCpp->diagramName() == QLatin1String( "Stacked" ) )
52  sipType = sipType_QgsStackedBarDiagram;
53  else
54  sipType = NULL;
55  SIP_END
56 #endif
57 
58  virtual ~QgsDiagram() { clearCache(); }
59 
64  virtual QgsDiagram *clone() const = 0 SIP_FACTORY;
65 
66  void clearCache();
67 
74  QgsExpression *getExpression( const QString &expression, const QgsExpressionContext &context );
75 
77  virtual void renderDiagram( const QgsFeature &feature, QgsRenderContext &c, const QgsDiagramSettings &s, QPointF position ) = 0;
78 
82  virtual QString diagramName() const = 0;
84  virtual QSizeF diagramSize( const QgsAttributes &attributes, const QgsRenderContext &c, const QgsDiagramSettings &s ) = 0;
86  virtual QSizeF diagramSize( const QgsFeature &feature, const QgsRenderContext &c, const QgsDiagramSettings &s, const QgsDiagramInterpolationSettings &is ) = 0;
87 
95  virtual double legendSize( double value, const QgsDiagramSettings &s, const QgsDiagramInterpolationSettings &is ) const = 0;
96 
97  protected:
98 
102  QgsDiagram() = default;
103  QgsDiagram( const QgsDiagram &other );
104 
111  void setPenWidth( QPen &pen, const QgsDiagramSettings &s, const QgsRenderContext &c );
112 
121  QSizeF sizePainterUnits( QSizeF size, const QgsDiagramSettings &s, const QgsRenderContext &c );
122 
131  double sizePainterUnits( double l, const QgsDiagramSettings &s, const QgsRenderContext &c );
132 
140  QFont scaledFont( const QgsDiagramSettings &s, const QgsRenderContext &c );
141 
149  QSizeF sizeForValue( double value, const QgsDiagramSettings &s, const QgsDiagramInterpolationSettings &is ) const;
150 
151  private:
152  QMap<QString, QgsExpression *> mExpressions;
153  QgsDiagram &operator= ( const QgsDiagram & ) = delete;
154 };
155 
156 #endif // QGSDIAGRAM_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsDiagram::renderDiagram
virtual void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, const QgsDiagramSettings &s, QPointF position)=0
Draws the diagram at the given position (in pixel coordinates)
QgsDiagram::diagramSize
virtual QSizeF diagramSize(const QgsAttributes &attributes, const QgsRenderContext &c, const QgsDiagramSettings &s)=0
Returns the size in map units the diagram will use to render.
QgsDiagram
Base class for all diagram types.
Definition: qgsdiagram.h:40
QgsDiagram::diagramSize
virtual QSizeF diagramSize(const QgsFeature &feature, const QgsRenderContext &c, const QgsDiagramSettings &s, const QgsDiagramInterpolationSettings &is)=0
Returns the size in map units the diagram will use to render. Interpolate size.
QgsDiagram::clone
virtual QgsDiagram * clone() const =0
Returns an instance that is equivalent to this one.
qgsexpression.h
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:45
QgsDiagram::diagramName
virtual QString diagramName() const =0
Gets a descriptive name for this diagram type.
qgis.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
QgsDiagram::~QgsDiagram
virtual ~QgsDiagram()
Definition: qgsdiagram.h:58
QgsDiagramInterpolationSettings
Additional diagram settings for interpolated size rendering.
Definition: qgsdiagramrenderer.h:662
SIP_NODEFAULTCTORS
#define SIP_NODEFAULTCTORS
Definition: qgis_sip.h:101
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsAttributes
A vector of attributes.
Definition: qgsattributes.h:58
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsDiagram::QgsDiagram
QgsDiagram()=default
Constructor for QgsDiagram.
QgsDiagram::legendSize
virtual double legendSize(double value, const QgsDiagramSettings &s, const QgsDiagramInterpolationSettings &is) const =0
Returns the size of the legend item for the diagram corresponding to a specified value.
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:105
SIP_END
#define SIP_END
Definition: qgis_sip.h:194
QgsDiagramSettings
Stores the settings for rendering a single diagram.
Definition: qgsdiagramrenderer.h:381