mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
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
This commit is contained in:
parent
149b23e08b
commit
7e6796c657
@ -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 )
|
||||
|
Loading…
x
Reference in New Issue
Block a user