Skip to content

Commit 9bb9b58

Browse files
authoredNov 30, 2016
Merge pull request #3810 from nirvn/colorrampbutton
[FEATURE] color ramp button widget
2 parents 57f17e3 + a755f08 commit 9bb9b58

20 files changed

+1245
-134
lines changed
 

‎python/core/qgscolorramp.sip

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class QgsColorRamp
4848
*/
4949
virtual QString type() const = 0;
5050

51+
virtual void invert();
52+
5153
/** Creates a clone of the color ramp.
5254
*/
5355
virtual QgsColorRamp* clone() const = 0 /Factory/;
@@ -118,6 +120,7 @@ class QgsGradientColorRamp : QgsColorRamp
118120
virtual double value( int index ) const;
119121
virtual QColor color( double value ) const;
120122
virtual QString type() const;
123+
virtual void invert();
121124
virtual QgsGradientColorRamp* clone() const /Factory/;
122125
virtual QgsStringMap properties() const;
123126

@@ -333,6 +336,7 @@ class QgsPresetSchemeColorRamp : QgsColorRamp, QgsColorScheme
333336
virtual double value( int index ) const;
334337
virtual QColor color( double value ) const;
335338
virtual QString type() const;
339+
virtual void invert();
336340
virtual QgsPresetSchemeColorRamp* clone() const /Factory/;
337341
virtual QgsStringMap properties() const;
338342
int count() const;
@@ -355,7 +359,8 @@ class QgsColorBrewerColorRamp : QgsColorRamp
355359
%End
356360
public:
357361
QgsColorBrewerColorRamp( const QString& schemeName = DEFAULT_COLORBREWER_SCHEMENAME,
358-
int colors = DEFAULT_COLORBREWER_COLORS );
362+
int colors = DEFAULT_COLORBREWER_COLORS,
363+
bool inverted = false );
359364

360365
static QgsColorRamp* create( const QgsStringMap& properties = QgsStringMap() ) /Factory/;
361366

@@ -365,6 +370,8 @@ class QgsColorBrewerColorRamp : QgsColorRamp
365370

366371
virtual QString type() const;
367372

373+
virtual void invert();
374+
368375
virtual QgsColorBrewerColorRamp* clone() const /Factory/;
369376

370377
virtual QgsStringMap properties() const;
@@ -403,7 +410,7 @@ class QgsCptCityColorRamp : QgsGradientColorRamp
403410
static QgsColorRamp* create( const QgsStringMap& properties = QgsStringMap() ) /Factory/;
404411

405412
virtual QString type() const;
406-
413+
virtual void invert();
407414
virtual QgsCptCityColorRamp* clone() const /Factory/;
408415
void copy( const QgsCptCityColorRamp* other );
409416
QgsGradientColorRamp* cloneGradientRamp() const /Factory/;

‎python/core/symbology-ng/qgscategorizedsymbolrenderer.sip

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,11 @@ class QgsCategorizedSymbolRenderer : QgsFeatureRenderer
157157
*/
158158
void setSourceColorRamp( QgsColorRamp* ramp /Transfer/ );
159159

160-
//! @note added in 2.1
161-
bool invertedColorRamp();
162-
void setInvertedColorRamp( bool inverted );
163-
164160
/** Update the color ramp used and all symbols colors.
165161
* @param ramp color ramp. Ownership is transferred to the renderer
166-
* @param inverted set to true to invert ramp colors
167162
* @note added in 2.5
168163
*/
169-
void updateColorRamp( QgsColorRamp* ramp /Transfer/, bool inverted = false );
164+
void updateColorRamp( QgsColorRamp* ramp /Transfer/ );
170165

171166
//! items of symbology items in legend should be checkable
172167
//! @note added in 2.5

‎python/gui/gui.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
%Include qgscharacterselectdialog.sip
4242
%Include qgscolorbrewercolorrampdialog.sip
4343
%Include qgscolorbutton.sip
44-
%Include qgscolorbutton.sip
44+
%Include qgscolorrampbutton.sip
4545
%Include qgscolordialog.sip
4646
%Include qgscolorschemelist.sip
4747
%Include qgscolorswatchgrid.sip

