Skip to content

Commit

Permalink
Merge pull request #59747 from troopa81/fix_cmyk_test_qt6_8
Browse files Browse the repository at this point in the history
fix(CMYK): Fix test
  • Loading branch information
troopa81 authored Dec 9, 2024
2 parents e9138ea + 8b447f2 commit e9e7bc5
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/src/python/test_qgsprojectstylesettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Qt,
QTemporaryDir,
QTemporaryFile,
QT_VERSION,
)
from qgis.PyQt.QtGui import QColor, QColorSpace, QFont
from qgis.PyQt.QtTest import QSignalSpy
Expand Down Expand Up @@ -889,10 +890,14 @@ def testReadWrite(self):
[unitTestDataPath() + "/style1.db", unitTestDataPath() + "/style2.db"],
)

@unittest.skipIf(
QT_VERSION < 0x060800, "CMYK support was not complete before Qt 6.8.0"
)
def testColorSettings(self):
"""
Test ICC profile attachment
"""

project = QgsProject()
settings = project.styleSettings()
self.assertFalse(project.isDirty())
Expand All @@ -907,17 +912,34 @@ def testColorSettings(self):
project.setDirty(False)
self.assertEqual(settings.colorModel(), Qgis.ColorModel.Cmyk)

# set an RGB color space, reset color model to RGB
with open(os.path.join(TEST_DATA_DIR, "sRGB2014.icc"), mode="rb") as f:
colorSpace = QColorSpace.fromIccProfile(f.read())

self.assertTrue(colorSpace.isValid())

settings.setColorSpace(colorSpace)
self.assertTrue(project.isDirty())
self.assertEqual(settings.colorModel(), Qgis.ColorModel.Rgb)
self.assertTrue(settings.colorSpace().isValid())
self.assertEqual(settings.colorSpace().primaries(), QColorSpace.Primaries.SRgb)
self.assertEqual(len(project.attachedFiles()), 2)

# set a CMYK color space, reset color model to CMYK
with open(os.path.join(TEST_DATA_DIR, "CGATS21_CRPC6.icc"), mode="rb") as f:
colorSpace = QColorSpace.fromIccProfile(f.read())

self.assertTrue(colorSpace.isValid())

settings.setColorSpace(colorSpace)
self.assertTrue(project.isDirty())
self.assertEqual(settings.colorModel(), Qgis.ColorModel.Cmyk)
self.assertTrue(settings.colorSpace().isValid())
self.assertEqual(
settings.colorSpace().primaries(), QColorSpace.Primaries.Custom
)
self.assertEqual(len(project.attachedFiles()), 2)

# save and restore
projectFile = QTemporaryFile(
QDir.temp().absoluteFilePath("testCmykSettings.qgz")
Expand All @@ -930,7 +952,9 @@ def testColorSettings(self):
settings = project.styleSettings()
self.assertEqual(settings.colorModel(), Qgis.ColorModel.Cmyk)
self.assertTrue(settings.colorSpace().isValid())
self.assertEqual(settings.colorSpace().primaries(), QColorSpace.Primaries.SRgb)
self.assertEqual(
settings.colorSpace().primaries(), QColorSpace.Primaries.Custom
)
self.assertEqual(len(project.attachedFiles()), 2)

# clear color space
Expand Down

0 comments on commit e9e7bc5

Please sign in to comment.