26 mCategoryBrush.setStyle( Qt::SolidPattern );
27 mPen.setStyle( Qt::SolidLine );
49 attrVal = expression->
evaluate( &expressionContext );
57 double value = fabs( attrVal.toDouble( &ok ) );
68 double painterUnitConversionScale =
c.convertToPainterUnits( 1, s.
sizeType );
71 mApplySpacingAdjust =
true;
78 const double totalBarLength = size.height() + spacing * std::max( 0, s.
categoryAttributes.size() - 1 );
79 size = QSizeF( s.
barWidth, totalBarLength );
86 const double totalBarLength = size.width() + spacing * std::max( 0, s.
categoryAttributes.size() - 1 );
87 size = QSizeF( totalBarLength, s.
barWidth );
95 size.setWidth( size.width() + 2 * maxBleed );
96 size.setHeight( size.height() + 2 * maxBleed );
114 return value * scaleFactor;
127 if ( attributes.isEmpty() )
135 double painterUnitConversionScale =
c.convertToPainterUnits( 1, s.
sizeType );
157 QPainter *p =
c.painter();
163 QList< QPair<double, QColor> > values;
164 QList< QPair<double, QColor> > negativeValues;
173 double negativeTotal = 0;
175 QList< QColor >::const_iterator colIt = s.
categoryColors.constBegin();
179 double currentVal = expression->
evaluate( &expressionContext ).toDouble();
180 total += fabs( currentVal );
181 if ( currentVal >= 0 )
183 values.push_back( qMakePair( currentVal, *colIt ) );
187 negativeTotal += currentVal;
188 negativeValues.push_back( qMakePair( -currentVal, *colIt ) );
197 double scaledMaxVal = 0;
210 if ( mApplySpacingAdjust )
211 scaledMaxVal -= totalSpacing;
213 double axisOffset = 0;
214 if ( !negativeValues.isEmpty() )
216 axisOffset = -negativeTotal / total * scaledMaxVal + ( negativeValues.size() - 1 ) * spacing;
220 double baseX = position.x();
221 double baseY = position.y();
236 while ( !negativeValues.isEmpty() )
238 values.push_front( negativeValues.takeLast() );
241 double currentOffset = 0;
242 QList< QPair<double, QColor> >::const_iterator valIt = values.constBegin();
243 for ( ; valIt != values.constEnd(); ++valIt )
245 double length = valIt->first / total * scaledMaxVal;
247 mCategoryBrush.setColor( valIt->second );
248 p->setBrush( mCategoryBrush );
253 p->drawRect( QRectF( baseX, baseY - currentOffset, scaledWidth, length * -1 ) );
257 p->drawRect( QRectF( baseX, baseY + currentOffset - scaledMaxVal - spacing * std::max( 0, values.size() - 1 ), scaledWidth, length ) );
261 p->drawRect( QRectF( baseX + currentOffset, baseY - scaledWidth, length, scaledWidth ) );
265 p->drawRect( QRectF( baseX + scaledMaxVal - currentOffset + spacing * std::max( 0, values.size() - 1 ), baseY - scaledWidth, 0 - length, scaledWidth ) );
269 currentOffset += length + spacing;
275 QPolygonF axisPoints;
279 axisPoints << QPointF( baseX, baseY - scaledMaxVal - spacing * std::max( 0, values.size() - 1 ) )
280 << QPointF( baseX, baseY - axisOffset )
281 << QPointF( baseX + scaledWidth, baseY - axisOffset );
285 axisPoints << QPointF( baseX, baseY )
286 << QPointF( baseX, baseY - scaledMaxVal - spacing * std::max( 0, values.size() - 1 ) + axisOffset )
287 << QPointF( baseX + scaledWidth, baseY - scaledMaxVal - spacing * std::max( 0, values.size() - 1 ) + axisOffset );
291 axisPoints << QPointF( baseX + scaledMaxVal + spacing * std::max( 0, values.size() - 1 ), baseY - scaledWidth )
292 << QPointF( baseX + axisOffset, baseY - scaledWidth )
293 << QPointF( baseX + axisOffset, baseY );
297 axisPoints << QPointF( baseX, baseY - scaledWidth )
298 << QPointF( baseX + scaledMaxVal + spacing * std::max( 0, values.size() - 1 ) - axisOffset, baseY - scaledWidth )
299 << QPointF( baseX + scaledMaxVal + spacing * std::max( 0, 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 id, geometry and a list of field/values...
QVariant attribute(const QString &name) const
Lookup attribute value from 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