Skip to content
Permalink
Browse files

Add method for editing color scheme colors

  • Loading branch information
nyalldawson committed Aug 16, 2014
1 parent ff28fe9 commit f7f4c74a56b572ece55e63bcd3c281a3ada9d1ec
Showing with 74 additions and 1 deletion.
  1. +22 −0 python/core/qgscolorscheme.sip
  2. +33 −1 src/core/qgscolorscheme.cpp
  3. +19 −0 src/core/qgscolorscheme.h
@@ -40,6 +40,24 @@ class QgsColorScheme
virtual QgsNamedColorList fetchColors( const QString context = QString(),
const QColor baseColor = QColor() ) = 0;

/**Returns whether the color scheme is editable
* @returns true if scheme is editable
* @see setColors
*/
virtual bool isEditable() const;

/**Sets the colors for the scheme. This method is only valid for editable color schemes.
* @param colors list of colors for the scheme
* @param context to set colors for
* @param baseColor base color to set colors for
* @returns true if colors were set successfully
* @see isEditable
*/
virtual bool setColors( const QgsNamedColorList colors, const QString context = QString(), const QColor baseColor = QColor() );

/**Clones a color scheme
* @returns copy of color scheme
*/
virtual QgsColorScheme* clone() const = 0 /Factory/;

}; // class QgsColorScheme
@@ -90,6 +108,10 @@ class QgsCustomColorScheme : QgsColorScheme

virtual QgsNamedColorList fetchColors( const QString context = QString(),
const QColor baseColor = QColor() );

virtual bool isEditable() const;

virtual bool setColors( const QgsNamedColorList colors, const QString context = QString(), const QColor baseColor = QColor() );

QgsColorScheme* clone() const /Factory/;
}; // class QgsCustomColorScheme
@@ -30,6 +30,15 @@ QgsColorScheme::~QgsColorScheme()

}

bool QgsColorScheme::setColors( const QgsNamedColorList colors, const QString context, const QColor baseColor )
{
//base implementation does nothing
Q_UNUSED( colors );
Q_UNUSED( context );
Q_UNUSED( baseColor );
return false;
}


//
// QgsRecentColorScheme
@@ -90,7 +99,7 @@ QgsNamedColorList QgsCustomColorScheme::fetchColors( const QString context, cons
QSettings settings;

//check if settings contains custom palette
if ( !settings.contains( QString( "/colors/ypalettecolors" ) ) )
if ( !settings.contains( QString( "/colors/palettecolors" ) ) )
{
//no custom palette, return default colors
colorList.append( qMakePair( QColor( "#000000" ), QString() ) );
@@ -129,6 +138,29 @@ QgsNamedColorList QgsCustomColorScheme::fetchColors( const QString context, cons
return colorList;
}

bool QgsCustomColorScheme::setColors( const QgsNamedColorList colors, const QString context, const QColor baseColor )
{
Q_UNUSED( context );
Q_UNUSED( baseColor );

// save colors to settings
QSettings settings;
QList< QVariant > customColors;
QList< QVariant > customColorLabels;

QgsNamedColorList::const_iterator colorIt = colors.constBegin();
for ( ; colorIt != colors.constEnd(); ++colorIt )
{
QVariant color = ( *colorIt ).first;
QVariant label = ( *colorIt ).second;
customColors.append( color );
customColorLabels.append( label );
}
settings.setValue( QString( "/colors/palettecolors" ), customColors );
settings.setValue( QString( "/colors/palettelabels" ), customColorLabels );
return true;
}

QgsColorScheme *QgsCustomColorScheme::clone() const
{
return new QgsCustomColorScheme();
@@ -62,6 +62,21 @@ class CORE_EXPORT QgsColorScheme
virtual QgsNamedColorList fetchColors( const QString context = QString(),
const QColor baseColor = QColor() ) = 0;

/**Returns whether the color scheme is editable
* @returns true if scheme is editable
* @see setColors
*/
virtual bool isEditable() const { return false; }

/**Sets the colors for the scheme. This method is only valid for editable color schemes.
* @param colors list of colors for the scheme
* @param context to set colors for
* @param baseColor base color to set colors for
* @returns true if colors were set successfully
* @see isEditable
*/
virtual bool setColors( const QgsNamedColorList colors, const QString context = QString(), const QColor baseColor = QColor() );

/**Clones a color scheme
* @returns copy of color scheme
*/
@@ -108,6 +123,10 @@ class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme
virtual QgsNamedColorList fetchColors( const QString context = QString(),
const QColor baseColor = QColor() );

virtual bool isEditable() const { return true; }

virtual bool setColors( const QgsNamedColorList colors, const QString context = QString(), const QColor baseColor = QColor() );

QgsColorScheme* clone() const;
};

0 comments on commit f7f4c74

Please sign in to comment.
You can’t perform that action at this time.