Skip to content
Permalink
Browse files

Fix clearing colors for selection of mixed color cells in table editor

  • Loading branch information
nyalldawson committed Feb 5, 2020
1 parent f8d863c commit 60d89ecc3a2a07da9820c07ab2ff95c40a6a44f3
@@ -415,6 +415,8 @@ Sets color to null.

.. seealso:: :py:func:`setToNoColor`

.. seealso:: :py:func:`cleared`

.. versionadded:: 2.16
%End

@@ -448,6 +450,15 @@ Emitted when the button is clicked, if the button's behavior is set to SignalOnl
.. seealso:: :py:func:`setBehavior`

.. seealso:: :py:func:`behavior`
%End

void cleared();
%Docstring
Emitted when the color is cleared (set to null).

.. seealso:: :py:func:`setToNull`

.. versionadded:: 3.12
%End

void unlinked();
@@ -160,6 +160,7 @@ void QgsColorButton::setToDefaultColor()
void QgsColorButton::setToNull()
{
setColor( QColor() );
emit cleared();
}

void QgsColorButton::unlink()
@@ -362,6 +362,7 @@ class GUI_EXPORT QgsColorButton : public QToolButton
* Sets color to null.
* \see setToDefaultColor()
* \see setToNoColor()
* \see cleared()
* \since QGIS 2.16
*/
void setToNull();
@@ -393,6 +394,14 @@ class GUI_EXPORT QgsColorButton : public QToolButton
*/
void colorClicked( const QColor &color );

/**
* Emitted when the color is cleared (set to null).
*
* \see setToNull()
* \since QGIS 3.12
*/
void cleared();

/**
* Emitted when the color is unlinked, e.g. when it was previously set to link
* to a project color and is now no longer linked.
@@ -43,11 +43,21 @@ QgsTableEditorFormattingWidget::QgsTableEditorFormattingWidget( QWidget *parent
if ( !mBlockSignals )
emit foregroundColorChanged( mTextColorButton->color() );
} );
connect( mTextColorButton, &QgsColorButton::cleared, this, [ = ]
{
if ( !mBlockSignals )
emit foregroundColorChanged( QColor() );
} );
connect( mBackgroundColorButton, &QgsColorButton::colorChanged, this, [ = ]
{
if ( !mBlockSignals )
emit backgroundColorChanged( mBackgroundColorButton->color() );
} );
connect( mBackgroundColorButton, &QgsColorButton::cleared, this, [ = ]
{
if ( !mBlockSignals )
emit backgroundColorChanged( QColor() );
} );

connect( mFormatNumbersCheckBox, &QCheckBox::stateChanged, this, [ = ]( int state )
{
@@ -39,6 +39,39 @@ def testClearingColors(self):
# ensure that only the alpha channel has changed - not the other color components
self.assertEqual(button.color(), QColor(255, 100, 200, 0))

def testNulling(self):
"""
Test clearing colors to null
"""

# start with a valid color
button = QgsColorButton()
button.setAllowOpacity(True)
button.setColor(QColor(255, 100, 200, 255))
self.assertEqual(button.color(), QColor(255, 100, 200, 255))

spy_changed = QSignalSpy(button.colorChanged)
spy_cleared = QSignalSpy(button.cleared)

button.setColor(QColor(50, 100, 200, 255))
self.assertEqual(button.color(), QColor(50, 100, 200, 255))
self.assertEqual(len(spy_changed), 1)
self.assertEqual(len(spy_cleared), 0)

# now set to null
button.setToNull()

self.assertEqual(button.color(), QColor())
self.assertEqual(len(spy_changed), 2)
self.assertEqual(len(spy_cleared), 1)

button.setToNull()
self.assertEqual(button.color(), QColor())
# should not be refired, the color wasn't changed
self.assertEqual(len(spy_changed), 2)
# SHOULD be refired
self.assertEqual(len(spy_cleared), 2)

def testLinkProjectColor(self):
"""
Test linking to a project color

0 comments on commit 60d89ec

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