32 Q_UNUSED( baseColor );
44 Q_UNUSED( baseColor );
48 QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
52 Q_FOREACH (
const QVariant &color, recentColorVariants )
66 if ( !color.isValid() )
72 QColor opaqueColor = color;
73 opaqueColor.setAlpha( 255 );
76 QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
79 for (
int colorIdx = recentColorVariants.length() - 1; colorIdx >= 0; --colorIdx )
81 if ( ( recentColorVariants.at( colorIdx ).value<QColor>() ).name() == opaqueColor.name() )
83 recentColorVariants.removeAt( colorIdx );
88 QVariant colorVariant = QVariant( opaqueColor );
89 recentColorVariants.prepend( colorVariant );
92 while ( recentColorVariants.count() > 20 )
94 recentColorVariants.pop_back();
97 settings.
setValue( QStringLiteral(
"colors/recent" ), recentColorVariants );
104 QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
106 if ( recentColorVariants.isEmpty() )
109 return recentColorVariants.at( 0 ).value<QColor>();
115 Q_UNUSED( baseColor );
122 if ( !settings.
contains( QStringLiteral(
"/colors/palettecolors" ) ) )
125 colorList.append( qMakePair( QColor( 0, 0, 0 ), QString() ) );
126 colorList.append( qMakePair( QColor( 255, 255, 255 ), QString() ) );
127 colorList.append( qMakePair( QColor( 166, 206, 227 ), QString() ) );
128 colorList.append( qMakePair( QColor( 31, 120, 180 ), QString() ) );
129 colorList.append( qMakePair( QColor( 178, 223, 138 ), QString() ) );
130 colorList.append( qMakePair( QColor( 51, 160, 44 ), QString() ) );
131 colorList.append( qMakePair( QColor( 251, 154, 153 ), QString() ) );
132 colorList.append( qMakePair( QColor( 227, 26, 28 ), QString() ) );
133 colorList.append( qMakePair( QColor( 253, 191, 111 ), QString() ) );
134 colorList.append( qMakePair( QColor( 255, 127, 0 ), QString() ) );
139 QList< QVariant > customColorVariants = settings.
value( QStringLiteral(
"colors/palettecolors" ) ).toList();
140 QList< QVariant > customColorLabels = settings.
value( QStringLiteral(
"colors/palettelabels" ) ).toList();
144 for ( QList< QVariant >::iterator it = customColorVariants.begin();
145 it != customColorVariants.end(); ++it )
147 QColor color = ( *it ).value<QColor>();
149 if ( customColorLabels.length() > colorIndex )
151 label = customColorLabels.at( colorIndex ).toString();
154 colorList.append( qMakePair( color, label ) );
164 Q_UNUSED( baseColor );
168 QList< QVariant > customColors;
169 QList< QVariant > customColorLabels;
171 QgsNamedColorList::const_iterator colorIt = colors.constBegin();
172 for ( ; colorIt != colors.constEnd(); ++colorIt )
174 QVariant color = ( *colorIt ).first;
175 QVariant label = ( *colorIt ).second;
176 customColors.append( color );
177 customColorLabels.append( label );
179 settings.
setValue( QStringLiteral(
"colors/palettecolors" ), customColors );
180 settings.
setValue( QStringLiteral(
"colors/palettelabels" ), customColorLabels );
193 Q_UNUSED( baseColor );
202 for ( QStringList::iterator it = colorStrings.begin();
203 it != colorStrings.end(); ++it )
207 if ( colorLabels.length() > colorIndex )
209 label = colorLabels.at( colorIndex );
212 colorList.append( qMakePair( color, label ) );
222 Q_UNUSED( baseColor );
225 QStringList customColors;
226 QStringList customColorLabels;
228 QgsNamedColorList::const_iterator colorIt = colors.constBegin();
229 for ( ; colorIt != colors.constEnd(); ++colorIt )
232 QString label = ( *colorIt ).second;
233 customColors.append( color );
234 customColorLabels.append( label );
254 Q_UNUSED( baseColor );
256 QString sourceFilePath = gplFilePath();
257 if ( sourceFilePath.isEmpty() )
265 QFile sourceFile( sourceFilePath );
272 Q_UNUSED( baseColor );
274 QString destFilePath = gplFilePath();
275 if ( destFilePath.isEmpty() )
280 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() )
335 QStringList showInMenuSchemes = s.
value( QStringLiteral(
"/colors/showInMenuList" ) ).toStringList();
337 if ( showInMenuSchemes.contains(
mName ) )
348 if ( filePath.isEmpty() )
354 return QFile::remove( filePath );
360 QStringList showInMenuSchemes = s.
value( QStringLiteral(
"/colors/showInMenuList" ) ).toStringList();
362 if ( show && !showInMenuSchemes.contains(
mName ) )
364 showInMenuSchemes <<
mName;
366 else if ( !show && showInMenuSchemes.contains(
mName ) )
368 showInMenuSchemes.removeAll(
mName );
371 s.
setValue( QStringLiteral(
"/colors/showInMenuList" ), showInMenuSchemes );
379 if ( !localDir.mkpath( palettesDir ) )
384 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 contains(const QString &key, const QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
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 QString encodeColor(const QColor &color)
bool writeEntry(const QString &scope, const QString &key, bool value)
Write a boolean entry to the project file.
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
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.
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 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.
QString schemeName() const override
Gets the name for the color scheme.
QgsUserColorScheme * clone() const override
Clones a color scheme.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
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)