@@ -32,17 +32,17 @@ QgsHistogramDiagram::~QgsHistogramDiagram()
32
32
QSizeF QgsHistogramDiagram::diagramSize ( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is )
33
33
{
34
34
Q_UNUSED ( c );
35
- QSize size;
35
+ QSizeF size;
36
36
if ( attributes.count () == 0 )
37
37
{
38
- return QSizeF () ; // zero size if no attributes
38
+ return size ; // zero size if no attributes
39
39
}
40
40
41
- double maxValue = attributes[ 0 ]. toDouble () ;
41
+ double maxValue = 0 ;
42
42
43
- for ( int i = 1 ; i < attributes. count (); ++i )
43
+ foreach ( int cat, s. categoryIndices )
44
44
{
45
- maxValue = qMax ( attributes[i ].toDouble (), maxValue );
45
+ maxValue = qMax ( attributes[cat ].toDouble (), maxValue );
46
46
}
47
47
48
48
// Scale, if extension is smaller than the specified minimum
@@ -56,13 +56,13 @@ QSizeF QgsHistogramDiagram::diagramSize( const QgsAttributes& attributes, const
56
56
case QgsDiagramSettings::Up:
57
57
case QgsDiagramSettings::Down:
58
58
mScaleFactor = (( is.upperSize .width () - is.lowerSize .height () ) / ( is.upperValue - is.lowerValue ) );
59
- size.scale ( s.barWidth * attributes .size (), maxValue * mScaleFactor , Qt::IgnoreAspectRatio );
59
+ size.scale ( s.barWidth * s. categoryIndices .size (), maxValue * mScaleFactor , Qt::IgnoreAspectRatio );
60
60
break ;
61
61
62
62
case QgsDiagramSettings::Right:
63
63
case QgsDiagramSettings::Left:
64
64
mScaleFactor = (( is.upperSize .width () - is.lowerSize .width () ) / ( is.upperValue - is.lowerValue ) );
65
- size.scale ( maxValue * mScaleFactor , s.barWidth * attributes .size (), Qt::IgnoreAspectRatio );
65
+ size.scale ( maxValue * mScaleFactor , s.barWidth * s. categoryIndices .size (), Qt::IgnoreAspectRatio );
66
66
break ;
67
67
}
68
68
@@ -114,14 +114,17 @@ void QgsHistogramDiagram::renderDiagram( const QgsAttributes& att, QgsRenderCont
114
114
}
115
115
116
116
QList<double > values;
117
+ double maxValue = 0 ;
117
118
118
- QList<int >::const_iterator catIt = s.categoryIndices .constBegin ();
119
- for ( ; catIt != s.categoryIndices .constEnd (); ++catIt )
119
+ foreach ( int cat, s.categoryIndices )
120
120
{
121
- double currentVal = att[*catIt ].toDouble ();
121
+ double currentVal = att[cat ].toDouble ();
122
122
values.push_back ( currentVal );
123
+ maxValue = qMax ( currentVal, maxValue );
123
124
}
124
125
126
+ double scaledMaxVal = sizePainterUnits ( maxValue * mScaleFactor , s, c );
127
+
125
128
double currentOffset = 0 ;
126
129
double scaledWidth = sizePainterUnits ( s.barWidth , s, c );
127
130
@@ -144,19 +147,19 @@ void QgsHistogramDiagram::renderDiagram( const QgsAttributes& att, QgsRenderCont
144
147
switch ( s.diagramOrientation )
145
148
{
146
149
case QgsDiagramSettings::Up:
147
- p->drawRect ( baseX + currentOffset, baseY, scaledWidth, 0 - length );
150
+ p->drawRect ( baseX + currentOffset, baseY, scaledWidth, length * - 1 );
148
151
break ;
149
152
150
153
case QgsDiagramSettings::Down:
151
- p->drawRect ( baseX + currentOffset, baseY, scaledWidth, length );
154
+ p->drawRect ( baseX + currentOffset, baseY - scaledMaxVal , scaledWidth, length );
152
155
break ;
153
156
154
157
case QgsDiagramSettings::Right:
155
- p->drawRect ( baseX, baseY + currentOffset, length, scaledWidth );
158
+ p->drawRect ( baseX, baseY - currentOffset, length, scaledWidth * - 1 );
156
159
break ;
157
160
158
161
case QgsDiagramSettings::Left:
159
- p->drawRect ( baseX, baseY + currentOffset, 0 - length, scaledWidth );
162
+ p->drawRect ( baseX + scaledMaxVal , baseY - currentOffset, 0 - length, scaledWidth * - 1 );
160
163
break ;
161
164
}
162
165
0 commit comments