25 mCategoryBrush.setStyle( Qt::SolidPattern );
26 mPen.setStyle( Qt::SolidLine );
48 attrVal = expression->
evaluate( &expressionContext );
56 double value = attrVal.toDouble( &ok );
70 mApplySpacingAdjust =
true;
77 const double totalBarLength = size.height() + spacing * std::max( 0, s.
categoryAttributes.size() - 1 );
78 size = QSizeF( s.
barWidth, totalBarLength );
85 const double totalBarLength = size.width() + spacing * std::max( 0, s.
categoryAttributes.size() - 1 );
86 size = QSizeF( totalBarLength, s.
barWidth );
106 return value * scaleFactor;
119 if ( attributes.isEmpty() )
125 for (
int i = 0; i < attributes.count(); ++i )
127 totalSum += attributes.at( i ).toDouble();
161 QList<double> values;
173 double currentVal = expression->
evaluate( &expressionContext ).toDouble();
174 values.push_back( currentVal );
181 double scaledMaxVal = 0;
194 if ( mApplySpacingAdjust )
195 scaledMaxVal -= totalSpacing;
197 double currentOffset = 0;
201 double baseX = position.x();
202 double baseY = position.y();
208 QList<double>::const_iterator valIt = values.constBegin();
209 QList< QColor >::const_iterator colIt = s.
categoryColors.constBegin();
210 for ( ; valIt != values.constEnd(); ++valIt, ++colIt )
212 double length = *valIt / total * scaledMaxVal;
214 mCategoryBrush.setColor( *colIt );
215 p->setBrush( mCategoryBrush );
220 p->drawRect( QRectF( baseX, baseY - currentOffset, scaledWidth, length * -1 ) );
224 p->drawRect( QRectF( baseX, baseY + currentOffset - scaledMaxVal - spacing * std::max( 0, values.size() - 1 ), scaledWidth, length ) );
228 p->drawRect( QRectF( baseX + currentOffset, baseY - scaledWidth, length, scaledWidth ) );
232 p->drawRect( QRectF( baseX + scaledMaxVal - currentOffset + spacing * std::max( 0, values.size() - 1 ), baseY - scaledWidth, 0 - length, scaledWidth ) );
236 currentOffset += length + spacing;
QSizeF sizePainterUnits(QSizeF size, const QgsDiagramSettings &s, const QgsRenderContext &c)
Calculates a size to match the current settings and rendering context.
Class for parsing and evaluation of expressions (formerly called "search strings").
double minimumSize
Scale diagrams smaller than mMinimumSize to mMinimumSize.
QString diagramName() const override
Gets a descriptive name for this diagram type.
const QgsMapUnitScale & spacingMapUnitScale() const
Returns the map unit scale for the content spacing.
A stacked bar chart diagram.
QgsUnitTypes::RenderUnit spacingUnit() const
Returns the units for the content spacing.
QList< QString > categoryAttributes
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
bool classificationAttributeIsExpression
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QVariant evaluate()
Evaluate the feature and return the result.
double legendSize(double value, const QgsDiagramSettings &s, const QgsDiagramInterpolationSettings &is) const override
Returns the size of the legend item for the diagram corresponding to a specified value.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
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
DiagramOrientation diagramOrientation
QString classificationAttributeExpression
QSizeF diagramSize(const QgsAttributes &attributes, const QgsRenderContext &c, const QgsDiagramSettings &s) override
Returns the size in map units the diagram will use to render.
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...
double spacing() const
Returns the spacing between diagram contents.
#define DIAGRAM_NAME_STACKED
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
QgsUnitTypes::RenderUnit sizeType
Diagram size unit.
QSizeF sizeForValue(double value, const QgsDiagramSettings &s, const QgsDiagramInterpolationSettings &is) const
Returns the scaled size of a diagram for a value, respecting the specified diagram interpolation sett...
QgsExpressionContext & expressionContext()
Gets the expression context.
Additional diagram settings for interpolated size rendering.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsStackedBarDiagram * clone() const override
Returns an instance that is equivalent to this one.
QString classificationField
Name of the field for classification.
bool isEmpty() const
Checks whether the container is empty.
void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, const QgsDiagramSettings &s, QPointF position) override
Draws the diagram at the given position (in pixel coordinates)
void setPenWidth(QPen &pen, const QgsDiagramSettings &s, const QgsRenderContext &c)
Changes the pen width to match the current settings and rendering context.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QList< QColor > categoryColors
Stores the settings for rendering a single diagram.