49 QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
53 const auto constRecentColorVariants = recentColorVariants;
54 for (
const QVariant &color : constRecentColorVariants )
68 if ( !color.isValid() )
74 QColor opaqueColor = color;
75 opaqueColor.setAlpha( 255 );
78 QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
81 for (
int colorIdx = recentColorVariants.length() - 1; colorIdx >= 0; --colorIdx )
83 if ( ( recentColorVariants.at( colorIdx ).value<QColor>() ).name() == opaqueColor.name() )
85 recentColorVariants.removeAt( colorIdx );
90 QVariant colorVariant = QVariant( opaqueColor );
91 recentColorVariants.prepend( colorVariant );
94 while ( recentColorVariants.count() > 20 )
96 recentColorVariants.pop_back();
99 settings.
setValue( QStringLiteral(
"colors/recent" ), recentColorVariants );
106 QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
108 if ( recentColorVariants.isEmpty() )
111 return recentColorVariants.at( 0 ).value<QColor>();
117 Q_UNUSED( baseColor )
124 if ( !settings.
contains( QStringLiteral(
"/colors/palettecolors" ) ) )
127 colorList.append( qMakePair( QColor( 0, 0, 0 ), QString() ) );
128 colorList.append( qMakePair( QColor( 255, 255, 255 ), QString() ) );
129 colorList.append( qMakePair( QColor( 166, 206, 227 ), QString() ) );
130 colorList.append( qMakePair( QColor( 31, 120, 180 ), QString() ) );
131 colorList.append( qMakePair( QColor( 178, 223, 138 ), QString() ) );
132 colorList.append( qMakePair( QColor( 51, 160, 44 ), QString() ) );
133 colorList.append( qMakePair( QColor( 251, 154, 153 ), QString() ) );
134 colorList.append( qMakePair( QColor( 227, 26, 28 ), QString() ) );
135 colorList.append( qMakePair( QColor( 253, 191, 111 ), QString() ) );
136 colorList.append( qMakePair( QColor( 255, 127, 0 ), QString() ) );
141 QList< QVariant > customColorVariants = settings.
value( QStringLiteral(
"colors/palettecolors" ) ).toList();
142 QList< QVariant > customColorLabels = settings.
value( QStringLiteral(
"colors/palettelabels" ) ).toList();
146 for ( QList< QVariant >::iterator it = customColorVariants.begin();
147 it != customColorVariants.end(); ++it )
149 QColor color = ( *it ).value<QColor>();
151 if ( customColorLabels.length() > colorIndex )
153 label = customColorLabels.at( colorIndex ).toString();
156 colorList.append( qMakePair( color, label ) );
166 Q_UNUSED( baseColor )
170 QList< QVariant > customColors;
171 QList< QVariant > customColorLabels;
173 QgsNamedColorList::const_iterator colorIt = colors.constBegin();
174 for ( ; colorIt != colors.constEnd(); ++colorIt )
176 QVariant color = ( *colorIt ).first;
177 QVariant label = ( *colorIt ).second;
178 customColors.append( color );
179 customColorLabels.append( label );
181 settings.
setValue( QStringLiteral(
"colors/palettecolors" ), customColors );
182 settings.
setValue( QStringLiteral(
"colors/palettelabels" ), customColorLabels );
195 Q_UNUSED( baseColor )
204 for ( QStringList::iterator it = colorStrings.begin();
205 it != colorStrings.end(); ++it )
209 if ( colorLabels.length() > colorIndex )
211 label = colorLabels.at( colorIndex );
214 colorList.append( qMakePair( color, label ) );
224 Q_UNUSED( baseColor )
242 Q_UNUSED( baseColor )
244 QString sourceFilePath = gplFilePath();
245 if ( sourceFilePath.isEmpty() )
253 QFile sourceFile( sourceFilePath );
260 Q_UNUSED( baseColor )
262 QString destFilePath = gplFilePath();
263 if ( destFilePath.isEmpty() )
268 QFile destFile( destFilePath );
290 : mFilename( filename )
295 if ( sourceFile.open( QIODevice::ReadOnly ) )
297 QTextStream in( &sourceFile );
301 while ( !in.atEnd() && !line.startsWith( QLatin1String(
"Name:" ) ) )
303 line = in.readLine();
307 QRegExp rx(
"Name:\\s*(\\S.*)$" );
308 if ( rx.indexIn( line ) != -1 )
314 if (
mName.isEmpty() )
323 mEditable = !sourceFileInfo.exists() || sourceFileInfo.isWritable();
341 QStringList showInMenuSchemes = s.
value( QStringLiteral(
"/colors/showInMenuList" ) ).toStringList();
343 if ( showInMenuSchemes.contains(
mName ) )
354 if ( filePath.isEmpty() )
360 return QFile::remove( filePath );
366 QStringList showInMenuSchemes = s.
value( QStringLiteral(
"/colors/showInMenuList" ) ).toStringList();
368 if ( show && !showInMenuSchemes.contains(
mName ) )
370 showInMenuSchemes <<
mName;
372 else if ( !show && showInMenuSchemes.contains(
mName ) )
374 showInMenuSchemes.removeAll(
mName );
377 s.
setValue( QStringLiteral(
"/colors/showInMenuList" ), showInMenuSchemes );
385 if ( !localDir.mkpath( palettesDir ) )
390 return QDir( palettesDir ).filePath(
mFilename );
A color scheme which contains custom colors set through QGIS app options dialog.
A color scheme which stores its colors in a gpl palette file within the "palettes" subfolder off the ...
QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor()) override
Gets a list of colors from the scheme.
A color scheme which contains project specific colors set through project properties dialog...
bool erase()
Erases the associated gpl palette file from the users "palettes" folder.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
QgsCustomColorScheme * clone() const override
Clones a color scheme.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
virtual SchemeFlags flags() const
Returns the current flags for the color scheme.
bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor()) override
Sets the colors for the scheme.
QgsRecentColorScheme * clone() const override
Clones a color scheme.
QgsColorScheme::SchemeFlags flags() const override
Returns the current flags for the color scheme.
Show scheme in color button drop-down menu.
QgsProjectColorScheme * clone() const override
Clones a color scheme.
static QgsNamedColorList importColorsFromGpl(QFile &file, bool &ok, QString &name)
Imports colors from a gpl GIMP palette file.
void setShowSchemeInMenu(bool show)
Sets whether a this scheme should be shown in color button menus.
static QString colorToName(const QColor &color)
Returns a friendly display name for a color.
QgsUserColorScheme(const QString &filename)
Constructs a new user color scheme, using a specified gpl palette file.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor()) override
Sets the colors for the scheme.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
void setProjectColors(const QgsNamedColorList &colors)
Sets the colors for the project's color scheme (see QgsProjectColorScheme).
static void addRecentColor(const QColor &color)
Adds a color to the list of recent colors.
QString gplFilePath() override
Returns the file path for the associated gpl palette file.
A color scheme which contains the most recently used colors.
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes. ...
static bool saveColorsToGpl(QFile &file, const QString &paletteName, const QgsNamedColorList &colors)
Exports colors to a gpl GIMP palette file.
QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor()) override
Gets a list of colors from the scheme.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
void setRandomStyleColorScheme(QgsColorScheme *scheme)
Sets the color scheme to use when fetching random colors to use for symbol styles.
QString schemeName() const override
Gets the name for the color scheme.
QgsUserColorScheme * clone() const override
Clones a color scheme.
virtual QString schemeName() const =0
Gets the name for the color scheme.
bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor()) override
Sets the colors for the scheme.
static QgsProject * instance()
Returns the QgsProject singleton instance.
static QColor lastUsedColor()
Returns the most recently used color.
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor()) override
Gets a list of colors from the scheme.
QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor()) override
Gets a list of colors from the scheme.
virtual bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor())
Sets the colors for the scheme.
static QColor decodeColor(const QString &str)