Skip to content
Permalink
Browse files

add transparency for diagrams

  • Loading branch information
m-kuhn committed Aug 15, 2012
1 parent ef3a086 commit a9008d0c8339ea1a6a043279d7c57431859077d4
@@ -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() );
@@ -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 );
@@ -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()
@@ -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;
@@ -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();
@@ -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;
}
}
}
@@ -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();
@@ -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
@@ -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 )
@@ -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">
@@ -189,7 +189,7 @@
</size>
</property>
<property name="maximum">
<number>100</number>
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -701,7 +701,7 @@
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
@@ -711,7 +711,7 @@
<string>Down</string>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
@@ -721,7 +721,7 @@
<string>Right</string>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
@@ -731,7 +731,7 @@
<string>Left</string>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>

0 comments on commit a9008d0

Please sign in to comment.
You can’t perform that action at this time.