diff --git a/python/core/qgscolorschemeregistry.sip.in b/python/core/qgscolorschemeregistry.sip.in index 3d207247692..a2356923836 100644 --- a/python/core/qgscolorschemeregistry.sip.in +++ b/python/core/qgscolorschemeregistry.sip.in @@ -50,6 +50,13 @@ Adds all default color schemes to this color scheme. .. seealso:: :py:func:`addColorScheme` .. seealso:: :py:func:`addUserSchemes` +%End + + void initStyleScheme(); +%Docstring +Initializes the default random style color scheme for the user. + +.. versionadded:: 3.2 %End void addUserSchemes(); diff --git a/src/core/qgsapplication.cpp b/src/core/qgsapplication.cpp index e311824daa8..574cfcea4ca 100644 --- a/src/core/qgsapplication.cpp +++ b/src/core/qgsapplication.cpp @@ -271,6 +271,9 @@ void QgsApplication::init( QString profileFolder ) // so we read actual value in main.cpp ABISYM( mMaxThreads ) = -1; + colorSchemeRegistry()->addDefaultSchemes(); + colorSchemeRegistry()->initStyleScheme(); + ABISYM( mInitialized ) = true; } @@ -1718,7 +1721,6 @@ QgsApplication::ApplicationMembers::ApplicationMembers() mFieldFormatterRegistry = new QgsFieldFormatterRegistry(); mSvgCache = new QgsSvgCache(); mColorSchemeRegistry = new QgsColorSchemeRegistry(); - mColorSchemeRegistry->addDefaultSchemes(); mPaintEffectRegistry = new QgsPaintEffectRegistry(); mSymbolLayerRegistry = new QgsSymbolLayerRegistry(); mRendererRegistry = new QgsRendererRegistry(); diff --git a/src/core/qgscolorschemeregistry.cpp b/src/core/qgscolorschemeregistry.cpp index a360bb86f77..8608b0c6009 100644 --- a/src/core/qgscolorschemeregistry.cpp +++ b/src/core/qgscolorschemeregistry.cpp @@ -51,6 +51,17 @@ void QgsColorSchemeRegistry::addDefaultSchemes() addUserSchemes(); } +void QgsColorSchemeRegistry::initStyleScheme() +{ + QString stylePalette = QgsApplication::pkgDataPath() + QStringLiteral( "/resources/new_layer_colors.gpl" ); + if ( QFileInfo::exists( stylePalette ) ) + { + QgsUserColorScheme *scheme = new QgsUserColorScheme( stylePalette ); + addColorScheme( scheme ); + setRandomStyleColorScheme( scheme ); + } +} + void QgsColorSchemeRegistry::addUserSchemes() { QString palettesDir = QgsApplication::qgisSettingsDirPath() + "/palettes"; diff --git a/src/core/qgscolorschemeregistry.h b/src/core/qgscolorschemeregistry.h index e08f8c6a7dc..b17a5b2bbda 100644 --- a/src/core/qgscolorschemeregistry.h +++ b/src/core/qgscolorschemeregistry.h @@ -58,6 +58,12 @@ class CORE_EXPORT QgsColorSchemeRegistry */ void addDefaultSchemes(); + /** + * Initializes the default random style color scheme for the user. + * \since QGIS 3.2 + */ + void initStyleScheme(); + /** * Creates schemes for all gpl palettes in the user's palettes folder. * \see populateFromInstance diff --git a/tests/src/core/testqgscolorschemeregistry.cpp b/tests/src/core/testqgscolorschemeregistry.cpp index 8a9e4a25316..e895f720419 100644 --- a/tests/src/core/testqgscolorschemeregistry.cpp +++ b/tests/src/core/testqgscolorschemeregistry.cpp @@ -104,7 +104,8 @@ class TestQgsColorSchemeRegistry : public QObject void TestQgsColorSchemeRegistry::initTestCase() { - + QgsApplication::init(); + QgsApplication::initQgis(); } void TestQgsColorSchemeRegistry::cleanupTestCase() @@ -249,6 +250,8 @@ void TestQgsColorSchemeRegistry::fetchRandomStyleColor() QVERIFY( registry->fetchRandomStyleColor().isValid() ); } + // we expect the default application color scheme registry to have a randomStyleColorScheme set + QVERIFY( QgsApplication::colorSchemeRegistry()->randomStyleColorScheme() ); } QGSTEST_MAIN( TestQgsColorSchemeRegistry )