27 mCategoryBrush.setStyle( Qt::SolidPattern );
28 mPen.setStyle( Qt::SolidLine );
50 attrVal = expression->
evaluate( &expressionContext );
58 double value = fabs( attrVal.toDouble( &ok ) );
69 double painterUnitConversionScale =
c.convertToPainterUnits( 1, s.
sizeType );
72 mApplySpacingAdjust =
true;
79 const double totalBarLength = size.height() + spacing * std::max( 0,
static_cast<int>( s.
categoryAttributes.size() ) - 1 );
80 size = QSizeF( s.
barWidth, totalBarLength );
87 const double totalBarLength = size.width() + spacing * std::max( 0,
static_cast<int>( s.
categoryAttributes.size() ) - 1 );
88 size = QSizeF( totalBarLength, s.
barWidth );
96 size.setWidth( size.width() + 2 * maxBleed );
97 size.setHeight( size.height() + 2 * maxBleed );
115 return value * scaleFactor;
128 if ( attributes.isEmpty() )
136 double painterUnitConversionScale =
c.convertToPainterUnits( 1, s.
sizeType );
158 QPainter *p =
c.painter();
164 QList< QPair<double, QColor> > values;
165 QList< QPair<double, QColor> > negativeValues;
174 double negativeTotal = 0;
176 QList< QColor >::const_iterator colIt = s.
categoryColors.constBegin();
180 double currentVal = expression->
evaluate( &expressionContext ).toDouble();
181 total += fabs( currentVal );
182 if ( currentVal >= 0 )
184 values.push_back( qMakePair( currentVal, *colIt ) );
188 negativeTotal += currentVal;
189 negativeValues.push_back( qMakePair( -currentVal, *colIt ) );
196 const double totalSpacing = std::max( 0,
static_cast<int>( s.
categoryAttributes.size() ) - 1 ) * spacing;
198 double scaledMaxVal = 0;
211 if ( mApplySpacingAdjust )
212 scaledMaxVal -= totalSpacing;
214 double axisOffset = 0;
215 if ( !negativeValues.isEmpty() )
217 axisOffset = -negativeTotal / total * scaledMaxVal + ( negativeValues.size() - 1 ) * spacing;
221 double baseX = position.x();
222 double baseY = position.y();
237 while ( !negativeValues.isEmpty() )
239 values.push_front( negativeValues.takeLast() );
242 double currentOffset = 0;
243 QList< QPair<double, QColor> >::const_iterator valIt = values.constBegin();
244 for ( ; valIt != values.constEnd(); ++valIt )
246 double length = valIt->first / total * scaledMaxVal;
248 mCategoryBrush.setColor( valIt->second );
249 p->setBrush( mCategoryBrush );
254 p->drawRect( QRectF( baseX, baseY - currentOffset, scaledWidth, length * -1 ) );
258 p->drawRect( QRectF( baseX, baseY + currentOffset - scaledMaxVal - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ), scaledWidth, length ) );
262 p->drawRect( QRectF( baseX + currentOffset, baseY - scaledWidth, length, scaledWidth ) );
266 p->drawRect( QRectF( baseX + scaledMaxVal - currentOffset + spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ), baseY - scaledWidth, 0 - length, scaledWidth ) );
270 currentOffset += length + spacing;
276 QPolygonF axisPoints;
280 axisPoints << QPointF( baseX, baseY - scaledMaxVal - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) )
281 << QPointF( baseX, baseY - axisOffset )
282 << QPointF( baseX + scaledWidth, baseY - axisOffset );
286 axisPoints << QPointF( baseX, baseY )
287 << QPointF( baseX, baseY - scaledMaxVal - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) + axisOffset )
288 << QPointF( baseX + scaledWidth, baseY - scaledMaxVal - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) + axisOffset );
292 axisPoints << QPointF( baseX + scaledMaxVal + spacing * std::max( 0, static_cast<int>( values.size() ) - 1 ), baseY - scaledWidth )
293 << QPointF( baseX + axisOffset, baseY - scaledWidth )
294 << QPointF( baseX + axisOffset, baseY );
298 axisPoints << QPointF( baseX, baseY - scaledWidth )
299 << QPointF( baseX + scaledMaxVal + spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) - axisOffset, baseY - scaledWidth )
300 << QPointF( baseX + scaledMaxVal + spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) - axisOffset, baseY );
Additional diagram settings for interpolated size rendering.
bool classificationAttributeIsExpression
QString classificationField
Name of the field for classification.
QString classificationAttributeExpression
Stores the settings for rendering a single diagram.
QgsUnitTypes::RenderUnit spacingUnit() const
Returns the units for the content spacing.
QgsUnitTypes::RenderUnit sizeType
Diagram size unit.
bool showAxis() const
Returns true if the diagram axis should be shown.
QgsLineSymbol * axisLineSymbol() const
Returns the line symbol to use for rendering axis in diagrams.
QList< QString > categoryAttributes
DiagramOrientation diagramOrientation
double spacing() const
Returns the spacing between diagram contents.
const QgsMapUnitScale & spacingMapUnitScale() const
Returns the map unit scale for the content spacing.
QList< QColor > categoryColors
double minimumSize
Scale diagrams smaller than mMinimumSize to mMinimumSize.
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.
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...
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.
Class for 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...
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
bool isEmpty() const
Checks whether the container is empty.
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.
A stacked bar chart diagram.
QgsStackedBarDiagram * clone() const override
Returns an instance that is equivalent to this one.
QSizeF diagramSize(const QgsAttributes &attributes, const QgsRenderContext &c, const QgsDiagramSettings &s) override
Returns the size in map units the diagram will use to render.
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.
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)
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)
#define DIAGRAM_NAME_STACKED