diff --git a/python/gui/auto_generated/qgssymbolbutton.sip.in b/python/gui/auto_generated/qgssymbolbutton.sip.in index 6c4e12b8106..a42dc115416 100644 --- a/python/gui/auto_generated/qgssymbolbutton.sip.in +++ b/python/gui/auto_generated/qgssymbolbutton.sip.in @@ -179,6 +179,52 @@ Pastes a color from the clipboard to the symbol. If clipboard does not contain a color or string representation of a color, then no change is applied. .. seealso:: :py:func:`copyColor` +%End + + void setShowNull( bool showNull ); +%Docstring +Sets whether a set to null (clear) option is shown in the button's drop-down menu. + +:param showNull: set to ``True`` to show a null option + +.. seealso:: :py:func:`showNull` + +.. seealso:: :py:func:`isNull` + +.. versionadded:: 3.26 +%End + + bool showNull() const; +%Docstring +Returns whether the set to null (clear) option is shown in the button's drop-down menu. + +.. seealso:: :py:func:`setShowNull` + +.. seealso:: :py:func:`isNull` + +.. versionadded:: 3.26 +%End + + bool isNull() const; +%Docstring +Returns ``True`` if the current color is null. + +.. seealso:: :py:func:`setShowNull` + +.. seealso:: :py:func:`showNull` + +.. versionadded:: 3.26 +%End + + void setToNull(); +%Docstring +Sets symbol to to null. + +.. seealso:: :py:func:`setShowNull` + +.. seealso:: :py:func:`showNull` + +.. versionadded:: 3.26 %End signals: diff --git a/src/gui/qgssymbolbutton.cpp b/src/gui/qgssymbolbutton.cpp index 4dc7526e8b9..822a2a21361 100644 --- a/src/gui/qgssymbolbutton.cpp +++ b/src/gui/qgssymbolbutton.cpp @@ -421,6 +421,14 @@ void QgsSymbolButton::prepareMenu() mMenu->addAction( pasteSymbolAction ); connect( pasteSymbolAction, &QAction::triggered, this, &QgsSymbolButton::pasteSymbol ); + if ( mShowNull ) + { + QAction *nullAction = new QAction( tr( "Clear Current Symbol" ), this ); + nullAction->setEnabled( !isNull() ); + mMenu->addAction( nullAction ); + connect( nullAction, &QAction::triggered, this, &QgsSymbolButton::setToNull ); + } + mMenu->addSeparator(); QgsColorWheel *colorWheel = new QgsColorWheel( mMenu ); @@ -717,3 +725,23 @@ QgsSymbol *QgsSymbolButton::symbol() { return mSymbol.get(); } + +void QgsSymbolButton::setShowNull( bool showNull ) +{ + mShowNull = showNull; +} + +bool QgsSymbolButton::showNull() const +{ + return mShowNull; +} + +bool QgsSymbolButton::isNull() const +{ + return !mSymbol; +} + +void QgsSymbolButton::setToNull() +{ + setSymbol( nullptr ); +} diff --git a/src/gui/qgssymbolbutton.h b/src/gui/qgssymbolbutton.h index d6550c49c89..e101ee3c84b 100644 --- a/src/gui/qgssymbolbutton.h +++ b/src/gui/qgssymbolbutton.h @@ -204,6 +204,39 @@ class GUI_EXPORT QgsSymbolButton : public QToolButton */ void pasteColor(); + /** + * Sets whether a set to null (clear) option is shown in the button's drop-down menu. + * \param showNull set to TRUE to show a null option + * \see showNull() + * \see isNull() + * \since QGIS 3.26 + */ + void setShowNull( bool showNull ); + + /** + * Returns whether the set to null (clear) option is shown in the button's drop-down menu. + * \see setShowNull() + * \see isNull() + * \since QGIS 3.26 + */ + bool showNull() const; + + /** + * Returns TRUE if the current color is null. + * \see setShowNull() + * \see showNull() + * \since QGIS 3.26 + */ + bool isNull() const; + + /** + * Sets symbol to to null. + * \see setShowNull() + * \see showNull() + * \since QGIS 3.26 + */ + void setToNull(); + signals: /** @@ -277,6 +310,8 @@ class GUI_EXPORT QgsSymbolButton : public QToolButton bool mPickingColor = false; + bool mShowNull = false; + /** * Regenerates the text preview. If \a color is specified, a temporary color preview * is shown instead.