Skip to content
Permalink
Browse files

Add flags for controlling behaviour of color schemes

  • Loading branch information
nyalldawson committed Sep 17, 2014
1 parent dff326f commit a7a1bee5cc077ccb3d0d673061ea92ad1c4f8618
@@ -16,7 +16,17 @@ class QgsColorScheme
#include <qgscolorscheme.h>
%End

public:
public:

/** Flags for controlling behaviour of color scheme
*/
enum SchemeFlag
{
ShowInColorDialog, /*< show scheme in color picker dialog */
ShowInColorButtonMenu, /*< show scheme in color button drop down menu */
ShowInAllContexts /*< show scheme in all contexts */
};
typedef QFlags<QgsColorScheme::SchemeFlag> SchemeFlags;

QgsColorScheme();

@@ -27,6 +37,11 @@ class QgsColorScheme
*/
virtual QString schemeName() const = 0;

/**Returns the current flags for the color scheme.
* @returns current flags
*/
virtual SchemeFlags flags() const;

/**Gets a list of colors from the scheme. The colors can optionally
* be generated using the supplied context and base color.
* @param context string specifiying an optional context for the returned
@@ -62,6 +77,8 @@ class QgsColorScheme

}; // class QgsColorScheme

QFlags<QgsColorScheme::SchemeFlag> operator|(QgsColorScheme::SchemeFlag f1, QFlags<QgsColorScheme::SchemeFlag> f2);


/** \ingroup core
* \class QgsGplColorScheme
@@ -146,6 +163,8 @@ class QgsRecentColorScheme : QgsColorScheme

virtual QString schemeName() const;

virtual SchemeFlags flags() const;

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

@@ -171,6 +190,8 @@ class QgsCustomColorScheme : QgsColorScheme

virtual QString schemeName() const;

virtual SchemeFlags flags() const;

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

@@ -199,6 +220,8 @@ class QgsProjectColorScheme : QgsColorScheme

virtual QString schemeName() const;

virtual SchemeFlags flags() const;

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

@@ -55,5 +55,11 @@ class QgsColorSchemeRegistry
* @returns list of color schemes
*/
QList<QgsColorScheme *> schemes() const;