‎python/gui/qgscolorrampbutton.sip

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
2+
/** \ingroup gui
3+
* \class QgsColorRampButton
4+
* A cross platform button subclass for selecting color ramps. Will open color ramp dialogs when clicked.
5+
* Offers live updates to button from color ramp dialog. An attached drop down menu allows for access to
6+
* saved color ramps, as well as option to invert the current color ramp and create new ramps.
7+
* \note Added in version 3.0
8+
*/
9+
10+
class QgsColorRampButton : QToolButton
11+
{
12+
%TypeHeaderCode
13+
#include <qgscolorrampbutton.h>
14+
%End
15+
16+
public:
17+
18+
/** Construct a new color ramp button.
19+
* @param parent The parent QWidget for the dialog
20+
* @param dialogTitle The title to show in the color ramp dialog
21+
*/
22+
QgsColorRampButton( QWidget *parent = nullptr, const QString& dialogTitle = QString() );
23+
24+
virtual ~QgsColorRampButton();
25+
26+
virtual QSize sizeHint() const;
27+
28+
/** Return the current color ramp.
29+
* @returns currently selected color
30+
* @see setColor
31+
*/
32+
QgsColorRamp* colorRamp() const;
33+
34+
/** Set the title for the color ramp dialog window.
35+
* @param title Title for the color ramp dialog
36+
* @see colorRampDialogTitle
37+
*/
38+
void setColorRampDialogTitle( const QString& title );
39+
40+
/** Returns the title for the color ramp dialog window.
41+
* @returns title for the color ramp dialog
42+
* @see setColorRampDialogTitle
43+
*/
44+
QString colorRampDialogTitle() const;
45+
46+
/** Returns whether the button accepts live updates from QgsColorRampDialog.
47+
* @returns true if the button will be accepted immediately when the dialog's color ramp changes
48+
* @see setAcceptLiveUpdates
49+
*/
50+
bool acceptLiveUpdates() const;
51+
52+
/** Sets whether the button accepts live updates from QgsColorRampDialog. Live updates may cause changes
53+
* that are not undoable on QColorRampDialog cancel.
54+
* @param accept set to true to enable live updates
55+
* @see acceptLiveUpdates
56+
*/
57+
void setAcceptLiveUpdates( const bool accept );
58+
59+
/** Sets whether the drop down menu should be shown for the button. The default behaviour is to
60+
* show the menu.
61+
* @param showMenu set to false to hide the drop down menu
62+
* @see showMenu
63+
*/
64+
void setShowMenu( const bool showMenu );
65+
66+
/** Returns whether the drop down menu is shown for the button.
67+
* @returns true if drop down menu is shown
68+
* @see setShowMenu
69+
*/
70+
bool showMenu() const;
71+
72+
/** Sets the default color ramp for the button, which is shown in the button's drop down menu for the
73+
* "default color ramp" option.
74+
* @param colorramp default color ramp for the button. Set to a null pointer to disable the default color
75+
* ramp option.
76+
* @see defaultColorRamp
77+
*/
78+
void setDefaultColorRamp( QgsColorRamp* colorramp );
79+
80+
/** Returns the default color ramp for the button, which is shown in the button's drop down menu for the
81+
* "default color ramp" option.
82+
* @returns default color ramp for the button. Returns a null pointer if the default color ramp
83+
* option is disabled.
84+
* @see setDefaultColorRamp
85+
*/
86+
QgsColorRamp* defaultColorRamp() const;
87+
88+
/** Sets whether a random colors option is shown in the button's drop down menu.
89+
* @param showNull set to true to show a null option
90+
* @see showRandom()
91+
*/
92+
void setShowRandomColorRamp( bool showRandom );
93+
94+
/** Returns whether random colors option is shown in the button's drop down menu.
95+
* @see setShowRandom()
96+
*/
97+
bool showRandomColorRamp() const;
98+
99+
/** Returns true if the current color is null.
100+
* @see setShowNull()
101+
* @see showNull()
102+
*/
103+
bool isRandomColorRamp() const;
104+
105+
/** Sets whether a set to null (clear) option is shown in the button's drop down menu.
106+
* @param showNull set to true to show a null option
107+
* @see showNull()
108+
* @see isNull()
109+
*/
110+
void setShowNull( bool showNull );
111+
112+
/** Returns whether the set to null (clear) option is shown in the button's drop down menu.
113+
* @see setShowNull()
114+
* @see isNull()
115+
*/
116+
bool showNull() const;
117+
118+
/** Returns true if the current color is null.
119+
* @see setShowNull()
120+
* @see showNull()
121+
*/
122+
bool isNull() const;
123+
124+
/** Sets the context string for the color ramp button. The context string is passed to all color ramp
125+
* preview icons shown in the button's drop down menu, to (eventually) allow them to customise their display colors
126+
* based on the context.
127+
* @param context context string for the color dialog button's color ramp preview icons
128+
* @see context
129+
*/
130+
void setContext( const QString& context );
131+
132+
/** Returns the context string for the color ramp button. The context string is passed to all color ramp
133+
* preview icons shown in the button's drop down menu, to (eventually) allow them to customise their display colors
134+
* based on the context.
135+
* @returns context context string for the color dialog button's color ramp preview icons
136+
* @see setContext
137+
*/
138+
QString context() const;
139+
140+
/** Sets whether the color ramp button only shows gradient type ramps
141+
* @param gradientonly set to true to show only gradient type ramps
142+
* @see showGradientOnly
143+
*/
144+
void setShowGradientOnly( bool gradientonly );
145+
146+
/** Returns true if the color ramp button only shows gradient type ramps
147+
* @see setShowGradientOnly
148+
*/
149+
bool showGradientOnly() const;
150+
151+
public slots:
152+
153+
/** Sets the current color ramp for the button. Will emit a colorRampChanged() signal if the color ramp is different
154+
* to the previous color ramp.
155+
* @param colorramp New color ramp for the button
156+
* @see setRandomColorRamp, setColorRampFromName, colorRamp
157+
*/
158+
void setColorRamp( QgsColorRamp* colorramp );
159+
160+
/** Sets the current color ramp for the button to random colors. Will emit a colorRampChanged() signal
161+
* if the color ramp is different to the previous color ramp.
162+
* @see setColorRamp, setColorRampFromName, colorRamp
163+
*/
164+
void setRandomColorRamp();
165+
166+
/** Sets the current color ramp for the button using a saved color ramp name. Will emit a colorRampChanged() signal
167+
* if the color ramp is different to the previous color ramp.
168+
* @param name Name of saved color ramp
169+
* @see setColorRamp, setRandomColorRamp, colorRamp
170+
*/
171+
void setColorRampFromName( QString name = QString() );
172+
173+
/** Sets the background pixmap for the button based upon current color ramp.
174+
* @param colorramp Color ramp for button background. If no color ramp is specified, the button's current
175+
* color ramp will be used
176+
*/
177+
void setButtonBackground( QgsColorRamp* colorramp = nullptr );
178+
179+
/** Sets color ramp to the button's default color ramp, if set.
180+
* @see setDefaultColorRamp
181+
* @see defaultColorRamp
182+
* @see setToNull()
183+
*/
184+
void setToDefaultColorRamp();
185+
186+
/** Sets color ramp to null.
187+
* @see setToDefaultColorRamp()
188+
*/
189+
void setToNull();
190+
191+
signals:
192+
193+
/** Emitted whenever a new color ramp is set for the button. The color ramp is always valid.
194+
* In case the new color ramp is the same, no signal is emitted to avoid infinite loops.
195+
*/
196+
void colorRampChanged();
197+
198+
protected:
199+
200+
bool event( QEvent *e );
201+
void changeEvent( QEvent* e );
202+
void showEvent( QShowEvent* e );
203+
void resizeEvent( QResizeEvent *event );
204+
205+
/**
206+
* Reimplemented to detect right mouse button clicks on the color ramp button
207+
*/
208+
void mousePressEvent( QMouseEvent* e );
209+
210+
};

‎python/gui/symbology-ng/qgscategorizedsymbolrendererwidget.sip

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ class QgsCategorizedSymbolRendererWidget : QgsRendererWidget
7272

7373
void changeCategorySymbol();
7474

75-
QgsColorRamp* getColorRamp();
76-
7775
QList<QgsSymbol*> selectedSymbols();
7876
QgsCategoryList selectedCategoryList();
7977
void refreshSymbolView();

0 commit comments

Comments
 (0)
Please sign in to comment.