Skip to content
Permalink
Browse files

add test coverage for qgscolorramp's invert() function

  • Loading branch information
nirvn committed Nov 30, 2016
1 parent deb18c4 commit a755f08ba6448923bb38255b19fd250a42dc1fc0
@@ -15,14 +15,6 @@ class QgsColorRampButton : QToolButton

public:

/** Specifies the behaviour when the button is clicked
*/
enum Behaviour
{
ShowDialog, /*!< show a color picker dialog when clicked */
SignalOnly /*!< emit colorClicked signal only, no dialog */
};

/** Construct a new color ramp button.
* @param parent The parent QWidget for the dialog
* @param dialogTitle The title to show in the color ramp dialog
@@ -77,19 +69,6 @@ class QgsColorRampButton : QToolButton
*/
bool showMenu() const;

/** Sets the behaviour for when the button is clicked. The default behaviour is to show
* a color ramp dialog.
* @param behaviour behaviour when button is clicked
* @see behaviour
*/
void setBehaviour( const Behaviour behaviour );

/** Returns the behaviour for when the button is clicked.
* @returns behaviour when button is clicked
* @see setBehaviour
*/
Behaviour behaviour() const;

/** Sets the default color ramp for the button, which is shown in the button's drop down menu for the
* "default color ramp" option.
* @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
*/
void colorRampChanged();

/** Emitted when the button is clicked, if the button's behaviour is set to SignalOnly
* @param colorramp Button's current color ramp
* @see setBehaviour
* @see behaviour
* @note may not be available in Python bindings on some platforms
*/
void colorRampClicked( const QgsColorRamp* colorramp );

protected:

bool event( QEvent *e );
@@ -36,7 +36,6 @@

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

void QgsColorRampButton::buttonClicked()
{
switch ( mBehaviour )
if ( !isRandomColorRamp() )
{
case ShowDialog:
if ( !isRandomColorRamp() )
{
showColorRampDialog();
}
else
{
QToolButton::showMenu();
}
return;
case SignalOnly:
emit colorRampClicked( mColorRamp );
return;
showColorRampDialog();
}
else
{
QToolButton::showMenu();
}
}

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

void QgsColorRampButton::setBehaviour( const QgsColorRampButton::Behaviour behaviour )
{
mBehaviour = behaviour;
}

void QgsColorRampButton::setDefaultColorRamp( QgsColorRamp* colorramp )
{
delete mDefaultColorRamp;
@@ -35,24 +35,14 @@ class QgsPanelWidget;
class GUI_EXPORT QgsColorRampButton : public QToolButton
{
Q_OBJECT
Q_ENUMS( Behaviour )
Q_PROPERTY( QString colorRampDialogTitle READ colorRampDialogTitle WRITE setColorRampDialogTitle )
Q_PROPERTY( bool acceptLiveUpdates READ acceptLiveUpdates WRITE setAcceptLiveUpdates )
Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
Q_PROPERTY( Behaviour behaviour READ behaviour WRITE setBehaviour )
Q_PROPERTY( QgsColorRamp* defaultColorRamp READ defaultColorRamp WRITE setDefaultColorRamp )
Q_PROPERTY( QString context READ context WRITE setContext )

public:

/** Specifies the behaviour when the button is clicked
*/
enum Behaviour
{
ShowDialog = 0, //!< Show a color ramp dialog when clicked
SignalOnly //!< Emit colorRampClicked signal only, no dialog
};

/** Construct a new color ramp button.
* @param parent The parent QWidget for the dialog
* @param dialogTitle The title to show in the color ramp dialog
@@ -107,19 +97,6 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton
*/
bool showMenu() const { return menu() ? true : false; }

/** Sets the behaviour for when the button is clicked. The default behaviour is to show
* a color ramp dialog.
* @param behaviour behaviour when button is clicked
* @see behaviour
*/
void setBehaviour( const Behaviour behaviour );

/** Returns the behaviour for when the button is clicked.
* @returns behaviour when button is clicked
* @see setBehaviour
*/
Behaviour behaviour() const { return mBehaviour; }

/** Sets the default color ramp for the button, which is shown in the button's drop down menu for the
* "default color ramp" option.
* @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
*/
void colorRampChanged();

/** Emitted when the button is clicked, if the button's behaviour is set to SignalOnly
* @param colorramp Button's current color ramp
* @see setBehaviour
* @see behaviour
*/
void colorRampClicked( const QgsColorRamp* colorramp );

protected:

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

private:

Behaviour mBehaviour;
QString mColorRampDialogTitle;
bool mShowGradientOnly;
QgsColorRamp* mColorRamp;
@@ -161,6 +161,12 @@ def testQgsVectorGradientRampV2(self):
self.assertEqual(s[3].offset, 0.8)
self.assertEqual(s[3].color, QColor(50, 20, 10))

# test invert function
r.invert()
self.assertEqual(r.color(0), QColor(0, 200, 0))
self.assertEqual(r.color(1), QColor(200, 0, 0))
self.assertEqual(r.color(0.2), QColor(50, 20, 10))

def testQgsLimitedRandomColorRampV2(self):
# test random color ramp
r = QgsLimitedRandomColorRamp(5)
@@ -310,6 +316,11 @@ def testQgsPresetSchemeColorRamp(self):
self.assertEqual(cloned.count(), 2)
self.assertEqual(cloned.fetchColors(), r.fetchColors())

# test invert function
r.invert()
self.assertEqual(r.color(0), QColor(0, 255, 0))
self.assertEqual(r.color(1), QColor(255, 0, 0))

def testQgsColorBrewerColorRampV2(self):
# test color brewer color ramps
r = QgsColorBrewerColorRamp('OrRd', 6)
@@ -373,6 +384,13 @@ def testQgsColorBrewerColorRampV2(self):
self.assertEqual(r.color(0.8), QColor(222, 45, 38))
self.assertEqual(r.color(1.0), QColor(165, 15, 21))

# test invert function
r.invert()
self.assertEqual(r.color(0), QColor(165, 15, 21))
self.assertEqual(r.color(0.2), QColor(222, 45, 38))
self.assertEqual(r.color(1), QColor(254, 229, 217))
r.invert()

# set colors
r.setColors(3)
self.assertEqual(r.colors(), 3)

0 comments on commit a755f08

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