Skip to content

Commit a9008d0

Browse files
committed
add transparency for diagrams
1 parent ef3a086 commit a9008d0

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

src/app/qgsdiagramproperties.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
105105
QTreeWidgetItem *newItem = new QTreeWidgetItem( mAttributesTreeWidget );
106106
newItem->setText( 0, fieldIt.value().name() );
107107
newItem->setData( 0, Qt::UserRole, fieldIt.key() );
108+
newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );
108109
if ( fieldIt.value().type() != QVariant::String )
109110
{
110111
mSizeAttributeComboBox->addItem( fieldIt.value().name(), fieldIt.key() );
@@ -165,7 +166,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
165166
mDiagramFont = settingList.at( 0 ).font;
166167
QSizeF size = settingList.at( 0 ).size;
167168
mBackgroundColorButton->setColor( settingList.at( 0 ).backgroundColor );
168-
mTransparencySlider->setValue( settingList.at( 0 ).transparency * 100 / 256 );
169+
mTransparencySlider->setValue( settingList.at( 0 ).transparency );
169170
mDiagramPenColorButton->setColor( settingList.at( 0 ).penColor );
170171
mPenWidthSpinBox->setValue( settingList.at( 0 ).penWidth );
171172
mDiagramSizeSpinBox->setValue(( size.width() + size.height() ) / 2.0 );
@@ -340,7 +341,7 @@ void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( const QS
340341

341342
void QgsDiagramProperties::on_mTransparencySlider_valueChanged( int value )
342343
{
343-
mTransparencyLabel->setText( tr( "Transparency: %1%" ).arg( value ) );
344+
mTransparencyLabel->setText( tr( "Transparency: %1%" ).arg( value * 100 / 255 ) );
344345
}
345346

346347
void QgsDiagramProperties::on_mAddCategoryPushButton_clicked()
@@ -470,11 +471,15 @@ void QgsDiagramProperties::apply()
470471

471472
QgsDiagramSettings ds;
472473
ds.font = mDiagramFont;
474+
ds.transparency = mTransparencySlider->value();
475+
473476
QList<QColor> categoryColors;
474477
QList<int> categoryAttributes;
475478
for ( int i = 0; i < mDiagramAttributesTreeWidget->topLevelItemCount(); ++i )
476479
{
477-
categoryColors.append( mDiagramAttributesTreeWidget->topLevelItem( i )->background( 1 ).color() );
480+
QColor color = mDiagramAttributesTreeWidget->topLevelItem( i )->background( 1 ).color();
481+
color.setAlpha( 255 - ds.transparency );
482+
categoryColors.append( color );
478483
categoryAttributes.append( mDiagramAttributesTreeWidget->topLevelItem( i )->data( 0, Qt::UserRole ).toInt() );
479484
}
480485
ds.categoryColors = categoryColors;
@@ -517,11 +522,6 @@ void QgsDiagramProperties::apply()
517522
}
518523

519524
ds.backgroundColor = mBackgroundColorButton->color();
520-
ds.transparency = mTransparencySlider->value() * 255 / 100;
521-
foreach( QColor col, ds.categoryColors )
522-
{
523-
col.setAlpha( 255 - ds.transparency );
524-
}
525525
ds.penColor = mDiagramPenColorButton->color();
526526
ds.penColor.setAlpha( 255 - ds.transparency );
527527
ds.penWidth = mPenWidthSpinBox->value();

src/core/diagram/qgspiediagram.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,9 @@ void QgsPieDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext&
119119
for ( ; valIt != values.constEnd(); ++valIt, ++colIt )
120120
{
121121
currentAngle = *valIt / valSum * 360 * 16;
122-
QColor col = *colIt;
123-
col.setAlpha( 255 - s.transparency );
124-
mCategoryBrush.setColor( col );
122+
mCategoryBrush.setColor( *colIt );
125123
p->setBrush( mCategoryBrush );
126124
p->drawPie( baseX, baseY, w, h, totalAngle, currentAngle );
127125
totalAngle += currentAngle;
128126
}
129-
}
127+
}

src/core/qgsdiagramrendererv2.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ void QgsDiagramSettings::readXML( const QDomElement& elem )
5252
backgroundColor.setAlpha( elem.attribute( "backgroundAlpha" ).toInt() );
5353
size.setWidth( elem.attribute( "width" ).toDouble() );
5454
size.setHeight( elem.attribute( "height" ).toDouble() );
55+
transparency = elem.attribute( "transparency", "0" ).toInt();
5556
penColor.setNamedColor( elem.attribute( "penColor" ) );
57+
penColor.setAlpha( 255 - transparency );
5658
penWidth = elem.attribute( "penWidth" ).toDouble();
5759
minScaleDenominator = elem.attribute( "minScaleDenominator", "-1" ).toDouble();
5860
maxScaleDenominator = elem.attribute( "maxScaleDenominator", "-1" ).toDouble();
@@ -115,7 +117,9 @@ void QgsDiagramSettings::readXML( const QDomElement& elem )
115117
QStringList::const_iterator colorIt = colorList.constBegin();
116118
for ( ; colorIt != colorList.constEnd(); ++colorIt )
117119
{
118-
categoryColors.append( QColor( *colorIt ) );
120+
QColor newColor( *colorIt );
121+
newColor.setAlpha( 255 - transparency );
122+
categoryColors.append( QColor( newColor ) );
119123
}
120124

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

144149
// site type (mm vs. map units)
145150
if ( sizeType == MM )

src/ui/qgsdiagrampropertiesbase.ui

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
<rect>
3737
<x>0</x>
3838
<y>0</y>
39-
<width>742</width>
40-
<height>559</height>
39+
<width>720</width>
40+
<height>614</height>
4141
</rect>
4242
</property>
4343
<layout class="QVBoxLayout" name="scrollAreaLayout">
@@ -189,7 +189,7 @@
189189
</size>
190190
</property>
191191
<property name="maximum">
192-
<number>100</number>
192+
<number>255</number>
193193
</property>
194194
<property name="orientation">
195195
<enum>Qt::Horizontal</enum>
@@ -701,7 +701,7 @@
701701
<bool>true</bool>
702702
</property>
703703
<attribute name="buttonGroup">
704-
<string>mOrientationButtonGroup</string>
704+
<string notr="true">mOrientationButtonGroup</string>
705705
</attribute>
706706
</widget>
707707
</item>
@@ -711,7 +711,7 @@
711711
<string>Down</string>
712712
</property>
713713
<attribute name="buttonGroup">
714-
<string>mOrientationButtonGroup</string>
714+
<string notr="true">mOrientationButtonGroup</string>
715715
</attribute>
716716
</widget>
717717
</item>
@@ -721,7 +721,7 @@
721721
<string>Right</string>
722722
</property>
723723
<attribute name="buttonGroup">
724-
<string>mOrientationButtonGroup</string>
724+
<string notr="true">mOrientationButtonGroup</string>
725725
</attribute>
726726
</widget>
727727
</item>
@@ -731,7 +731,7 @@
731731
<string>Left</string>
732732
</property>
733733
<attribute name="buttonGroup">
734-
<string>mOrientationButtonGroup</string>
734+
<string notr="true">mOrientationButtonGroup</string>
735735
</attribute>
736736
</widget>
737737
</item>

0 commit comments

Comments
 (0)