Skip to content

Commit

Permalink
feat(CMYK): Convert new color to project color model
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 authored and nyalldawson committed Aug 20, 2024
1 parent eac7f1a commit c7120cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/core/symbology/qgssymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,16 @@ QgsSymbol *QgsSymbol::defaultSymbol( Qgis::GeometryType geomType )
s->setColor( QgsApplication::colorSchemeRegistry()->fetchRandomStyleColor() );
}

const bool isCmyk = QgsProject::instance()->styleSettings() && QgsProject::instance()->styleSettings()->colorModel() == Qgis::ColorModel::Cmyk;
if ( s->color().spec() == QColor::Spec::Rgb && isCmyk )
{
s->setColor( s->color().toCmyk() );
}
else if ( s->color().spec() == QColor::Spec::Cmyk && !isCmyk )
{
s->setColor( s->color().toRgb() );
}

return s.release();
}

Expand Down
9 changes: 9 additions & 0 deletions tests/src/python/test_qgssymbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,15 @@ def renderGeometry(self, symbol, geom):

return image

def testDefaultSymbolColor(self):
s1 = QgsSymbol.defaultSymbol(Qgis.GeometryType.Point)
self.assertEqual(s1.color().spec(), QColor.Spec.Rgb)

self.assertTrue(QgsProject.instance().styleSettings())
QgsProject.instance().styleSettings().setColorModel(Qgis.ColorModel.Cmyk)
s1 = QgsSymbol.defaultSymbol(Qgis.GeometryType.Point)
self.assertEqual(s1.color().spec(), QColor.Spec.Cmyk)


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

0 comments on commit c7120cf

Please sign in to comment.