26#include <QFileInfoList>
30using namespace Qt::StringLiterals;
34 qDeleteAll( mColorSchemeList );
35 mColorSchemeList.clear();
44 QList< QgsColorScheme * >::iterator it = schemeList.begin();
45 for ( ; it != schemeList.end(); ++it )
63 if ( QFileInfo::exists( stylePalette ) )
76 if ( !localDir.mkpath( palettesDir ) )
81 const QFileInfoList fileInfoList = QDir( palettesDir ).entryInfoList( QStringList( u
"*.gpl"_s ), QDir::Files );
82 QFileInfoList::const_iterator infoIt = fileInfoList.constBegin();
83 for ( ; infoIt != fileInfoList.constEnd(); ++infoIt )
91 mColorSchemeList.append( scheme );
96 QList< QgsColorScheme * > allSchemes;
97 QList<QgsColorScheme *>::const_iterator schemeIt;
98 for ( schemeIt = mColorSchemeList.constBegin(); schemeIt != mColorSchemeList.constEnd(); ++schemeIt )
100 allSchemes.append( ( *schemeIt ) );
107 QList< QgsColorScheme * > matchingSchemes;
108 QList<QgsColorScheme *>::const_iterator schemeIt;
109 for ( schemeIt = mColorSchemeList.constBegin(); schemeIt != mColorSchemeList.constEnd(); ++schemeIt )
111 if ( ( *schemeIt )->flags().testFlag( flag ) )
113 matchingSchemes.append( ( *schemeIt ) );
116 return matchingSchemes;
121 mRandomStyleColorScheme = scheme;
126 if ( mRandomStyleColors.count() > 0 )
128 std::random_device rd;
129 std::mt19937 mt( rd() );
130 std::uniform_int_distribution<int> colorDist( 0, mRandomStyleColors.count() - 1 );
131 mNextRandomStyleColorIndex = colorDist( mt );
132 std::uniform_int_distribution<int> colorDir( 0, 1 );
133 mNextRandomStyleColorDirection = colorDir( mt ) == 0 ? -1 : 1;
138 mRandomStyleColors.clear();
144 return mRandomStyleColorScheme;
149 if ( mRandomStyleColors.empty() )
154 std::random_device rd;
155 std::mt19937 mt( rd() );
156 std::uniform_int_distribution<int> hueDist( 0, 359 );
157 std::uniform_int_distribution<int> satDist( 64, 255 );
158 std::uniform_int_distribution<int> valueDist( 128, 255 );
159 return QColor::fromHsv( hueDist( mt ), satDist( mt ), valueDist( mt ) );
163 static QMutex sMutex;
164 const QMutexLocker locker( &sMutex );
165 QColor res = mRandomStyleColors.at( mNextRandomStyleColorIndex ).first;
166 mNextRandomStyleColorIndex += mNextRandomStyleColorDirection;
167 if ( mNextRandomStyleColorIndex < 0 )
168 mNextRandomStyleColorIndex = mRandomStyleColors.count() - 1;
169 if ( mNextRandomStyleColorIndex >= mRandomStyleColors.count() )
170 mNextRandomStyleColorIndex = 0;
177 if ( mRandomStyleColorScheme == scheme )
179 mRandomStyleColorScheme =
nullptr;
180 mRandomStyleColors.clear();
183 if ( mColorSchemeList.indexOf( scheme ) != -1 )
185 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 ...