Skip to content

Commit

Permalink
add transparency for diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 15, 2012
1 parent ef3a086 commit a9008d0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
16 changes: 8 additions & 8 deletions src/app/qgsdiagramproperties.cpp
Expand Up @@ -105,6 +105,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
QTreeWidgetItem *newItem = new QTreeWidgetItem( mAttributesTreeWidget );
newItem->setText( 0, fieldIt.value().name() );
newItem->setData( 0, Qt::UserRole, fieldIt.key() );
newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );
if ( fieldIt.value().type() != QVariant::String )
{
mSizeAttributeComboBox->addItem( fieldIt.value().name(), fieldIt.key() );
Expand Down Expand Up @@ -165,7 +166,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
mDiagramFont = settingList.at( 0 ).font;
QSizeF size = settingList.at( 0 ).size;
mBackgroundColorButton->setColor( settingList.at( 0 ).backgroundColor );
mTransparencySlider->setValue( settingList.at( 0 ).transparency * 100 / 256 );
mTransparencySlider->setValue( settingList.at( 0 ).transparency );
mDiagramPenColorButton->setColor( settingList.at( 0 ).penColor );
mPenWidthSpinBox->setValue( settingList.at( 0 ).penWidth );
mDiagramSizeSpinBox->setValue(( size.width() + size.height() ) / 2.0 );
Expand Down Expand Up @@ -340,7 +341,7 @@ void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( const QS

void QgsDiagramProperties::on_mTransparencySlider_valueChanged( int value )
{
mTransparencyLabel->setText( tr( "Transparency: %1%" ).arg( value ) );
mTransparencyLabel->setText( tr( "Transparency: %1%" ).arg( value * 100 / 255 ) );
}

void QgsDiagramProperties::on_mAddCategoryPushButton_clicked()
Expand Down Expand Up @@ -470,11 +471,15 @@ void QgsDiagramProperties::apply()

QgsDiagramSettings ds;
ds.font = mDiagramFont;
ds.transparency = mTransparencySlider->value();

QList<QColor> categoryColors;
QList<int> categoryAttributes;
for ( int i = 0; i < mDiagramAttributesTreeWidget->topLevelItemCount(); ++i )
{
categoryColors.append( mDiagramAttributesTreeWidget->topLevelItem( i )->background( 1 ).color() );
QColor color = mDiagramAttributesTreeWidget->topLevelItem( i )->background( 1 ).color();
color.setAlpha( 255 - ds.transparency );
categoryColors.append( color );
categoryAttributes.append( mDiagramAttributesTreeWidget->topLevelItem( i )->data( 0, Qt::UserRole ).toInt() );
}
ds.categoryColors = categoryColors;
Expand Down Expand Up @@ -517,11 +522,6 @@ void QgsDiagramProperties::apply()
}

ds.backgroundColor = mBackgroundColorButton->color();
ds.transparency = mTransparencySlider->value() * 255 / 100;
foreach( QColor col, ds.categoryColors )
{
col.setAlpha( 255 - ds.transparency );
}
ds.penColor = mDiagramPenColorButton->color();
ds.penColor.setAlpha( 255 - ds.transparency );
ds.penWidth = mPenWidthSpinBox->value();
Expand Down
6 changes: 2 additions & 4 deletions src/core/diagram/qgspiediagram.cpp
Expand Up @@ -119,11 +119,9 @@ void QgsPieDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext&
for ( ; valIt != values.constEnd(); ++valIt, ++colIt )
{
currentAngle = *valIt / valSum * 360 * 16;
QColor col = *colIt;
col.setAlpha( 255 - s.transparency );
mCategoryBrush.setColor( col );
mCategoryBrush.setColor( *colIt );
p->setBrush( mCategoryBrush );
p->drawPie( baseX, baseY, w, h, totalAngle, currentAngle );
totalAngle += currentAngle;
}
}
}
7 changes: 6 additions & 1 deletion src/core/qgsdiagramrendererv2.cpp
Expand Up @@ -52,7 +52,9 @@ void QgsDiagramSettings::readXML( const QDomElement& elem )
backgroundColor.setAlpha( elem.attribute( "backgroundAlpha" ).toInt() );
size.setWidth( elem.attribute( "width" ).toDouble() );
size.setHeight( elem.attribute( "height" ).toDouble() );
transparency = elem.attribute( "transparency", "0" ).toInt();
penColor.setNamedColor( elem.attribute( "penColor" ) );
penColor.setAlpha( 255 - transparency );
penWidth = elem.attribute( "penWidth" ).toDouble();
minScaleDenominator = elem.attribute( "minScaleDenominator", "-1" ).toDouble();
maxScaleDenominator = elem.attribute( "maxScaleDenominator", "-1" ).toDouble();
Expand Down Expand Up @@ -115,7 +117,9 @@ void QgsDiagramSettings::readXML( const QDomElement& elem )
QStringList::const_iterator colorIt = colorList.constBegin();
for ( ; colorIt != colorList.constEnd(); ++colorIt )
{
categoryColors.append( QColor( *colorIt ) );
QColor newColor( *colorIt );
newColor.setAlpha( 255 - transparency );
categoryColors.append( QColor( newColor ) );
}

//attribute indices
Expand All @@ -140,6 +144,7 @@ void QgsDiagramSettings::writeXML( QDomElement& rendererElem, QDomDocument& doc
categoryElem.setAttribute( "penWidth", QString::number( penWidth ) );
categoryElem.setAttribute( "minScaleDenominator", QString::number( minScaleDenominator ) );
categoryElem.setAttribute( "maxScaleDenominator", QString::number( maxScaleDenominator ) );
categoryElem.setAttribute( "transparency", QString::number( transparency ) );

// site type (mm vs. map units)
if ( sizeType == MM )
Expand Down
14 changes: 7 additions & 7 deletions src/ui/qgsdiagrampropertiesbase.ui
Expand Up @@ -36,8 +36,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>742</width>
<height>559</height>
<width>720</width>
<height>614</height>
</rect>
</property>
<layout class="QVBoxLayout" name="scrollAreaLayout">
Expand Down Expand Up @@ -189,7 +189,7 @@
</size>
</property>
<property name="maximum">
<number>100</number>
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand Down Expand Up @@ -701,7 +701,7 @@
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
Expand All @@ -711,7 +711,7 @@
<string>Down</string>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
Expand All @@ -721,7 +721,7 @@
<string>Right</string>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
Expand All @@ -731,7 +731,7 @@
<string>Left</string>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
Expand Down

0 comments on commit a9008d0

Please sign in to comment.