mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
fix(ColorProject): Don't convert color to RGB on writing
This commit is contained in:
parent
6c2c9b7750
commit
ea05550683
@ -22,6 +22,7 @@
|
||||
#include "qgssymbollayerutils.h"
|
||||
#include "qgsapplication.h"
|
||||
#include "qgssettings.h"
|
||||
#include "qgscolorutils.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QRegularExpression>
|
||||
@ -206,7 +207,7 @@ QgsNamedColorList QgsProjectColorScheme::fetchColors( const QString &context, co
|
||||
for ( QStringList::iterator it = colorStrings.begin();
|
||||
it != colorStrings.end(); ++it )
|
||||
{
|
||||
const QColor color = QgsSymbolLayerUtils::decodeColor( *it );
|
||||
const QColor color = QgsColorUtils::colorFromString( *it );
|
||||
QString label;
|
||||
if ( colorLabels.length() > colorIndex )
|
||||
{
|
||||
|
@ -812,6 +812,7 @@ void TestQgsExpressionContext::projectScope()
|
||||
QgsNamedColorList colorList;
|
||||
colorList << qMakePair( QColor( 200, 255, 0 ), QStringLiteral( "vomit yellow" ) );
|
||||
colorList << qMakePair( QColor( 30, 60, 20 ), QStringLiteral( "murky depths of hades" ) );
|
||||
colorList << qMakePair( QColor::fromCmykF( 1., 0.9, 0.8, 0.7 ), QStringLiteral( "cmyk colors" ) );
|
||||
s.setColors( colorList );
|
||||
QgsExpressionContext contextColors;
|
||||
contextColors << QgsExpressionContextUtils::projectScope( QgsProject::instance() );
|
||||
@ -829,9 +830,10 @@ void TestQgsExpressionContext::projectScope()
|
||||
//matching color names should be case insensitive
|
||||
QgsExpression expProjectColorObjectCaseInsensitive( QStringLiteral( "project_color_object('Murky Depths of hades')" ) );
|
||||
QCOMPARE( expProjectColorObjectCaseInsensitive.evaluate( &contextColors ), QVariant( QColor::fromRgb( 30, 60, 20 ) ) );
|
||||
QgsExpression expProjectColorCmyk( QStringLiteral( "project_color_object('cmyk colors')" ) );
|
||||
QCOMPARE( expProjectColorCmyk.evaluate( &contextColors ), QVariant( QColor::fromCmykF( 1., 0.9, 0.8, 0.7 ) ) );
|
||||
QgsExpression badProjectColorObject( QStringLiteral( "project_color_object('dusk falls in san juan del sur')" ) );
|
||||
QCOMPARE( badProjectColorObject.evaluate( &contextColors ), QVariant() );
|
||||
|
||||
}
|
||||
|
||||
void TestQgsExpressionContext::layerScope()
|
||||
|
@ -45,7 +45,7 @@ from qgis.core import (
|
||||
import unittest
|
||||
from qgis.testing import start_app, QgisTestCase
|
||||
|
||||
from utilities import unitTestDataPath
|
||||
from utilities import unitTestDataPath, getTempfilePath
|
||||
|
||||
app = start_app()
|
||||
TEST_DATA_DIR = unitTestDataPath()
|
||||
@ -1610,11 +1610,15 @@ class TestQgsProject(QgisTestCase):
|
||||
def testColorScheme(self):
|
||||
p = QgsProject.instance()
|
||||
spy = QSignalSpy(p.projectColorsChanged)
|
||||
p.setProjectColors([[QColor(255, 0, 0), 'red'], [QColor(0, 255, 0), 'green']])
|
||||
p.setProjectColors([[QColor(255, 0, 0), 'red'], [QColor(0, 255, 0), 'green'], [QColor.fromCmykF(1, 0.9, 0.8, 0.7), 'TestCmyk']])
|
||||
self.assertEqual(len(spy), 1)
|
||||
scheme = [s for s in QgsApplication.colorSchemeRegistry().schemes() if isinstance(s, QgsProjectColorScheme)][0]
|
||||
self.assertEqual([[c[0].name(), c[1]] for c in scheme.fetchColors()],
|
||||
[['#ff0000', 'red'], ['#00ff00', 'green']])
|
||||
self.assertEqual([[c[0], c[1]] for c in scheme.fetchColors()],
|
||||
[[QColor(255, 0, 0), 'red'], [QColor(0, 255, 0), 'green'], [QColor.fromCmykF(1, 0.9, 0.8, 0.7), 'TestCmyk']])
|
||||
|
||||
project_filepath = getTempfilePath("qgs")
|
||||
p.write(project_filepath)
|
||||
|
||||
# except color changed signal when clearing project
|
||||
p.clear()
|
||||
self.assertEqual(len(spy), 2)
|
||||
@ -1627,6 +1631,13 @@ class TestQgsProject(QgisTestCase):
|
||||
del p
|
||||
self.assertEqual(len(spy), 0)
|
||||
|
||||
# Test that write/read doesn't convert color to RGB always
|
||||
p = QgsProject.instance()
|
||||
p.read(project_filepath)
|
||||
scheme = [s for s in QgsApplication.colorSchemeRegistry().schemes() if isinstance(s, QgsProjectColorScheme)][0]
|
||||
self.assertEqual([[c[0], c[1]] for c in scheme.fetchColors()],
|
||||
[[QColor(255, 0, 0), 'red'], [QColor(0, 255, 0), 'green'], [QColor.fromCmykF(1, 0.9, 0.8, 0.7), 'TestCmyk']])
|
||||
|
||||
def testTransformContextSignalIsEmitted(self):
|
||||
"""Test that when a project transform context changes a transformContextChanged signal is emitted"""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user