27#include <QFileInfoList>
31using namespace Qt::StringLiterals;
35 qDeleteAll( mColorSchemeList );
36 mColorSchemeList.clear();
45 QList< QgsColorScheme * >::iterator it = schemeList.begin();
46 for ( ; it != schemeList.end(); ++it )
65 if ( QFileInfo::exists( stylePalette ) )
78 if ( !localDir.mkpath( palettesDir ) )
83 const QFileInfoList fileInfoList = QDir( palettesDir ).entryInfoList( QStringList( u
"*.gpl"_s ), QDir::Files );
84 QFileInfoList::const_iterator infoIt = fileInfoList.constBegin();
85 for ( ; infoIt != fileInfoList.constEnd(); ++infoIt )
93 mColorSchemeList.append( scheme );
98 QList< QgsColorScheme * > allSchemes;
99 QList<QgsColorScheme *>::const_iterator schemeIt;
100 for ( schemeIt = mColorSchemeList.constBegin(); schemeIt != mColorSchemeList.constEnd(); ++schemeIt )
102 allSchemes.append( ( *schemeIt ) );
109 QList< QgsColorScheme * > matchingSchemes;
110 QList<QgsColorScheme *>::const_iterator schemeIt;
111 for ( schemeIt = mColorSchemeList.constBegin(); schemeIt != mColorSchemeList.constEnd(); ++schemeIt )
113 if ( ( *schemeIt )->flags().testFlag( flag ) )
115 matchingSchemes.append( ( *schemeIt ) );
118 return matchingSchemes;
123 mRandomStyleColorScheme = scheme;
128 if ( mRandomStyleColors.count() > 0 )
130 std::random_device rd;
131 std::mt19937 mt( rd() );
132 std::uniform_int_distribution<int> colorDist( 0, mRandomStyleColors.count() - 1 );
133 mNextRandomStyleColorIndex = colorDist( mt );
134 std::uniform_int_distribution<int> colorDir( 0, 1 );
135 mNextRandomStyleColorDirection = colorDir( mt ) == 0 ? -1 : 1;
140 mRandomStyleColors.clear();
146 return mRandomStyleColorScheme;
151 if ( mRandomStyleColors.empty() )
156 std::random_device rd;
157 std::mt19937 mt( rd() );
158 std::uniform_int_distribution<int> hueDist( 0, 359 );
159 std::uniform_int_distribution<int> satDist( 64, 255 );
160 std::uniform_int_distribution<int> valueDist( 128, 255 );
161 return QColor::fromHsv( hueDist( mt ), satDist( mt ), valueDist( mt ) );
165 static QMutex sMutex;
166 const QMutexLocker locker( &sMutex );
167 QColor res = mRandomStyleColors.at( mNextRandomStyleColorIndex ).first;
168 mNextRandomStyleColorIndex += mNextRandomStyleColorDirection;
169 if ( mNextRandomStyleColorIndex < 0 )
170 mNextRandomStyleColorIndex = mRandomStyleColors.count() - 1;
171 if ( mNextRandomStyleColorIndex >= mRandomStyleColors.count() )
172 mNextRandomStyleColorIndex = 0;
179 if ( project == mProject )
184 QList< QgsProjectColorScheme * > existingSchemes;
186 const bool hadScheme = !existingSchemes.isEmpty();
193 if ( mProject && hadScheme )
199 if ( mRandomStyleColorScheme == scheme )
201 mRandomStyleColorScheme =
nullptr;
202 mRandomStyleColors.clear();
205 if ( mColorSchemeList.indexOf( scheme ) != -1 )
207 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 setProject(QgsProject *project)
Sets the project associated with the registry, used to provide the "Project colors" scheme.
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.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
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 ...