Skip to content
Permalink
Browse files

By default, generate new layer colors from a random selection

in a preset palette

The palette is packaged as resources/new_layer_colors.gpl

TODO: allow users to set a different palette
  • Loading branch information
nyalldawson committed Mar 12, 2018
1 parent 149b23e commit 7e6796c6571eb9660cb4ed6d2f4fdff370992de5
@@ -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();
@@ -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();
@@ -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";
@@ -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
@@ -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 )

0 comments on commit 7e6796c

Please sign in to comment.
You can’t perform that action at this time.