Skip to content

Commit

Permalink
RASTER properties dlg sync opacity
Browse files Browse the repository at this point in the history
Fixes #54496

Backported from master
  • Loading branch information
elpaso committed Oct 5, 2023
1 parent a16d558 commit e457fae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/gui/raster/qgsrasterlayerproperties.cpp
Expand Up @@ -678,6 +678,8 @@ void QgsRasterLayerProperties::sync()
if ( !provider )
return;

mRasterTransparencyWidget->syncToLayer();

if ( provider->dataType( 1 ) == Qgis::DataType::ARGB32
|| provider->dataType( 1 ) == Qgis::DataType::ARGB32_Premultiplied )
{
Expand Down
34 changes: 32 additions & 2 deletions tests/src/python/test_qgsrasterlayerproperties.py
Expand Up @@ -17,8 +17,15 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QWidget
from qgis.core import QgsMapLayer, QgsProject, QgsRasterLayer
from qgis.gui import QgsMapCanvas, QgsMapLayerConfigWidgetFactory, QgsMapLayerConfigWidget, QgsRasterLayerProperties
from qgis.testing import start_app, unittest
from qgis.gui import (
QgsMapCanvas,
QgsMapLayerConfigWidget,
QgsMapLayerConfigWidgetFactory,
QgsRasterLayerProperties,
)
import unittest
from qgis.testing import start_app, QgisTestCase
import tempfile

from utilities import unitTestDataPath

Expand Down Expand Up @@ -92,6 +99,29 @@ def createWidget(self,
self.assertEqual(MyFactory.COUNT, 1, msg='Custom QgsMapLayerConfigWidget::createWidget(...) not called')
self.assertEqual(MyWidget.COUNT, 1, msg='Custom QgsMapLayerConfigWidget::apply() not called')

def test_transparency_load(self):
"""Test issue GH #54496"""

myCanvas = QgsMapCanvas()
myPath = pathlib.Path(unitTestDataPath('raster')) / 'band1_float32_noct_epsg4326.tif'
myRasterLayer = QgsRasterLayer(myPath.as_posix(), myPath.name)

assert myRasterLayer.isValid(), f'Raster not loaded {myPath}'

dialog = QgsRasterLayerProperties(myRasterLayer, myCanvas)

with tempfile.NamedTemporaryFile(suffix='.qml') as qml_file_object:
renderer = myRasterLayer.renderer()
renderer.setOpacity(0.5)
self.assertTrue(myRasterLayer.saveNamedStyle(qml_file_object.name)[1])
myRasterLayer.loadNamedStyle(qml_file_object.name)
dialog.syncToLayer()
renderer = myRasterLayer.renderer()
self.assertEqual(renderer.opacity(), 0.5)
dialog.apply()
renderer = myRasterLayer.renderer()
self.assertEqual(renderer.opacity(), 0.5)


if __name__ == '__main__':
unittest.main()

0 comments on commit e457fae

Please sign in to comment.