18 #include "qgsexpression.h" 24 mCategoryBrush.setStyle( Qt::SolidPattern );
25 mPen.setStyle( Qt::SolidLine );
54 QgsExpression *expression =
getExpression( cat, expressionContext );
55 maxValue = std::max( expression->evaluate( &expressionContext ).toDouble(), maxValue );
94 return value * scaleFactor;
107 if ( attributes.isEmpty() )
112 double maxValue = attributes.at( 0 ).toDouble();
114 for (
int i = 0; i < attributes.count(); ++i )
116 maxValue = std::max( attributes.at( i ).toDouble(), maxValue );
123 mScaleFactor = maxValue / s.
size.height();
130 mScaleFactor = maxValue / s.
size.width();
146 QList<double> values;
156 QgsExpression *expression =
getExpression( cat, expressionContext );
157 double currentVal = expression->evaluate( &expressionContext ).toDouble();
158 values.push_back( currentVal );
159 maxValue = std::max( currentVal, maxValue );
164 double currentOffset = 0;
167 double baseX = position.x();
168 double baseY = position.y();
174 QList<double>::const_iterator valIt = values.constBegin();
175 QList< QColor >::const_iterator colIt = s.
categoryColors.constBegin();
176 for ( ; valIt != values.constEnd(); ++valIt, ++colIt )
180 mCategoryBrush.setColor( *colIt );
181 p->setBrush( mCategoryBrush );
186 p->drawRect( baseX + currentOffset, baseY, scaledWidth, length * -1 );
190 p->drawRect( baseX + currentOffset, baseY - scaledMaxVal, scaledWidth, length );
194 p->drawRect( baseX, baseY - currentOffset, length, scaledWidth * -1 );
198 p->drawRect( baseX + scaledMaxVal, baseY - currentOffset, 0 - length, scaledWidth * -1 );
202 currentOffset += scaledWidth;
QSizeF sizePainterUnits(QSizeF size, const QgsDiagramSettings &s, const QgsRenderContext &c)
Calculates a size to match the current settings and rendering context.
void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, const QgsDiagramSettings &s, QPointF position) override
Draws the diagram at the given position (in pixel coordinates)
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 minimumSize
Scale diagrams smaller than mMinimumSize to mMinimumSize.
QgsHistogramDiagram * clone() const override
Returns an instance that is equivalent to this one.
QList< QString > categoryAttributes
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
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.
#define DIAGRAM_NAME_HISTOGRAM
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
QString diagramName() const override
Get a descriptive name for this diagram type.
DiagramOrientation diagramOrientation
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 setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
QgsExpressionContext & expressionContext()
Gets the expression context.
Additional diagram settings for interpolated size rendering.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
bool isEmpty() const
Check whether the container is empty.
void setPenWidth(QPen &pen, const QgsDiagramSettings &s, const QgsRenderContext &c)
Changes the pen width to match the current settings and rendering context.
QList< QColor > categoryColors
Stores the settings for rendering a single diagram.