/**Returns all color schemes in the registry which have a specified flag set
* @param flag flag to match
* @returns list of color schemes with flag set
*/
QList<QgsColorScheme *> schemes( const QgsColorScheme::SchemeFlag flag ) const;

}; // class QgsColorSchemeRegistry
@@ -309,7 +309,7 @@ QgsUserColorScheme::QgsUserColorScheme( const QString filename )
}
if ( !in.atEnd() )
{
QRegExp rx( "Name:\\s*(.*)$" );
QRegExp rx( "Name:\\s*(\\S.*)$" );
if ( rx.indexIn( line ) != -1 )
{
mName = rx.cap( 1 );
@@ -40,6 +40,16 @@ class CORE_EXPORT QgsColorScheme
{
public:

/** Flags for controlling behaviour of color scheme
*/
enum SchemeFlag
{
ShowInColorDialog = 0x01, /*< show scheme in color picker dialog */
ShowInColorButtonMenu = 0x02, /*< show scheme in color button drop down menu */
ShowInAllContexts = ShowInColorDialog | ShowInColorButtonMenu /*< show scheme in all contexts */
};
Q_DECLARE_FLAGS( SchemeFlags, SchemeFlag )

QgsColorScheme();

virtual ~QgsColorScheme();
@@ -49,6 +59,11 @@ class CORE_EXPORT QgsColorScheme
*/
virtual QString schemeName() const = 0;

/**Returns the current flags for the color scheme.
* @returns current flags
*/
virtual SchemeFlags flags() const { return ShowInColorDialog; }

/**Gets a list of colors from the scheme. The colors can optionally
* be generated using the supplied context and base color.
* @param context string specifiying an optional context for the returned
@@ -83,6 +98,8 @@ class CORE_EXPORT QgsColorScheme
virtual QgsColorScheme* clone() const = 0;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsColorScheme::SchemeFlags )

/** \ingroup core
* \class QgsGplColorScheme
* \brief A color scheme which stores its colors in a gpl palette file.
@@ -158,6 +175,8 @@ class CORE_EXPORT QgsRecentColorScheme : public QgsColorScheme

virtual QString schemeName() const { return QT_TR_NOOP( "Recent colors" ); }

virtual SchemeFlags flags() const { return ShowInAllContexts; }

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

@@ -179,6 +198,8 @@ class CORE_EXPORT QgsCustomColorScheme : public QgsColorScheme

virtual QString schemeName() const { return QT_TR_NOOP( "Standard colors" ); }

virtual SchemeFlags flags() const { return ShowInAllContexts; }

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

@@ -204,6 +225,8 @@ class CORE_EXPORT QgsProjectColorScheme : public QgsColorScheme

virtual QString schemeName() const { return QT_TR_NOOP( "Project colors" ); }

virtual SchemeFlags flags() const { return ShowInAllContexts; }

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

@@ -111,6 +111,20 @@ QList<QgsColorScheme *> QgsColorSchemeRegistry::schemes() const
return allSchemes;
}

QList<QgsColorScheme *> QgsColorSchemeRegistry::schemes( const QgsColorScheme::SchemeFlag flag ) const
{
QList< QgsColorScheme* > matchingSchemes;
QList<QgsColorScheme*>::const_iterator schemeIt;
for ( schemeIt = mColorSchemeList.constBegin(); schemeIt != mColorSchemeList.constEnd(); ++schemeIt )
{
if (( *schemeIt )->flags().testFlag( flag ) )
{
matchingSchemes.append(( *schemeIt ) );
}
}
return matchingSchemes;
}

bool QgsColorSchemeRegistry::removeColorScheme( QgsColorScheme *scheme )
{
if ( mColorSchemeList.indexOf( scheme ) != -1 )
9 src/core/qgscolorschemeregistry.h 100755 → 100644
@@ -18,10 +18,9 @@
#ifndef QGSCOLORSCHEMEREGISTRY_H
#define QGSCOLORSCHEMEREGISTRY_H

#include "qgscolorscheme.h"
#include <QList>

class QgsColorScheme;

/** \ingroup core
* \class QgsColorSchemeRegistry
* \brief Registry of color schemes
@@ -85,6 +84,12 @@ class CORE_EXPORT QgsColorSchemeRegistry
*/
QList<QgsColorScheme *> schemes() const;

/**Returns all color schemes in the registry which have a specified flag set
* @param flag flag to match
* @returns list of color schemes with flag set
*/
QList<QgsColorScheme *> schemes( const QgsColorScheme::SchemeFlag flag ) const;

/**Return color schemes of a specific type
* @param schemeList destination list for matching schemes
* @note not available in python bindings
@@ -405,7 +405,8 @@ void QgsColorButtonV2::prepareMenu()

if ( mColorSchemeRegistry )
{
QList< QgsColorScheme* > schemeList = mColorSchemeRegistry->schemes();
//get schemes with ShowInColorButtonMenu flag set
QList< QgsColorScheme* > schemeList = mColorSchemeRegistry->schemes( QgsColorScheme::ShowInColorButtonMenu );
QList< QgsColorScheme* >::iterator it = schemeList.begin();
for ( ; it != schemeList.end(); ++it )
{
@@ -79,7 +79,8 @@ QgsColorDialogV2::QgsColorDialogV2( QWidget *parent, Qt::WindowFlags fl, const Q
mSchemeList->header()->hide();
mSchemeList->setColumnWidth( 0, 44 );

QList<QgsColorScheme *> schemeList = QgsColorSchemeRegistry::instance()->schemes();
//get schemes with ShowInColorDialog set
QList<QgsColorScheme *> schemeList = QgsColorSchemeRegistry::instance()->schemes( QgsColorScheme::ShowInColorDialog );
QList<QgsColorScheme *>::const_iterator schemeIt = schemeList.constBegin();
for ( ; schemeIt != schemeList.constEnd(); ++schemeIt )
{
@@ -418,7 +419,8 @@ void QgsColorDialogV2::schemeIndexChanged( int index )
mSchemeList->saveColorsToScheme();
}

QList<QgsColorScheme *> schemeList = QgsColorSchemeRegistry::instance()->schemes();
//get schemes with ShowInColorDialog set
QList<QgsColorScheme *> schemeList = QgsColorSchemeRegistry::instance()->schemes( QgsColorScheme::ShowInColorDialog );
if ( index >= schemeList.length() )
{
return;

0 comments on commit a7a1bee

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