Skip to content

Commit 052b5d3

Browse files
committedMay 29, 2017
Flip QgsDiagramSettings from transparency to opacity
1 parent ac39320 commit 052b5d3

File tree

6 files changed

+85
-48
lines changed

6 files changed

+85
-48
lines changed
 

‎doc/api_break.dox

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,8 @@ QgsDiagramSettings {#qgis_api_break_3_0_QgsDiagramSettings}
10091009

10101010
- The SizeType enum was removed. Use QgsUnitTypes.RenderUnit instead.
10111011
- readXml() and writeXml() do not take QgsVectorLayer as an argument anymore.
1012+
- transparency was removed. Use opacity instead.
1013+
10121014

10131015
QgsDial {#qgis_api_break_3_0_QgsDial}
10141016
-------

‎python/core/qgsdiagramrenderer.sip

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,12 @@ class QgsDiagramSettings
358358
LabelPlacementMethod labelPlacementMethod;
359359
DiagramOrientation diagramOrientation;
360360
double barWidth;
361-
int transparency; // 0 - 100
361+
362+
double opacity;
363+
%Docstring
364+
Opacity, from 0 (transparent) to 1.0 (opaque)
365+
%End
366+
362367
bool scaleByArea;
363368
int angleOffset;
364369

‎src/app/qgsdiagramproperties.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
9494
mDiagramPenColorButton->setContext( QStringLiteral( "symbology" ) );
9595
mDiagramPenColorButton->setShowNoColor( true );
9696
mDiagramPenColorButton->setNoColorString( tr( "Transparent stroke" ) );
97+
mOpacitySpinBox->setClearValue( 100.0 );
9798

9899
mMaxValueSpinBox->setShowClearButton( false );
99100

@@ -261,8 +262,8 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
261262
mDiagramFont = settingList.at( 0 ).font;
262263
QSizeF size = settingList.at( 0 ).size;
263264
mBackgroundColorButton->setColor( settingList.at( 0 ).backgroundColor );
264-
mTransparencySpinBox->setValue( settingList.at( 0 ).transparency * 100.0 / 255.0 );
265-
mTransparencySlider->setValue( mTransparencySpinBox->value() );
265+
mOpacitySpinBox->setValue( settingList.at( 0 ).opacity * 100.0 );
266+
mOpacitySlider->setValue( mOpacitySpinBox->value() * 10 );
266267
mDiagramPenColorButton->setColor( settingList.at( 0 ).penColor );
267268
mPenWidthSpinBox->setValue( settingList.at( 0 ).penWidth );
268269
mDiagramSizeSpinBox->setValue( ( size.width() + size.height() ) / 2.0 );
@@ -404,8 +405,8 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
404405
}
405406

406407
connect( mAddAttributeExpression, &QPushButton::clicked, this, &QgsDiagramProperties::showAddAttributeExpressionDialog );
407-
connect( mTransparencySlider, &QSlider::valueChanged, mTransparencySpinBox, &QgsSpinBox::setValue );
408-
connect( mTransparencySpinBox, static_cast < void ( QgsSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), mTransparencySlider, &QSlider::setValue );
408+
connect( mOpacitySlider, &QSlider::valueChanged, this, [ = ]( int value ) { mOpacitySpinBox->setValue( value / 10.0 ); } );
409+
connect( mOpacitySpinBox, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double value ) { mOpacitySlider->setValue( value * 10 ); } );
409410

410411
registerDataDefinedButton( mBackgroundColorDDBtn, QgsDiagramLayerSettings::BackgroundColor );
411412
registerDataDefinedButton( mLineColorDDBtn, QgsDiagramLayerSettings::StrokeColor );
@@ -738,7 +739,7 @@ void QgsDiagramProperties::apply()
738739
QgsDiagramSettings ds;
739740
ds.enabled = ( mDiagramTypeComboBox->currentIndex() != 0 );
740741
ds.font = mDiagramFont;
741-
ds.transparency = mTransparencySpinBox->value() * 255.0 / 100.0;
742+
ds.opacity = mOpacitySpinBox->value() / 100.0;
742743

