Skip to content

Commit a755f08

Browse files
committedNov 30, 2016
add test coverage for qgscolorramp's invert() function
1 parent deb18c4 commit a755f08

File tree

4 files changed

+24
-80
lines changed

4 files changed

+24
-80
lines changed
 

‎python/gui/qgscolorrampbutton.sip

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ class QgsColorRampButton : QToolButton
1515

1616
public:
1717

18-
/** Specifies the behaviour when the button is clicked
19-
*/
20-
enum Behaviour
21-
{
22-
ShowDialog, /*!< show a color picker dialog when clicked */
23-
SignalOnly /*!< emit colorClicked signal only, no dialog */
24-
};
25-
2618
/** Construct a new color ramp button.
2719
* @param parent The parent QWidget for the dialog
2820
* @param dialogTitle The title to show in the color ramp dialog
@@ -77,19 +69,6 @@ class QgsColorRampButton : QToolButton
7769
*/
7870
bool showMenu() const;
7971

80-
/** Sets the behaviour for when the button is clicked. The default behaviour is to show
81-
* a color ramp dialog.
82-
* @param behaviour behaviour when button is clicked
83-
* @see behaviour
84-
*/
85-
void setBehaviour( const Behaviour behaviour );
86-
87-
/** Returns the behaviour for when the button is clicked.
88-
* @returns behaviour when button is clicked
89-
* @see setBehaviour
90-
*/
91-
Behaviour behaviour() const;
92-
9372
/** Sets the default color ramp for the button, which is shown in the button's drop down menu for the
9473
* "default color ramp" option.
9574
* @param colorramp default color ramp for the button. Set to a null pointer to disable the default color
@@ -216,14 +195,6 @@ class QgsColorRampButton : QToolButton
216195
*/
217196
void colorRampChanged();
218197

219-
/** Emitted when the button is clicked, if the button's behaviour is set to SignalOnly
220-
* @param colorramp Button's current color ramp
221-
* @see setBehaviour
222-
* @see behaviour
223-
* @note may not be available in Python bindings on some platforms
224-
*/
225-
void colorRampClicked( const QgsColorRamp* colorramp );
226-
227198
protected:
228199

229200
bool event( QEvent *e );

‎src/gui/qgscolorrampbutton.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
QgsColorRampButton::QgsColorRampButton( QWidget *parent, const QString& dialogTitle )
3838
: QToolButton( parent )
39-
, mBehaviour( QgsColorRampButton::ShowDialog )
4039
, mColorRampDialogTitle( dialogTitle.isEmpty() ? tr( "Select Color Ramp" ) : dialogTitle )
4140
, mShowGradientOnly( false )
4241
, mColorRamp( nullptr )
@@ -227,21 +226,13 @@ QPixmap QgsColorRampButton::createMenuIcon( QgsColorRamp* colorramp )
227226

228227
void QgsColorRampButton::buttonClicked()
229228
{
230-
switch ( mBehaviour )
229+
if ( !isRandomColorRamp() )
231230
{
232-
case ShowDialog:
233-
if ( !isRandomColorRamp() )
234-
{
235-
showColorRampDialog();
236-
}
237-
else
238-
{
239-
QToolButton::showMenu();
240-
}
241-
return;
242-
case SignalOnly:
243-
emit colorRampClicked( mColorRamp );
244-
return;
231+
showColorRampDialog();
232+
}
233+
else
234+
{
235+
QToolButton::showMenu();
245236
}
246237
}
247238

@@ -535,11 +526,6 @@ void QgsColorRampButton::setShowMenu( const bool showMenu )
535526
setButtonBackground( mColorRamp );
536527
}
537528

