Skip to content

Commit

Permalink
Merge branch 'diagram-additional-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 29, 2012
2 parents c8a3321 + b97f2fc commit 0eab969
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/app/qgsdiagramproperties.cpp
Expand Up @@ -511,7 +511,6 @@ void QgsDiagramProperties::apply()

ds.backgroundColor = mBackgroundColorButton->color();
ds.penColor = mDiagramPenColorButton->color();
ds.penColor.setAlpha( 255 - ds.transparency );
ds.penWidth = mPenWidthSpinBox->value();
if ( mVisibilityGroupBox->isChecked() )
{
Expand Down
15 changes: 13 additions & 2 deletions src/core/diagram/qgspiediagram.cpp
Expand Up @@ -89,13 +89,15 @@ void QgsPieDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext&
QList<double> values;
double currentVal = 0;
double valSum = 0;
int valCount = 0;

QList<int>::const_iterator catIt = s.categoryIndices.constBegin();
for ( ; catIt != s.categoryIndices.constEnd(); ++catIt )
{
currentVal = att[*catIt].toDouble();
values.push_back( currentVal );
valSum += currentVal;
if ( currentVal ) valCount++;
}

//draw the slices
Expand All @@ -114,7 +116,7 @@ void QgsPieDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext&
setPenWidth( mPen, s, c );
p->setPen( mPen );

// draw empty circle if no values are defined at all
// there are some values > 0 available
if ( valSum > 0 )
{
QList<double>::const_iterator valIt = values.constBegin();
Expand All @@ -124,12 +126,21 @@ void QgsPieDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext&
currentAngle = *valIt / valSum * 360 * 16;
mCategoryBrush.setColor( *colIt );
p->setBrush( mCategoryBrush );
p->drawPie( baseX, baseY, w, h, totalAngle, currentAngle );
// if only 1 value is > 0, draw a circle
if ( valCount == 1 )
{
p->drawEllipse( baseX, baseY, w, h );
}
else
{
p->drawPie( baseX, baseY, w, h, totalAngle, currentAngle );
}
totalAngle += currentAngle;
}
}
else // valSum > 0
{
// draw empty circle if no values are defined at all
mCategoryBrush.setColor( Qt::transparent );
p->setBrush( mCategoryBrush );
p->drawEllipse( baseX, baseY, w, h );
Expand Down
5 changes: 4 additions & 1 deletion src/core/qgsdiagramrendererv2.cpp
Expand Up @@ -54,8 +54,10 @@ void QgsDiagramSettings::readXML( const QDomElement& elem )
size.setHeight( elem.attribute( "height" ).toDouble() );
transparency = elem.attribute( "transparency", "0" ).toInt();
penColor.setNamedColor( elem.attribute( "penColor" ) );
penColor.setAlpha( 255 - transparency );
int penAlpha = elem.attribute( "penAlpha", "255" ).toInt();
penColor.setAlpha( penAlpha );
penWidth = elem.attribute( "penWidth" ).toDouble();

minScaleDenominator = elem.attribute( "minScaleDenominator", "-1" ).toDouble();
maxScaleDenominator = elem.attribute( "maxScaleDenominator", "-1" ).toDouble();

Expand Down Expand Up @@ -141,6 +143,7 @@ void QgsDiagramSettings::writeXML( QDomElement& rendererElem, QDomDocument& doc
categoryElem.setAttribute( "width", QString::number( size.width() ) );
categoryElem.setAttribute( "height", QString::number( size.height() ) );
categoryElem.setAttribute( "penColor", penColor.name() );
categoryElem.setAttribute( "penAlpha", penColor.alpha() );
categoryElem.setAttribute( "penWidth", QString::number( penWidth ) );
categoryElem.setAttribute( "minScaleDenominator", QString::number( minScaleDenominator ) );
categoryElem.setAttribute( "maxScaleDenominator", QString::number( maxScaleDenominator ) );
Expand Down

0 comments on commit 0eab969

Please sign in to comment.