Skip to content
Browse files

[FEATURE] New version of color button (QgsColorButtonV2) based off

QToolButton. Features:
- context menu items have been moved to the attached menu button
- new gui widget QgsColorSwatchGrid, which displays a grid of colors
- new class for QgsColorScheme, which generates colors to show in a
  color swatch grid
- new class QgsColorSchemeRegistry, with a global instance containing
  default color schemes. QgsColorButtonV2 accepts a color scheme
  registry, to control which schemes to show in the popup menu as
  color swatch grids.
- color button can have a default color
- color button can also be quickly set to a totally transparent color
- c++ and python unit tests for all core components
  • Loading branch information
nyalldawson committed Aug 11, 2014
1 parent c3bd82a commit bfff4bd6b25bbf497caf1b882b6a3c118fd0b99c
@@ -16,6 +16,8 @@
%Include qgsattributeaction.sip
%Include qgsbrowsermodel.sip
%Include qgsclipper.sip
%Include qgscolorscheme.sip
%Include qgscolorschemeregistry.sip
%Include qgscontexthelp.sip
%Include qgscoordinatereferencesystem.sip
%Include qgscoordinatetransform.sip
@@ -0,0 +1,70 @@
/**List of colors paired with a friendly display name identifying the color*/
typedef QList< QPair< QColor, QString > > QgsNamedColorList;

/** \ingroup core
* \class QgsColorScheme
* \brief Abstract base class for color schemes
* A color scheme for display in QgsColorButtonV2. Color schemes return lists
* of colors with an optional associated color name. The colors returned
* can be generated using an optional base color.
* \note Added in version 2.5
class QgsColorScheme
#include <qgscolorscheme.h>



virtual ~QgsColorScheme();

/**Gets the name for the color scheme
* @returns color scheme name
virtual QString schemeName() const = 0;

/**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
* colors. For instance, a "recent colors" scheme may filter returned colors
* by context so that colors used only in a "composer" context are returned.
* @param baseColor base color for the scheme's colors. Some color schemes
* may take advantage of this to filter or modify their returned colors
* to colors related to the base color.
* @returns a list of QPairs of color and color name
virtual QgsNamedColorList fetchColors( const QString context = QString(),
const QColor baseColor = QColor() ) = 0;

virtual QgsColorScheme* clone() const = 0 /Factory/;

}; // class QgsColorScheme

/** \ingroup core
* \class QgsRecentColorScheme
* \brief A color scheme which contains the most recently used colors.
* \note Added in version 2.5
class QgsRecentColorScheme : QgsColorScheme
#include <qgscolorscheme.h>



virtual ~QgsRecentColorScheme();

virtual QString schemeName() const;

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

QgsColorScheme* clone() const /Factory/;
}; // class QgsRecentColorScheme
@@ -0,0 +1,59 @@

/** \ingroup core
* \class QgsColorSchemeRegistry
* \brief Registry of color schemes
* A registry of QgsColorScheme color schemes. This class can be created directly, or
* accessed via a global instance.
* \note Added in version 2.5
class QgsColorSchemeRegistry
#include <qgscolorschemeregistry.h>

/**Returns the global instance pointer, creating the object on the first call.
static QgsColorSchemeRegistry * instance();

/**Constructor for an empty color scheme registry

virtual ~QgsColorSchemeRegistry();

/**Adds all color schemes from the global instance to this color scheme.
* @see addDefaultSchemes
* @see addColorScheme
void populateFromInstance();

/**Adds all default color schemes to this color scheme.
* @see populateFromInstance
* @see addColorScheme
void addDefaultSchemes();

/**Adds a color scheme to the registry. Ownership of the scheme is transferred
* to the registry.
* @param scheme color scheme to add
* @see populateFromInstance
* @see removeColorScheme
void addColorScheme( QgsColorScheme* scheme /Transfer/ );

/**Removes all matching color schemes from the registry
* @param scheme color scheme to remove
* @returns true if scheme was found and removed
* @see addColorScheme
bool removeColorScheme( QgsColorScheme* scheme );

/**Returns all color schemes in the registry
* @returns list of color schemes
QList<QgsColorScheme *> schemes() const;

}; // class QgsColorSchemeRegistry
@@ -33,7 +33,9 @@
%Include qgscodeeditorcss.sip
%Include qgscolorbutton.sip
%Include qgscolorbuttonv2.sip
%Include qgscolordialog.sip
%Include qgscolorswatchgrid.sip
%Include qgscomposerview.sip
%Include qgscredentialdialog.sip
%Include qgsdetaileditemdata.sip

0 comments on commit bfff4bd

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