161 QPainter *p =
c.painter();
167 QList< QPair<double, QColor> > values;
168 QList< QPair<double, QColor> > negativeValues;
177 double negativeTotal = 0;
179 QList< QColor >::const_iterator colIt = s.
categoryColors.constBegin();
183 double currentVal = expression->
evaluate( &expressionContext ).toDouble();
184 total += fabs( currentVal );
185 if ( currentVal >= 0 )
187 values.push_back( qMakePair( currentVal, *colIt ) );
191 negativeTotal += currentVal;
192 negativeValues.push_back( qMakePair( -currentVal, *colIt ) );
199 const double totalSpacing = std::max( 0,
static_cast<int>( s.
categoryAttributes.size() ) - 1 ) * spacing;
201 double scaledMaxVal = 0;
214 if ( mApplySpacingAdjust )
215 scaledMaxVal -= totalSpacing;
217 double axisOffset = 0;
218 if ( !negativeValues.isEmpty() )
220 axisOffset = -negativeTotal / total * scaledMaxVal + ( negativeValues.size() - 1 ) * spacing;
224 double baseX = position.x();
225 double baseY = position.y();
240 while ( !negativeValues.isEmpty() )
242 values.push_front( negativeValues.takeLast() );
245 double currentOffset = 0;
246 QList< QPair<double, QColor> >::const_iterator valIt = values.constBegin();
247 for ( ; valIt != values.constEnd(); ++valIt )
249 double length = valIt->first / total * scaledMaxVal;
251 QColor brushColor( valIt->second );
252 brushColor.setAlphaF( brushColor.alphaF() * s.
opacity );
253 mCategoryBrush.setColor( brushColor );
254 p->setBrush( mCategoryBrush );
259 p->drawRect( QRectF( baseX, baseY - currentOffset, scaledWidth, length * -1 ) );
263 p->drawRect( QRectF( baseX, baseY + currentOffset - scaledMaxVal - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ), scaledWidth, length ) );
267 p->drawRect( QRectF( baseX + currentOffset, baseY - scaledWidth, length, scaledWidth ) );
271 p->drawRect( QRectF( baseX + scaledMaxVal - currentOffset + spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ), baseY - scaledWidth, 0 - length, scaledWidth ) );
275 currentOffset += length + spacing;
281 QPolygonF axisPoints;
285 axisPoints << QPointF( baseX, baseY - scaledMaxVal - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) )
286 << QPointF( baseX, baseY - axisOffset )
287 << QPointF( baseX + scaledWidth, baseY - axisOffset );
291 axisPoints << QPointF( baseX, baseY )
292 << QPointF( baseX, baseY - scaledMaxVal - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) + axisOffset )
293 << QPointF( baseX + scaledWidth, baseY - scaledMaxVal - spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) + axisOffset );
297 axisPoints << QPointF( baseX + scaledMaxVal + spacing * std::max( 0, static_cast<int>( values.size() ) - 1 ), baseY - scaledWidth )
298 << QPointF( baseX + axisOffset, baseY - scaledWidth )
299 << QPointF( baseX + axisOffset, baseY );
303 axisPoints << QPointF( baseX, baseY - scaledWidth )
304 << QPointF( baseX + scaledMaxVal + spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) - axisOffset, baseY - scaledWidth )
305 << QPointF( baseX + scaledMaxVal + spacing * std::max( 0,
static_cast<int>( values.size() ) - 1 ) - axisOffset, baseY );
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.
Contains information about the context of a rendering operation.