24 #include "qgssettings.h" 
   27 #include <QTextStream> 
   50   QList< QVariant > recentColorVariants = settings.value( QStringLiteral( 
"colors/recent" ) ).toList();
 
   54   const auto constRecentColorVariants = recentColorVariants;
 
   55   for ( 
const QVariant &color : constRecentColorVariants )
 
   69   if ( !color.isValid() )
 
   75   QColor opaqueColor = color;
 
   76   opaqueColor.setAlpha( 255 );
 
   79   QList< QVariant > recentColorVariants = settings.value( QStringLiteral( 
"colors/recent" ) ).toList();
 
   82   for ( 
int colorIdx = recentColorVariants.length() - 1; colorIdx >= 0; --colorIdx )
 
   84     if ( ( recentColorVariants.at( colorIdx ).value<QColor>() ).name() == opaqueColor.name() )
 
   86       recentColorVariants.removeAt( colorIdx );
 
   91   QVariant colorVariant = QVariant( opaqueColor );
 
   92   recentColorVariants.prepend( colorVariant );
 
   95   while ( recentColorVariants.count() > 20 )
 
   97     recentColorVariants.pop_back();
 
  100   settings.setValue( QStringLiteral( 
"colors/recent" ), recentColorVariants );
 
  106   QgsSettings settings;
 
  107   QList< QVariant > recentColorVariants = settings.value( QStringLiteral( 
"colors/recent" ) ).toList();
 
  109   if ( recentColorVariants.isEmpty() )
 
  112   return recentColorVariants.at( 0 ).value<QColor>();
 
  118   Q_UNUSED( baseColor )
 
  122   QgsSettings settings;
 
  125   if ( !settings.contains( QStringLiteral( 
"/colors/palettecolors" ) ) )
 
  128     colorList.append( qMakePair( QColor( 0, 0, 0 ), QString() ) );
 
  129     colorList.append( qMakePair( QColor( 255, 255, 255 ), QString() ) );
 
  130     colorList.append( qMakePair( QColor( 166, 206, 227 ), QString() ) );
 
  131     colorList.append( qMakePair( QColor( 31, 120, 180 ), QString() ) );
 
  132     colorList.append( qMakePair( QColor( 178, 223, 138 ), QString() ) );
 
  133     colorList.append( qMakePair( QColor( 51, 160, 44 ), QString() ) );
 
  134     colorList.append( qMakePair( QColor( 251, 154, 153 ), QString() ) );
 
  135     colorList.append( qMakePair( QColor( 227, 26, 28 ), QString() ) );
 
  136     colorList.append( qMakePair( QColor( 253, 191, 111 ), QString() ) );
 
  137     colorList.append( qMakePair( QColor( 255, 127, 0 ), QString() ) );
 
  142   QList< QVariant > customColorVariants = settings.value( QStringLiteral( 
"colors/palettecolors" ) ).toList();
 
  143   QList< QVariant > customColorLabels = settings.value( QStringLiteral( 
"colors/palettelabels" ) ).toList();
 
  147   for ( QList< QVariant >::iterator it = customColorVariants.begin();
 
  148         it != customColorVariants.end(); ++it )
 
  150     QColor color = ( *it ).value<QColor>();
 
  152     if ( customColorLabels.length() > colorIndex )
 
  154       label = customColorLabels.at( colorIndex ).toString();
 
  157     colorList.append( qMakePair( color, label ) );
 
  167   Q_UNUSED( baseColor )
 
  170   QgsSettings settings;
 
  171   QList< QVariant > customColors;
 
  172   QList< QVariant > customColorLabels;
 
  174   QgsNamedColorList::const_iterator colorIt = colors.constBegin();
 
  175   for ( ; colorIt != colors.constEnd(); ++colorIt )
 
  177     QVariant color = ( *colorIt ).first;
 
  178     QVariant label = ( *colorIt ).second;
 
  179     customColors.append( color );
 
  180     customColorLabels.append( label );
 
  182   settings.setValue( QStringLiteral( 
"colors/palettecolors" ), customColors );
 
  183   settings.setValue( QStringLiteral( 
"colors/palettelabels" ), customColorLabels );
 
  196   Q_UNUSED( baseColor )
 
  205   for ( QStringList::iterator it = colorStrings.begin();
 
  206         it != colorStrings.end(); ++it )
 
  210     if ( colorLabels.length() > colorIndex )
 
  212       label = colorLabels.at( colorIndex );
 
  215     colorList.append( qMakePair( color, label ) );
 
  225   Q_UNUSED( baseColor )
 
  243   Q_UNUSED( baseColor )
 
  246   if ( sourceFilePath.isEmpty() )
 
  254   QFile sourceFile( sourceFilePath );
 
  261   Q_UNUSED( baseColor )
 
  264   if ( destFilePath.isEmpty() )
 
  269   QFile destFile( destFilePath );
 
  291   : mFilename( filename )
 
  296   if ( sourceFile.open( QIODevice::ReadOnly ) )
 
  298     QTextStream in( &sourceFile );
 
  302     while ( !in.atEnd() && !line.startsWith( QLatin1String( 
"Name:" ) ) )
 
  304       line = in.readLine();
 
  308       QRegExp rx( 
"Name:\\s*(\\S.*)$" );
 
  309       if ( rx.indexIn( line ) != -1 )
 
  315   if ( 
mName.isEmpty() )
 
  324   mEditable = !sourceFileInfo.exists() || sourceFileInfo.isWritable();
 
  342   QStringList showInMenuSchemes = s.value( QStringLiteral( 
"/colors/showInMenuList" ) ).toStringList();
 
  344   if ( showInMenuSchemes.contains( 
mName ) )
 
  355   if ( filePath.isEmpty() )
 
  361   if ( ! QFile::exists( filePath ) )
 
  367   return QFile::remove( filePath );
 
  373   QStringList showInMenuSchemes = s.value( QStringLiteral( 
"/colors/showInMenuList" ) ).toStringList();
 
  375   if ( show && !showInMenuSchemes.contains( 
mName ) )
 
  377     showInMenuSchemes << 
