33 Q_UNUSED( baseColor );
45 Q_UNUSED( baseColor );
49 QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
53 Q_FOREACH (
const QVariant &color, recentColorVariants )
67 if ( !color.isValid() )
73 QColor opaqueColor = color;
74 opaqueColor.setAlpha( 255 );
77 QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
80 for (
int colorIdx = recentColorVariants.length() - 1; colorIdx >= 0; --colorIdx )
82 if ( ( recentColorVariants.at( colorIdx ).value<QColor>() ).name() == opaqueColor.name() )
84 recentColorVariants.removeAt( colorIdx );
89 QVariant colorVariant = QVariant( opaqueColor );
90 recentColorVariants.prepend( colorVariant );
93 while ( recentColorVariants.count() > 20 )
95 recentColorVariants.pop_back();
98 settings.
setValue( QStringLiteral(
"colors/recent" ), recentColorVariants );
105 QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
107 if ( recentColorVariants.isEmpty() )
110 return recentColorVariants.at( 0 ).value<QColor>();
116 Q_UNUSED( baseColor );
123 if ( !settings.
contains( QStringLiteral(
"/colors/palettecolors" ) ) )
126 colorList.append( qMakePair( QColor( 0, 0, 0 ), QString() ) );
127 colorList.append( qMakePair( QColor( 255, 255, 255 ), QString() ) );
128 colorList.append( qMakePair( QColor( 166, 206, 227 ), QString() ) );
129 colorList.append( qMakePair( QColor( 31, 120, 180 ), QString() ) );
130 colorList.append( qMakePair( QColor( 178, 223, 138 ), QString() ) );
131 colorList.append( qMakePair( QColor( 51, 160, 44 ), QString() ) );
132 colorList.append( qMakePair( QColor( 251, 154, 153 ), QString() ) );
133 colorList.append( qMakePair( QColor( 227, 26, 28 ), QString() ) );
134 colorList.append( qMakePair( QColor( 253, 191, 111 ), QString() ) );
135 colorList.append( qMakePair( QColor( 255, 127, 0 ), QString() ) );
140 QList< QVariant > customColorVariants = settings.
value( QStringLiteral(
"colors/palettecolors" ) ).toList();
141 QList< QVariant > customColorLabels = settings.
value( QStringLiteral(
"colors/palettelabels" ) ).toList();
145 for ( QList< QVariant >::iterator it = customColorVariants.begin();
146 it != customColorVariants.end(); ++it )
148 QColor color = ( *it ).value<QColor>();
150 if ( customColorLabels.length() > colorIndex )
152 label = customColorLabels.at( colorIndex ).toString();
155 colorList.append( qMakePair( color, label ) );
165 Q_UNUSED( baseColor );
169 QList< QVariant > customColors;
170 QList< QVariant > customColorLabels;
172 QgsNamedColorList::const_iterator colorIt = colors.constBegin();
173 for ( ; colorIt != colors.constEnd(); ++colorIt )
175 QVariant color = ( *colorIt ).first;
176 QVariant label = ( *colorIt ).second;
177 customColors.append( color );
178 customColorLabels.append( label );
180 settings.
setValue( QStringLiteral(
"colors/palettecolors" ), customColors );
181 settings.
setValue( QStringLiteral(
"colors/palettelabels" ), customColorLabels );
194 Q_UNUSED( baseColor );
203 for ( QStringList::iterator it = colorStrings.begin();
204 it != colorStrings.end(); ++it )
208 if ( colorLabels.length() > colorIndex )
210 label = colorLabels.at( colorIndex );
213 colorList.append( qMakePair( color, label ) );
223 Q_UNUSED( baseColor );
226 QStringList customColors;
227 QStringList customColorLabels;
229 QgsNamedColorList::const_iterator colorIt = colors.constBegin();
230 for ( ; colorIt != colors.constEnd(); ++colorIt )
233 QString label = ( *colorIt ).second;
234 customColors.append( color );
235 customColorLabels.append( label );
255 Q_UNUSED( baseColor );
257 QString sourceFilePath = gplFilePath();
258 if ( sourceFilePath.isEmpty() )
266 QFile sourceFile( sourceFilePath );
273 Q_UNUSED( baseColor );
275 QString destFilePath = gplFilePath();
276 if ( destFilePath.isEmpty() )
281 QFile destFile( destFilePath );
303 : mFilename( filename )
308 if ( sourceFile.open( QIODevice::ReadOnly ) )
310 QTextStream in( &sourceFile );
314 while ( !in.atEnd() && !line.startsWith( QLatin1String(
"Name:" ) ) )
316 line = in.readLine();
320 QRegExp rx(
"Name:\\s*(\\S.*)$" );
321 if ( rx.indexIn( line ) != -1 )
327 if (
mName.isEmpty() )
336 mEditable = !sourceFileInfo.exists() || sourceFileInfo.isWritable();
354 QStringList showInMenuSchemes = s.
value( QStringLiteral(
"/colors/showInMenuList" ) ).toStringList();
356 if ( showInMenuSchemes.contains(
mName ) )
367 if ( filePath.isEmpty() )
373 return QFile::remove( filePath );
379 QStringList showInMenuSchemes = s.
value( QStringLiteral(
"/colors/showInMenuList" ) ).toStringList();
381 if ( show && !showInMenuSchemes.contains(
mName ) )
383 showInMenuSchemes <<
mName;
385 else if ( !show && showInMenuSchemes.contains(
mName ) )
387 showInMenuSchemes.removeAll(
mName );
390 s.
setValue( QStringLiteral(
"/colors/showInMenuList" ), showInMenuSchemes );
398 if ( !localDir.mkpath( palettesDir ) )
403 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:
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.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
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 QString encodeColor(const QColor &color)
bool writeEntry(const QString &scope, const QString &key, bool value)
Write a boolean entry to the project file.
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.
virtual SchemeFlags flags() const
Returns the current flags for the color scheme.
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.
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.
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
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.
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)