26#include <QFileInfoList>
31 qDeleteAll( mColorSchemeList );
32 mColorSchemeList.clear();
41 QList< QgsColorScheme * >::iterator it = schemeList.begin();
42 for ( ; it != schemeList.end(); ++it )
60 if ( QFileInfo::exists( stylePalette ) )
73 if ( !localDir.mkpath( palettesDir ) )
78 const QFileInfoList fileInfoList = QDir( palettesDir ).entryInfoList( QStringList( QStringLiteral(
"*.gpl" ) ), QDir::Files );
79 QFileInfoList::const_iterator infoIt = fileInfoList.constBegin();
80 for ( ; infoIt != fileInfoList.constEnd(); ++infoIt )
88 mColorSchemeList.append( scheme );
93 QList< QgsColorScheme * > allSchemes;
94 QList<QgsColorScheme *>::const_iterator schemeIt;
95 for ( schemeIt = mColorSchemeList.constBegin(); schemeIt != mColorSchemeList.constEnd(); ++schemeIt )
97 allSchemes.append( ( *schemeIt ) );
104 QList< QgsColorScheme * > matchingSchemes;
105 QList<QgsColorScheme *>::const_iterator schemeIt;
106 for ( schemeIt = mColorSchemeList.constBegin(); schemeIt != mColorSchemeList.constEnd(); ++schemeIt )
108 if ( ( *schemeIt )->flags().testFlag( flag ) )
110 matchingSchemes.append( ( *schemeIt ) );
113 return matchingSchemes;
118 mRandomStyleColorScheme = scheme;
123 if ( mRandomStyleColors.count() > 0 )
125 std::random_device rd;
126 std::mt19937 mt( rd() );
127 std::uniform_int_distribution<int> colorDist( 0, mRandomStyleColors.count() - 1 );
128 mNextRandomStyleColorIndex = colorDist( mt );
129 std::uniform_int_distribution<int> colorDir( 0, 1 );
130 mNextRandomStyleColorDirection = colorDir( mt ) == 0 ? -1 : 1;
135 mRandomStyleColors.clear();
141 return mRandomStyleColorScheme;
146 if ( mRandomStyleColors.empty() )
151 std::random_device rd;
152 std::mt19937 mt( rd() );
153 std::uniform_int_distribution<int> hueDist( 0, 359 );
154 std::uniform_int_distribution<int> satDist( 64, 255 );
155 std::uniform_int_distribution<int> valueDist( 128, 255 );
156 return QColor::fromHsv( hueDist( mt ), satDist( mt ), valueDist( mt ) );
160 static QMutex sMutex;
161 const QMutexLocker locker( &sMutex );
162 QColor res = mRandomStyleColors.at( mNextRandomStyleColorIndex ).first;
163 mNextRandomStyleColorIndex += mNextRandomStyleColorDirection;
164 if ( mNextRandomStyleColorIndex < 0 )
165 mNextRandomStyleColorIndex = mRandomStyleColors.count() - 1;
166 if ( mNextRandomStyleColorIndex >= mRandomStyleColors.count() )
167 mNextRandomStyleColorIndex = 0;
174 if ( mRandomStyleColorScheme == scheme )
176 mRandomStyleColorScheme =
nullptr;
177 mRandomStyleColors.clear();
180 if ( mColorSchemeList.indexOf( scheme ) != -1 )
182 mColorSchemeList.removeAll( scheme );
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes.
static QString pkgDataPath()
Returns the common root path of all application data directories.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
void addDefaultSchemes()
Adds all default color schemes to this color scheme.
void addColorScheme(QgsColorScheme *scheme)
Adds a color scheme to the registry.
QList< QgsColorScheme * > schemes() const
Returns all color schemes in the registry.
QColor fetchRandomStyleColor() const
Returns a random color for use with a new symbol style (e.g.
void populateFromInstance()
Adds all color schemes from the global instance to this color scheme.
QgsColorScheme * randomStyleColorScheme()
Returns the color scheme used when fetching random colors to use for symbol styles.
bool removeColorScheme(QgsColorScheme *scheme)
Removes all matching color schemes from the registry.
void initStyleScheme()
Initializes the default random style color scheme for the user.
void setRandomStyleColorScheme(QgsColorScheme *scheme)
Sets the color scheme to use when fetching random colors to use for symbol styles.
void addUserSchemes()
Creates schemes for all gpl palettes in the user's palettes folder.
virtual ~QgsColorSchemeRegistry()
Abstract base class for color schemes.
SchemeFlag
Flags for controlling behavior of color scheme.
virtual QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor())=0
Gets a list of colors from the scheme.
A color scheme which contains custom colors set through QGIS app options dialog.
A color scheme which contains project specific colors set through project properties dialog.
A color scheme which contains the most recently used colors.
A color scheme which stores its colors in a gpl palette file within the "palettes" subfolder off the ...