@@ -1945,31 +1945,46 @@ void TestQgsLayoutItem::opacity()
1945
1945
{
1946
1946
QgsProject proj;
1947
1947
QgsLayout l ( &proj );
1948
+ l.initializeDefaults ();
1949
+
1950
+ QgsSimpleFillSymbolLayer *simpleFill = new QgsSimpleFillSymbolLayer ();
1951
+ QgsFillSymbol *fillSymbol = new QgsFillSymbol ();
1952
+ fillSymbol->changeSymbolLayer ( 0 , simpleFill );
1953
+ simpleFill->setColor ( QColor ( 255 , 150 , 0 ) );
1954
+ simpleFill->setStrokeColor ( Qt::black );
1948
1955
1949
1956
QgsLayoutItemShape *item = new QgsLayoutItemShape ( &l );
1957
+ item->setShapeType ( QgsLayoutItemShape::Rectangle );
1958
+ item->attemptSetSceneRect ( QRectF ( 50 , 50 , 150 , 100 ) );
1959
+ item->setSymbol ( fillSymbol->clone () );
1960
+
1950
1961
l.addLayoutItem ( item );
1951
1962
1952
1963
item->setItemOpacity ( 0.75 );
1953
1964
QCOMPARE ( item->itemOpacity (), 0.75 );
1954
- QCOMPARE ( item->opacity (), 0.75 );
1965
+
1966
+ // we handle opacity ourselves, so QGraphicsItem opacity should never be set
1967
+ QCOMPARE ( item->opacity (), 1.0 );
1968
+
1969
+ QgsLayoutChecker checker ( QStringLiteral ( " composereffects_transparency75" ), &l );
1970
+ checker.setControlPathPrefix ( QStringLiteral ( " composer_effects" ) );
1971
+ QVERIFY ( checker.testLayout ( mReport ) );
1955
1972
1956
1973
item->dataDefinedProperties ().setProperty ( QgsLayoutObject::Opacity, QgsProperty::fromExpression ( " 35" ) );
1957
1974
item->refreshDataDefinedProperty ();
1958
1975
QCOMPARE ( item->itemOpacity (), 0.75 ); // should not change
1959
- QCOMPARE ( item->opacity (), 0.35 );
1976
+ QCOMPARE ( item->opacity (), 1.0 );
1960
1977
1978
+ checker = QgsLayoutChecker ( QStringLiteral ( " composereffects_transparency35" ), &l );
1979
+ checker.setControlPathPrefix ( QStringLiteral ( " composer_effects" ) );
1980
+ QVERIFY ( checker.testLayout ( mReport ) );
1961
1981
1962
1982
QgsLayout l2 ( QgsProject::instance () );
1963
1983
l2.initializeDefaults ();
1964
1984
QgsLayoutItemShape *mComposerRect1 = new QgsLayoutItemShape ( &l2 );
1965
1985
mComposerRect1 ->attemptSetSceneRect ( QRectF ( 20 , 20 , 150 , 100 ) );
1966
1986
mComposerRect1 ->setShapeType ( QgsLayoutItemShape::Rectangle );
1967
- QgsSimpleFillSymbolLayer *simpleFill = new QgsSimpleFillSymbolLayer ();
1968
- QgsFillSymbol *fillSymbol = new QgsFillSymbol ();
1969
- fillSymbol->changeSymbolLayer ( 0 , simpleFill );
1970
- simpleFill->setColor ( QColor ( 255 , 150 , 0 ) );
1971
- simpleFill->setStrokeColor ( Qt::black );
1972
- mComposerRect1 ->setSymbol ( fillSymbol );
1987
+ mComposerRect1 ->setSymbol ( fillSymbol->clone () );
1973
1988
delete fillSymbol;
1974
1989
1975
1990
l2.addLayoutItem ( mComposerRect1 );
@@ -1987,7 +2002,7 @@ void TestQgsLayoutItem::opacity()
1987
2002
1988
2003
mComposerRect2 ->setItemOpacity ( 0.5 );
1989
2004
1990
- QgsLayoutChecker checker ( QStringLiteral ( " composereffects_transparency" ), &l2 );
2005
+ checker = QgsLayoutChecker ( QStringLiteral ( " composereffects_transparency" ), &l2 );
1991
2006
checker.setControlPathPrefix ( QStringLiteral ( " composer_effects" ) );
1992
2007
QVERIFY ( checker.testLayout ( mReport ) );
1993
2008
}
0 commit comments