mName;
 
  379   else if ( !show && showInMenuSchemes.contains( 
mName ) )
 
  381     showInMenuSchemes.removeAll( 
mName );
 
  384   s.setValue( QStringLiteral( 
"/colors/showInMenuList" ), showInMenuSchemes );
 
  392   if ( !localDir.mkpath( palettesDir ) )
 
  397   return QDir( palettesDir ).filePath( 
mFilename );
 
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
void setRandomStyleColorScheme(QgsColorScheme *scheme)
Sets the color scheme to use when fetching random colors to use for symbol styles.
@ ShowInColorButtonMenu
Show scheme in color button drop-down menu.
virtual QString schemeName() const =0
Gets the name for the color scheme.
virtual bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor())
Sets the colors for the scheme.
virtual SchemeFlags flags() const
Returns the current flags for the color scheme.
A color scheme which contains custom colors set through QGIS app options dialog.
QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor()) override
Gets a list of colors from the scheme.
bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor()) override
Sets the colors for the scheme.
QgsCustomColorScheme * clone() const override
Clones a color scheme.
QgsCustomColorScheme()=default
Constructor for QgsCustomColorScheme.
virtual QString gplFilePath()=0
Returns the file path for the associated gpl palette file.
QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor()) override
Gets a list of colors from the scheme.
bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor()) override
Sets the colors for the scheme.
A color scheme which contains project specific colors set through project properties dialog.
QgsProjectColorScheme * clone() const override
Clones a color scheme.
bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor()) override
Sets the colors for the scheme.
QgsProjectColorScheme()=default
Constructor for QgsProjectColorScheme.
QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor()) override
Gets a list of colors from the scheme.
static QgsProject * instance()
Returns the QgsProject singleton instance.
void setProjectColors(const QgsNamedColorList &colors)
Sets the colors for the project's color scheme (see QgsProjectColorScheme).
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Reads a string list from the specified scope and key.
A color scheme which contains the most recently used colors.
QgsRecentColorScheme()=default
Constructor for QgsRecentColorScheme.
QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor()) override
Gets a list of colors from the scheme.
static QColor lastUsedColor()
Returns the most recently used color.
QgsRecentColorScheme * clone() const override
Clones a color scheme.
static void addRecentColor(const QColor &color)
Adds a color to the list of recent colors.
static QColor decodeColor(const QString &str)
static bool saveColorsToGpl(QFile &file, const QString &paletteName, const QgsNamedColorList &colors)
Exports colors to a gpl GIMP palette file.
static QgsNamedColorList importColorsFromGpl(QFile &file, bool &ok, QString &name)
Imports colors from a gpl GIMP palette file.
static QString colorToName(const QColor &color)
Returns a friendly display name for a color.
A color scheme which stores its colors in a gpl palette file within the "palettes" subfolder off the ...
QString schemeName() const override
Gets the name for the color scheme.
QgsUserColorScheme(const QString &filename)
Constructs a new user color scheme, using a specified gpl palette file.
QgsColorScheme::SchemeFlags flags() const override
Returns the current flags for the color scheme.
QString gplFilePath() override
Returns the file path for the associated gpl palette file.
bool erase()
Erases the associated gpl palette file from the users "palettes" folder.
void setShowSchemeInMenu(bool show)
Sets whether a this scheme should be shown in color button menus.
QgsUserColorScheme * clone() const override
Clones a color scheme.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.