538-
void QgsColorRampButton::setBehaviour( const QgsColorRampButton::Behaviour behaviour )
539-
{
540-
mBehaviour = behaviour;
541-
}
542-
543529
void QgsColorRampButton::setDefaultColorRamp( QgsColorRamp* colorramp )
544530
{
545531
delete mDefaultColorRamp;

‎src/gui/qgscolorrampbutton.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,14 @@ class QgsPanelWidget;
3535
class GUI_EXPORT QgsColorRampButton : public QToolButton
3636
{
3737
Q_OBJECT
38-
Q_ENUMS( Behaviour )
3938
Q_PROPERTY( QString colorRampDialogTitle READ colorRampDialogTitle WRITE setColorRampDialogTitle )
4039
Q_PROPERTY( bool acceptLiveUpdates READ acceptLiveUpdates WRITE setAcceptLiveUpdates )
4140
Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
42-
Q_PROPERTY( Behaviour behaviour READ behaviour WRITE setBehaviour )
4341
Q_PROPERTY( QgsColorRamp* defaultColorRamp READ defaultColorRamp WRITE setDefaultColorRamp )
4442
Q_PROPERTY( QString context READ context WRITE setContext )
4543

4644
public:
4745

48-
/** Specifies the behaviour when the button is clicked
49-
*/
50-
enum Behaviour
51-
{
52-
ShowDialog = 0, //!< Show a color ramp dialog when clicked
53-
SignalOnly //!< Emit colorRampClicked signal only, no dialog
54-
};
55-
5646
/** Construct a new color ramp button.
5747
* @param parent The parent QWidget for the dialog
5848
* @param dialogTitle The title to show in the color ramp dialog
@@ -107,19 +97,6 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton
10797
*/
10898
bool showMenu() const { return menu() ? true : false; }
10999

110-
/** Sets the behaviour for when the button is clicked. The default behaviour is to show
111-
* a color ramp dialog.
112-
* @param behaviour behaviour when button is clicked
113-
* @see behaviour
114-
*/
115-
void setBehaviour( const Behaviour behaviour );
116-
117-
/** Returns the behaviour for when the button is clicked.
118-
* @returns behaviour when button is clicked
119-
* @see setBehaviour
120-
*/
121-
Behaviour behaviour() const { return mBehaviour; }
122-
123100
/** Sets the default color ramp for the button, which is shown in the button's drop down menu for the
124101
* "default color ramp" option.
125102
* @param colorramp default color ramp for the button. Set to a null pointer to disable the default color
@@ -250,13 +227,6 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton
250227
*/
251228
void colorRampChanged();
252229

253-
/** Emitted when the button is clicked, if the button's behaviour is set to SignalOnly
254-
* @param colorramp Button's current color ramp
255-
* @see setBehaviour
256-
* @see behaviour
257-
*/
258-
void colorRampClicked( const QgsColorRamp* colorramp );
259-
260230
protected:
261231

262232
bool event( QEvent *e ) override;
@@ -271,7 +241,6 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton
271241

272242
private:
273243

274-
Behaviour mBehaviour;
275244
QString mColorRampDialogTitle;
276245
bool mShowGradientOnly;
277246
QgsColorRamp* mColorRamp;

‎tests/src/python/test_qgsvectorcolorramp.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ def testQgsVectorGradientRampV2(self):
161161
self.assertEqual(s[3].offset, 0.8)
162162
self.assertEqual(s[3].color, QColor(50, 20, 10))
163163

164+
# test invert function
165+
r.invert()
166+
self.assertEqual(r.color(0), QColor(0, 200, 0))
167+
self.assertEqual(r.color(1), QColor(200, 0, 0))
168+
self.assertEqual(r.color(0.2), QColor(50, 20, 10))
169+
164170
def testQgsLimitedRandomColorRampV2(self):
165171
# test random color ramp
166172
r = QgsLimitedRandomColorRamp(5)
@@ -310,6 +316,11 @@ def testQgsPresetSchemeColorRamp(self):
310316
self.assertEqual(cloned.count(), 2)
311317
self.assertEqual(cloned.fetchColors(), r.fetchColors())
312318

319+
# test invert function
320+
r.invert()
321+
self.assertEqual(r.color(0), QColor(0, 255, 0))
322+
self.assertEqual(r.color(1), QColor(255, 0, 0))
323+
313324
def testQgsColorBrewerColorRampV2(self):
314325
# test color brewer color ramps
315326
r = QgsColorBrewerColorRamp('OrRd', 6)
@@ -373,6 +384,13 @@ def testQgsColorBrewerColorRampV2(self):
373384
self.assertEqual(r.color(0.8), QColor(222, 45, 38))
374385
self.assertEqual(r.color(1.0), QColor(165, 15, 21))
375386

387+
# test invert function
388+
r.invert()
389+
self.assertEqual(r.color(0), QColor(165, 15, 21))
390+
self.assertEqual(r.color(0.2), QColor(222, 45, 38))
391+
self.assertEqual(r.color(1), QColor(254, 229, 217))
392+
r.invert()
393+
376394
# set colors
377395
r.setColors(3)
378396
self.assertEqual(r.colors(), 3)

0 commit comments

Comments
 (0)
Please sign in to comment.