Skip to content

Commit bfff4bd

Browse files
committedAug 11, 2014
[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
1 parent c3bd82a commit bfff4bd

27 files changed

+2982
-15
lines changed
 

‎python/core/core.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
%Include qgsattributeaction.sip
1717
%Include qgsbrowsermodel.sip
1818
%Include qgsclipper.sip
19+
%Include qgscolorscheme.sip
20+
%Include qgscolorschemeregistry.sip
1921
%Include qgscontexthelp.sip
2022
%Include qgscoordinatereferencesystem.sip
2123
%Include qgscoordinatetransform.sip

‎python/core/qgscolorscheme.sip

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**List of colors paired with a friendly display name identifying the color*/
2+
typedef QList< QPair< QColor, QString > > QgsNamedColorList;
3+
4+
/** \ingroup core
5+
* \class QgsColorScheme
6+
* \brief Abstract base class for color schemes
7+
*
8+
* A color scheme for display in QgsColorButtonV2. Color schemes return lists
9+
* of colors with an optional associated color name. The colors returned
10+
* can be generated using an optional base color.
11+
* \note Added in version 2.5
12+
*/
13+
class QgsColorScheme
14+
{
15+
%TypeHeaderCode
16+
#include <qgscolorscheme.h>
17+
%End
18+
19+
public:
20+
21+
QgsColorScheme();
22+
23+
virtual ~QgsColorScheme();
24+
25+
/**Gets the name for the color scheme
26+
* @returns color scheme name
27+
*/
28+
virtual QString schemeName() const = 0;
29+
30+
/**Gets a list of colors from the scheme. The colors can optionally
31+
* be generated using the supplied context and base color.
32+
* @param context string specifiying an optional context for the returned
33+
* colors. For instance, a "recent colors" scheme may filter returned colors
34+
* by context so that colors used only in a "composer" context are returned.
35+
* @param baseColor base color for the scheme's colors. Some color schemes
36+
* may take advantage of this to filter or modify their returned colors
37+
* to colors related to the base color.
38+
* @returns a list of QPairs of color and color name
39+
*/
40+
virtual QgsNamedColorList fetchColors( const QString context = QString(),
41+
const QColor baseColor = QColor() ) = 0;
42+
43+
virtual QgsColorScheme* clone() const = 0 /Factory/;
44+
45+
}; // class QgsColorScheme
46+
47+
/** \ingroup core
48+
* \class QgsRecentColorScheme
49+
* \brief A color scheme which contains the most recently used colors.
50+
* \note Added in version 2.5
51+
*/
52+
class QgsRecentColorScheme : QgsColorScheme
53+
{
54+
%TypeHeaderCode
55+
#include <qgscolorscheme.h>
56+
%End
57+
58+
public:
59+
60+
QgsRecentColorScheme();
61+
62+
virtual ~QgsRecentColorScheme();
63+
64+
virtual QString schemeName() const;
65+
66+
virtual QgsNamedColorList fetchColors( const QString context = QString(),
67+
const QColor baseColor = QColor() );
68+
69+
QgsColorScheme* clone() const /Factory/;
70+
}; // class QgsRecentColorScheme
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
/** \ingroup core
3+
* \class QgsColorSchemeRegistry
4+
* \brief Registry of color schemes
5+
*
6+
* A registry of QgsColorScheme color schemes. This class can be created directly, or
7+
* accessed via a global instance.
8+
* \note Added in version 2.5
9+
*/
10+
class QgsColorSchemeRegistry
11+
{
12+
%TypeHeaderCode
13+
#include <qgscolorschemeregistry.h>
14+
%End
15+
public:
16+
17+
/**Returns the global instance pointer, creating the object on the first call.
18+
*/
19+
static QgsColorSchemeRegistry * instance();
20+
21+
/**Constructor for an empty color scheme registry
22+
*/
23+
QgsColorSchemeRegistry();
24+
25+
virtual ~QgsColorSchemeRegistry();
26+
27+
/**Adds all color schemes from the global instance to this color scheme.
28+
* @see addDefaultSchemes
29+
* @see addColorScheme
30+
*/
31+
void populateFromInstance();
32+
33+
/**Adds all default color schemes to this color scheme.
34+
* @see populateFromInstance
35+
* @see addColorScheme
36+
*/
37+
void addDefaultSchemes();
38+
39+
/**Adds a color scheme to the registry. Ownership of the scheme is transferred
40+
* to the registry.
41+
* @param scheme color scheme to add
42+
* @see populateFromInstance
43+
* @see removeColorScheme
44+
*/
45+
void addColorScheme( QgsColorScheme* scheme /Transfer/ );
46+
47+
/**Removes all matching color schemes from the registry
48+
* @param scheme color scheme to remove
49+
* @returns true if scheme was found and removed
50+
* @see addColorScheme
51+
*/
52+
bool removeColorScheme( QgsColorScheme* scheme );
53+
54+
/**Returns all color schemes in the registry
55+
* @returns list of color schemes
56+
*/
57+
QList<QgsColorScheme *> schemes() const;
58+
59+
}; // class QgsColorSchemeRegistry

‎python/gui/gui.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
%Include qgscodeeditorcss.sip
3434
%End
3535
%Include qgscolorbutton.sip
36+
%Include qgscolorbuttonv2.sip
3637
%Include qgscolordialog.sip
38+
%Include qgscolorswatchgrid.sip
3739
%Include qgscomposerview.sip
3840
%Include qgscredentialdialog.sip
3941
%Include qgsdetaileditemdata.sip

0 commit comments

Comments
 (0)
Please sign in to comment.