743744
QList<QColor> categoryColors;
744745
QList<QString> categoryAttributes;
@@ -749,7 +750,7 @@ void QgsDiagramProperties::apply()
749750
for ( int i = 0; i < mDiagramAttributesTreeWidget->topLevelItemCount(); ++i )
750751
{
751752
QColor color = mDiagramAttributesTreeWidget->topLevelItem( i )->background( 1 ).color();
752-
color.setAlpha( 255 - ds.transparency );
753+
color.setAlphaF( ds.opacity );
753754
categoryColors.append( color );
754755
categoryAttributes.append( mDiagramAttributesTreeWidget->topLevelItem( i )->data( 0, RoleAttributeExpression ).toString() );
755756
categoryLabels.append( mDiagramAttributesTreeWidget->topLevelItem( i )->text( 2 ) );

‎src/core/qgsdiagramrenderer.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,15 @@ void QgsDiagramSettings::readXml( const QDomElement &elem )
174174
backgroundColor.setAlpha( elem.attribute( QStringLiteral( "backgroundAlpha" ) ).toInt() );
175175
size.setWidth( elem.attribute( QStringLiteral( "width" ) ).toDouble() );
176176
size.setHeight( elem.attribute( QStringLiteral( "height" ) ).toDouble() );
177-
transparency = elem.attribute( QStringLiteral( "transparency" ), QStringLiteral( "0" ) ).toInt();
177+
if ( elem.hasAttribute( QStringLiteral( "transparency" ) ) )
178+
{
179+
opacity = 1 - elem.attribute( QStringLiteral( "transparency" ), QStringLiteral( "0" ) ).toInt() / 255.0;
180+
}
181+
else
182+
{
183+
opacity = elem.attribute( QStringLiteral( "opacity" ), QStringLiteral( "1.00" ) ).toDouble();
184+
}
185+
178186
penColor.setNamedColor( elem.attribute( QStringLiteral( "penColor" ) ) );
179187
int penAlpha = elem.attribute( QStringLiteral( "penAlpha" ), QStringLiteral( "255" ) ).toInt();
180188
penColor.setAlpha( penAlpha );
@@ -261,7 +269,7 @@ void QgsDiagramSettings::readXml( const QDomElement &elem )
261269
{
262270
QDomElement attrElem = attributes.at( i ).toElement();
263271
QColor newColor( attrElem.attribute( QStringLiteral( "color" ) ) );
264-
newColor.setAlpha( 255 - transparency );
272+
newColor.setAlphaF( opacity );
265273
categoryColors.append( newColor );
266274
categoryAttributes.append( attrElem.attribute( QStringLiteral( "field" ) ) );
267275
categoryLabels.append( attrElem.attribute( QStringLiteral( "label" ) ) );
@@ -280,7 +288,7 @@ void QgsDiagramSettings::readXml( const QDomElement &elem )
280288
for ( ; colorIt != colorList.constEnd(); ++colorIt )
281289
{
282290
QColor newColor( *colorIt );
283-
newColor.setAlpha( 255 - transparency );
291+
newColor.setAlphaF( opacity );
284292
categoryColors.append( QColor( newColor ) );
285293
}
286294

@@ -311,7 +319,7 @@ void QgsDiagramSettings::writeXml( QDomElement &rendererElem, QDomDocument &doc
311319
categoryElem.setAttribute( QStringLiteral( "scaleBasedVisibility" ), scaleBasedVisibility );
312320
categoryElem.setAttribute( QStringLiteral( "minScaleDenominator" ), QString::number( minScaleDenominator ) );
313321
categoryElem.setAttribute( QStringLiteral( "maxScaleDenominator" ), QString::number( maxScaleDenominator ) );
314-
categoryElem.setAttribute( QStringLiteral( "transparency" ), QString::number( transparency ) );
322+
categoryElem.setAttribute( QStringLiteral( "opacity" ), QString::number( opacity ) );
315323

316324
//diagram size unit type and scale
317325
categoryElem.setAttribute( QStringLiteral( "sizeType" ), QgsUnitTypes::encodeUnit( sizeType ) );

‎src/core/qgsdiagramrenderer.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class CORE_EXPORT QgsDiagramSettings
372372
, labelPlacementMethod( QgsDiagramSettings::Height )
373373
, diagramOrientation( QgsDiagramSettings::Up )
374374
, barWidth( 5.0 )
375-
, transparency( 0 )
375+
, opacity( 1.0 )
376376
, scaleByArea( true )
377377
, angleOffset( 90 * 16 ) //top
378378
, scaleBasedVisibility( false )
@@ -413,7 +413,10 @@ class CORE_EXPORT QgsDiagramSettings
413413
LabelPlacementMethod labelPlacementMethod;
414414
DiagramOrientation diagramOrientation;
415415
double barWidth;
416-
int transparency; // 0 - 100
416+
417+
//! Opacity, from 0 (transparent) to 1.0 (opaque)
418+
double opacity;
419+
417420
bool scaleByArea;
418421
int angleOffset;
419422

‎src/ui/qgsdiagrampropertiesbase.ui

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
<item>
268268
<widget class="QStackedWidget" name="mDiagramStackedWidget">
269269
<property name="currentIndex">
270-
<number>0</number>
270+
<number>1</number>
271271
</property>
272272
<widget class="QWidget" name="mDiagramPage_Attributes">
273273
<layout class="QVBoxLayout" name="verticalLayout_9">
@@ -539,7 +539,7 @@
539539
<rect>
540540
<x>0</x>
541541
<y>0</y>
542-
<width>340</width>
542+
<width>630</width>
543543
<height>484</height>
544544
</rect>
545545
</property>
@@ -595,14 +595,14 @@
595595
</size>
596596
</property>
597597
<property name="text">
598-
<string>Transparency</string>
598+
<string>Opacity</string>
599599
</property>
600600
</widget>
601601
</item>
602602
<item row="0" column="1" colspan="2">
603603
<layout class="QHBoxLayout" name="horizontalLayout_5">
604604
<item>
605-
<widget class="QSlider" name="mTransparencySlider">
605+
<widget class="QSlider" name="mOpacitySlider">
606606
<property name="enabled">
607607
<bool>true</bool>
608608
</property>
@@ -619,15 +619,24 @@
619619
</size>
620620
</property>
621621
<property name="maximum">
622+
<number>1000</number>
623+
</property>
624+
<property name="singleStep">
625+
<number>10</number>
626+
</property>
627+
<property name="pageStep">
622628
<number>100</number>
623629
</property>
630+
<property name="value">
631+
<number>1000</number>
632+
</property>
624633
<property name="orientation">
625634
<enum>Qt::Horizontal</enum>
626635
</property>
627636
</widget>
628637
</item>
629638
<item>
630-
<widget class="QgsSpinBox" name="mTransparencySpinBox">
639+
<widget class="QgsDoubleSpinBox" name="mOpacitySpinBox">
631640
<property name="enabled">
632641
<bool>true</bool>
633642
</property>
@@ -637,11 +646,20 @@
637646
<verstretch>0</verstretch>
638647
</sizepolicy>
639648
</property>
649+
<property name="minimumSize">
650+
<size>
651+
<width>100</width>
652+
<height>0</height>
653+
</size>
654+
</property>
640655
<property name="suffix">
641656
<string> %</string>
642657
</property>
643-
<property name="maximum">
644-
<number>100</number>
658+
<property name="decimals">
659+
<number>1</number>
660+
</property>
661+
<property name="value">
662+
<double>100.000000000000000</double>
645663
</property>
646664
</widget>
647665
</item>
@@ -2169,35 +2187,17 @@
21692187
</layout>
21702188
</widget>
21712189
<customwidgets>
2172-
<customwidget>
2173-
<class>QgsScrollArea</class>
2174-
<extends>QScrollArea</extends>
2175-
<header>qgsscrollarea.h</header>
2176-
<container>1</container>
2177-
</customwidget>
2178-
<customwidget>
2179-
<class>QgsCollapsibleGroupBox</class>
2180-
<extends>QGroupBox</extends>
2181-
<header>qgscollapsiblegroupbox.h</header>
2182-
<container>1</container>
2183-
</customwidget>
2184-
<customwidget>
2185-
<class>QgsFieldExpressionWidget</class>
2186-
<extends>QWidget</extends>
2187-
<header>qgsfieldexpressionwidget.h</header>
2188-
<container>1</container>
2189-
</customwidget>
2190-
<customwidget>
2191-
<class>QgsScaleRangeWidget</class>
2192-
<extends>QWidget</extends>
2193-
<header>qgsscalerangewidget.h</header>
2194-
</customwidget>
21952190
<customwidget>
21962191
<class>QgsColorButton</class>
21972192
<extends>QToolButton</extends>
21982193
<header>qgscolorbutton.h</header>
21992194
<container>1</container>
22002195
</customwidget>
2196+
<customwidget>
2197+
<class>QgsPropertyOverrideButton</class>
2198+
<extends>QToolButton</extends>
2199+
<header>qgspropertyoverridebutton.h</header>
2200+
</customwidget>
22012201
<customwidget>
22022202
<class>QgsDoubleSpinBox</class>
22032203
<extends>QDoubleSpinBox</extends>
@@ -2209,16 +2209,34 @@
22092209
<header>qgsspinbox.h</header>
22102210
</customwidget>
22112211
<customwidget>
2212-
<class>QgsPropertyOverrideButton</class>
2213-
<extends>QToolButton</extends>
2214-
<header>qgspropertyoverridebutton.h</header>
2212+
<class>QgsCollapsibleGroupBox</class>
2213+
<extends>QGroupBox</extends>
2214+
<header>qgscollapsiblegroupbox.h</header>
2215+
<container>1</container>
22152216
</customwidget>
22162217
<customwidget>
22172218
<class>QgsUnitSelectionWidget</class>
22182219
<extends>QWidget</extends>
22192220
<header>qgsunitselectionwidget.h</header>
22202221
<container>1</container>
22212222
</customwidget>
2223+
<customwidget>
2224+
<class>QgsScrollArea</class>
2225+
<extends>QScrollArea</extends>
2226+
<header>qgsscrollarea.h</header>
2227+
<container>1</container>
2228+
</customwidget>
2229+
<customwidget>
2230+
<class>QgsFieldExpressionWidget</class>
2231+
<extends>QWidget</extends>
2232+
<header>qgsfieldexpressionwidget.h</header>
2233+
<container>1</container>
2234+
</customwidget>
2235+
<customwidget>
2236+
<class>QgsScaleRangeWidget</class>
2237+
<extends>QWidget</extends>
2238+
<header>qgsscalerangewidget.h</header>
2239+
</customwidget>
22222240
</customwidgets>
22232241
<tabstops>
22242242
<tabstop>mDiagramTypeComboBox</tabstop>
@@ -2231,8 +2249,8 @@
22312249
<tabstop>mRemoveCategoryPushButton</tabstop>
22322250
<tabstop>mDiagramAttributesTreeWidget</tabstop>
22332251
<tabstop>scrollArea_4</tabstop>
2234-
<tabstop>mTransparencySlider</tabstop>
2235-
<tabstop>mTransparencySpinBox</tabstop>
2252+
<tabstop>mOpacitySlider</tabstop>
2253+
<tabstop>mOpacitySpinBox</tabstop>
22362254
<tabstop>mBarWidthSpinBox</tabstop>
22372255
<tabstop>mBackgroundColorButton</tabstop>
22382256
<tabstop>mDiagramPenColorButton</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.