26using namespace Qt::StringLiterals;
32 mCategoryBrush.setStyle( Qt::SolidPattern );
33 mPen.setStyle( Qt::SolidLine );
63 maxValue = std::max( expression->
evaluate( &expressionContext ).toDouble(), maxValue );
75 double painterUnitConversionScale =
c.convertToPainterUnits( 1, s.
sizeType );
97 size.setWidth( size.width() + 2 * maxBleed );
98 size.setHeight( size.height() + 2 * maxBleed );
116 return value * scaleFactor;
128 if ( attributes.isEmpty() )
133 double maxValue = attributes.at( 0 ).toDouble();
135 for (
int i = 0; i < attributes.count(); ++i )
137 maxValue = std::max( attributes.at( i ).toDouble(), maxValue );
143 double painterUnitConversionScale =
c.convertToPainterUnits( 1, s.
sizeType );
151 mScaleFactor = maxValue / s.
size.height();
157 mScaleFactor = maxValue / s.
size.width();
165 size.setWidth( size.width() + 2 * maxBleed );
166 size.setHeight( size.height() + 2 * maxBleed );
174 QPainter *p =
c.painter();
180 QList<double> values;
192 double currentVal = expression->
evaluate( &expressionContext ).toDouble();
193 values.push_back( currentVal );
194 maxValue = std::max( currentVal, maxValue );
199 double currentOffset = 0;
204 double baseX = position.x();
205 double baseY = position.y();
220 QList<double>::const_iterator valIt = values.constBegin();
221 QList< QColor >::const_iterator colIt = s.
categoryColors.constBegin();
222 for ( ; valIt != values.constEnd(); ++valIt, ++colIt )
226 QColor brushColor( *colIt );
227 brushColor.setAlphaF( brushColor.alphaF() * s.
opacity );
228 mCategoryBrush.setColor( brushColor );
229 p->setBrush( mCategoryBrush );
234 p->drawRect( QRectF( baseX + currentOffset, baseY, scaledWidth, length * -1 ) );
238 p->drawRect( QRectF( baseX + currentOffset, baseY - scaledMaxVal, scaledWidth, length ) );
242 p->drawRect( QRectF( baseX, baseY - scaledWidth * values.size() - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) + currentOffset, length, scaledWidth ) );
246 p->drawRect( QRectF( baseX + scaledMaxVal, baseY - scaledWidth * values.size() - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) + currentOffset, 0 - length, scaledWidth ) );
250 currentOffset += scaledWidth + spacing;
256 QPolygonF axisPoints;
260 axisPoints << QPointF( baseX, baseY - scaledMaxVal ) << QPointF( baseX, baseY ) << QPointF( baseX + scaledWidth * values.size() + spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ), baseY );
264 axisPoints << QPointF( baseX, baseY ) << QPointF( baseX, baseY - scaledMaxVal ) << QPointF( baseX + scaledWidth * values.size() + spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ), baseY - scaledMaxVal );
268 axisPoints << QPointF( baseX + scaledMaxVal, baseY - scaledWidth * values.size() - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) )
269 << QPointF( baseX, baseY - scaledWidth * values.size() - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) )
270 << QPointF( baseX, baseY );
274 axisPoints << QPointF( baseX, baseY - scaledWidth * values.size() - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) )
275 << QPointF( baseX + scaledMaxVal, baseY - scaledWidth * values.size() - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) )
276 << QPointF( baseX + scaledMaxVal, baseY );
Additional diagram settings for interpolated size rendering.
Stores the settings for rendering a single diagram.
bool showAxis() const
Returns true if the diagram axis should be shown.
double opacity
Opacity, from 0 (transparent) to 1.0 (opaque).
QgsLineSymbol * axisLineSymbol() const
Returns the line symbol to use for rendering axis in diagrams.
Qgis::RenderUnit sizeType
Diagram size unit.
QList< QString > categoryAttributes
DiagramOrientation diagramOrientation
double spacing() const
Returns the spacing between diagram contents.
QList< QColor > categoryColors
const QgsMapUnitScale & spacingMapUnitScale() const
Returns the map unit scale for the content spacing.
double minimumSize
Scale diagrams smaller than mMinimumSize to mMinimumSize.
Qgis::RenderUnit spacingUnit() const
Returns the units for the content spacing.
void setPenWidth(QPen &pen, const QgsDiagramSettings &s, const QgsRenderContext &c)
Changes the pen width to match the current settings and rendering context.
QSizeF sizePainterUnits(QSizeF size, const QgsDiagramSettings &s, const QgsRenderContext &c)
Calculates a size to match the current settings and rendering context.
QgsExpression * getExpression(const QString &expression, const QgsExpressionContext &context)
Returns a prepared expression for the specified context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
Handles parsing and evaluation of expressions (formerly called "search strings").
QVariant evaluate()
Evaluate the feature and return the result.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
int attributeCount() const
Returns the number of attributes attached to the feature.
double legendSize(double value, const QgsDiagramSettings &s, const QgsDiagramInterpolationSettings &interpolationSettings) const override
Returns the size of the legend item for the diagram corresponding to a specified value.
QSizeF diagramSize(const QgsAttributes &attributes, const QgsRenderContext &c, const QgsDiagramSettings &s) override
Returns the size in map units the diagram will use to render.
static const QString DIAGRAM_NAME_HISTOGRAM
QString diagramName() const override
Gets a descriptive name for this diagram type.
void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, const QgsDiagramSettings &s, QPointF position) override
Draws the diagram at the given position (in pixel coordinates).
QgsHistogramDiagram * clone() const override
Returns an instance that is equivalent to this one.
void renderPolyline(const QPolygonF &points, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
Renders the symbol along the line joining points, using the given render context.
Contains information about the context of a rendering operation.
static double estimateMaxSymbolBleed(QgsSymbol *symbol, const QgsRenderContext &context)
Returns the maximum estimated bleed for the symbol.
void stopRender(QgsRenderContext &context)
Ends the rendering process.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
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
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).