QGIS API Documentation  2.99.0-Master (d55fa22)
Public Slots | Signals | Public Member Functions | Protected Member Functions | Properties | List of all members
QgsColorRampButton Class Reference

A cross platform button subclass for selecting color ramps. More...

#include <qgscolorrampbutton.h>

Inheritance diagram for QgsColorRampButton:
Inheritance graph
[legend]

Public Slots

void setButtonBackground (QgsColorRamp *colorramp=nullptr)
 Sets the background pixmap for the button based upon current color ramp. More...
 
void setColorRamp (QgsColorRamp *colorramp)
 Sets the current color ramp for the button. More...
 
void setColorRampFromName (const QString &name=QString())
 Sets the current color ramp for the button using a saved color ramp name. More...
 
void setRandomColorRamp ()
 Sets the current color ramp for the button to random colors. More...
 
void setToDefaultColorRamp ()
 Sets color ramp to the button's default color ramp, if set. More...
 
void setToNull ()
 Sets color ramp to null. More...
 

Signals

void colorRampChanged ()
 Emitted whenever a new color ramp is set for the button. More...
 

Public Member Functions

 QgsColorRampButton (QWidget *parent=nullptr, const QString &dialogTitle=QString())
 Construct a new color ramp button. More...
 
virtual ~QgsColorRampButton ()
 
bool acceptLiveUpdates () const
 Returns whether the button accepts live updates from QgsColorRampDialog. More...
 
QgsColorRampcolorRamp () const
 Return a copy of the current color ramp. More...
 
QString colorRampDialogTitle () const
 Returns the title for the color ramp dialog window. More...
 
QString colorRampName () const
 Returns the name of the current color ramp when it's available in the style manager. More...
 
QString context () const
 Returns the context string for the color ramp button. More...
 
QgsColorRampdefaultColorRamp () const
 Returns a copy of the default color ramp for the button, which is shown in the button's drop down menu for the "default color ramp" option. More...
 
bool isNull () const
 Returns true if the current color is null. More...
 
bool isRandomColorRamp () const
 Returns true if the current color is null. More...
 
void setAcceptLiveUpdates (const bool accept)
 Sets whether the button accepts live updates from QgsColorRampDialog. More...
 
void setColorRampDialogTitle (const QString &title)
 Set the title for the color ramp dialog window. More...
 
void setColorRampName (const QString &name)
 Sets the name of the current color ramp when it's available in the style manager. More...
 
void setContext (const QString &context)
 Sets the context string for the color ramp button. More...
 
void setDefaultColorRamp (QgsColorRamp *colorramp)
 Sets the default color ramp for the button, which is shown in the button's drop down menu for the "default color ramp" option. More...
 
void setShowGradientOnly (bool gradientonly)
 Sets whether the color ramp button only shows gradient type ramps. More...
 
void setShowMenu (const bool showMenu)
 Sets whether the drop down menu should be shown for the button. More...
 
void setShowNull (bool showNull)
 Sets whether a set to null (clear) option is shown in the button's drop down menu. More...
 
void setShowRandomColorRamp (bool showRandom)
 Sets whether a random colors option is shown in the button's drop down menu. More...
 
bool showGradientOnly () const
 Returns true if the color ramp button only shows gradient type ramps. More...
 
bool showMenu () const
 Returns whether the drop down menu is shown for the button. More...
 
bool showNull () const
 Returns whether the set to null (clear) option is shown in the button's drop down menu. More...
 
bool showRandomColorRamp () const
 Returns whether random colors option is shown in the button's drop down menu. More...
 
virtual QSize sizeHint () const override
 

Protected Member Functions

void changeEvent (QEvent *e) override
 
bool event (QEvent *e) override
 
void mousePressEvent (QMouseEvent *e) override
 Reimplemented to detect right mouse button clicks on the color ramp button. More...
 
void resizeEvent (QResizeEvent *event) override
 
void showEvent (QShowEvent *e) override
 

Properties

bool acceptLiveUpdates
 
QString colorRampDialogTitle
 
QString context
 
QgsColorRamp defaultColorRamp
 
bool showMenu
 

Detailed Description

A cross platform button subclass for selecting color ramps.

Will open color ramp dialogs when clicked. Offers live updates to button from color ramp dialog. An attached drop down menu allows for access to saved color ramps, as well as option to invert the current color ramp and create new ramps.

Since
QGIS 3.0

Definition at line 36 of file qgscolorrampbutton.h.

Constructor & Destructor Documentation

◆ QgsColorRampButton()

QgsColorRampButton::QgsColorRampButton ( QWidget *  parent = nullptr,
const QString &  dialogTitle = QString() 
)

Construct a new color ramp button.

Use parent to attach a parent QWidget to the dialog. Use dialogTitle string to define the title to show in the color ramp dialog

Definition at line 39 of file qgscolorrampbutton.cpp.

◆ ~QgsColorRampButton()

QgsColorRampButton::~QgsColorRampButton ( )
virtual

Definition at line 69 of file qgscolorrampbutton.cpp.

Member Function Documentation

◆ acceptLiveUpdates()

bool QgsColorRampButton::acceptLiveUpdates ( ) const
inline

Returns whether the button accepts live updates from QgsColorRampDialog.

Returns
true if the button will be accepted immediately when the dialog's color ramp changes
See also
setAcceptLiveUpdates

Definition at line 78 of file qgscolorrampbutton.h.

◆ changeEvent()

void QgsColorRampButton::changeEvent ( QEvent *  e)
overrideprotected

Definition at line 439 of file qgscolorrampbutton.cpp.

◆ colorRamp()

QgsColorRamp * QgsColorRampButton::colorRamp ( ) const

Return a copy of the current color ramp.

See also
setColorRamp()

Definition at line 584 of file qgscolorrampbutton.cpp.

◆ colorRampChanged

void QgsColorRampButton::colorRampChanged ( )
signal

Emitted whenever a new color ramp is set for the button.

The color ramp is always valid. In case the new color ramp is the same, no signal is emitted to avoid infinite loops.

◆ colorRampDialogTitle()

QString QgsColorRampButton::colorRampDialogTitle ( ) const

Returns the title for the color ramp dialog window.

Returns
title for the color ramp dialog
See also
setColorRampDialogTitle

◆ colorRampName()

QString QgsColorRampButton::colorRampName ( ) const
inline

Returns the name of the current color ramp when it's available in the style manager.

See also
setColorRampName

Definition at line 188 of file qgscolorrampbutton.h.

◆ context()

QString QgsColorRampButton::context ( ) const
inline

Returns the context string for the color ramp button.

The context string is passed to all color ramp preview icons shown in the button's drop down menu, to (eventually) allow them to customise their display colors based on the context.

Returns
context context string for the color dialog button's color ramp preview icons
See also
setContext

Definition at line 166 of file qgscolorrampbutton.h.

◆ defaultColorRamp()

QgsColorRamp* QgsColorRampButton::defaultColorRamp ( ) const
inline

Returns a copy of the default color ramp for the button, which is shown in the button's drop down menu for the "default color ramp" option.

Returns
default color ramp for the button. Returns a null pointer if the default color ramp option is disabled.
See also
setDefaultColorRamp

Definition at line 114 of file qgscolorrampbutton.h.

◆ event()

bool QgsColorRampButton::event ( QEvent *  e)
overrideprotected

Definition at line 196 of file qgscolorrampbutton.cpp.

◆ isNull()

bool QgsColorRampButton::isNull ( ) const

Returns true if the current color is null.

See also
setShowNull()
showNull()

Definition at line 630 of file qgscolorrampbutton.cpp.

◆ isRandomColorRamp()

bool QgsColorRampButton::isRandomColorRamp ( ) const

Returns true if the current color is null.

See also
setShowNull()
showNull()

Definition at line 614 of file qgscolorrampbutton.cpp.

◆ mousePressEvent()

void QgsColorRampButton::mousePressEvent ( QMouseEvent *  e)
overrideprotected

Reimplemented to detect right mouse button clicks on the color ramp button.

Definition at line 208 of file qgscolorrampbutton.cpp.

◆ resizeEvent()

void QgsColorRampButton::resizeEvent ( QResizeEvent *  event)
overrideprotected

Definition at line 466 of file qgscolorrampbutton.cpp.

◆ setAcceptLiveUpdates()

void QgsColorRampButton::setAcceptLiveUpdates ( const bool  accept)
inline

Sets whether the button accepts live updates from QgsColorRampDialog.

Live updates may cause changes that are not undoable on QColorRampDialog cancel.

Parameters
acceptset to true to enable live updates
See also
acceptLiveUpdates

Definition at line 85 of file qgscolorrampbutton.h.

◆ setButtonBackground

void QgsColorRampButton::setButtonBackground ( QgsColorRamp colorramp = nullptr)
slot

Sets the background pixmap for the button based upon current color ramp.

Parameters
colorrampColor ramp for button background. If no color ramp is specified, the button's current color ramp will be used

Definition at line 513 of file qgscolorrampbutton.cpp.

◆ setColorRamp

void QgsColorRampButton::setColorRamp ( QgsColorRamp colorramp)
slot

Sets the current color ramp for the button.

Will emit a colorRampChanged() signal if the color ramp is different to the previous color ramp.

Parameters
colorrampNew color ramp for the button. The ramp will be cloned and ownership is not transferred.
See also
setRandomColorRamp, setColorRampFromName, colorRamp

Definition at line 474 of file qgscolorrampbutton.cpp.

◆ setColorRampDialogTitle()

void QgsColorRampButton::setColorRampDialogTitle ( const QString &  title)

Set the title for the color ramp dialog window.

Parameters
titleTitle for the color ramp dialog
See also
colorRampDialogTitle

Definition at line 589 of file qgscolorrampbutton.cpp.

◆ setColorRampFromName

void QgsColorRampButton::setColorRampFromName ( const QString &  name = QString())
slot

Sets the current color ramp for the button using a saved color ramp name.

Will emit a colorRampChanged() signal if the color ramp is different to the previous color ramp.

Parameters
nameName of saved color ramp
See also
setColorRamp, setRandomColorRamp, colorRamp

Definition at line 492 of file qgscolorrampbutton.cpp.

◆ setColorRampName()

void QgsColorRampButton::setColorRampName ( const QString &  name)
inline

Sets the name of the current color ramp when it's available in the style manager.

Parameters
nameName of the saved color ramp
See also
colorRampName

Definition at line 183 of file qgscolorrampbutton.h.

◆ setContext()

void QgsColorRampButton::setContext ( const QString &  context)
inline

Sets the context string for the color ramp button.

The context string is passed to all color ramp preview icons shown in the button's drop down menu, to (eventually) allow them to customise their display colors based on the context.

Parameters
contextcontext string for the color dialog button's color ramp preview icons
See also
context

Definition at line 158 of file qgscolorrampbutton.h.

◆ setDefaultColorRamp()

void QgsColorRampButton::setDefaultColorRamp ( QgsColorRamp colorramp)

Sets the default color ramp for the button, which is shown in the button's drop down menu for the "default color ramp" option.

Parameters
colorrampdefault color ramp for the button. Set to a null pointer to disable the default color ramp option. The ramp will be cloned and ownership is not transferred.
See also
defaultColorRamp

Definition at line 608 of file qgscolorrampbutton.cpp.

◆ setRandomColorRamp

void QgsColorRampButton::setRandomColorRamp ( )
slot

Sets the current color ramp for the button to random colors.

Will emit a colorRampChanged() signal if the color ramp is different to the previous color ramp.

See also
setColorRamp, setColorRampFromName, colorRamp

Definition at line 504 of file qgscolorrampbutton.cpp.

◆ setShowGradientOnly()

void QgsColorRampButton::setShowGradientOnly ( bool  gradientonly)
inline

Sets whether the color ramp button only shows gradient type ramps.

Parameters
gradientonlyset to true to show only gradient type ramps
See also
showGradientOnly

Definition at line 172 of file qgscolorrampbutton.h.

◆ setShowMenu()

void QgsColorRampButton::setShowMenu ( const bool  showMenu)

Sets whether the drop down menu should be shown for the button.

The default behavior is to show the menu.

Parameters
showMenuset to false to hide the drop down menu
See also
showMenu

Definition at line 599 of file qgscolorrampbutton.cpp.

◆ setShowNull()

void QgsColorRampButton::setShowNull ( bool  showNull)

Sets whether a set to null (clear) option is shown in the button's drop down menu.

Parameters
showNullset to true to show a null option
See also
showNull()
isNull()

Definition at line 620 of file qgscolorrampbutton.cpp.

◆ setShowRandomColorRamp()

void QgsColorRampButton::setShowRandomColorRamp ( bool  showRandom)
inline

Sets whether a random colors option is shown in the button's drop down menu.

Parameters
showRandomset to true to show a random colors option
See also
showRandom()

Definition at line 120 of file qgscolorrampbutton.h.

◆ setToDefaultColorRamp

void QgsColorRampButton::setToDefaultColorRamp ( )
slot

Sets color ramp to the button's default color ramp, if set.

See also
setDefaultColorRamp
defaultColorRamp
setToNull()

Definition at line 181 of file qgscolorrampbutton.cpp.

◆ setToNull

void QgsColorRampButton::setToNull ( )
slot

Sets color ramp to null.

See also
setToDefaultColorRamp()

Definition at line 191 of file qgscolorrampbutton.cpp.

◆ showEvent()

void QgsColorRampButton::showEvent ( QShowEvent *  e)
overrideprotected

Definition at line 460 of file qgscolorrampbutton.cpp.

◆ showGradientOnly()

bool QgsColorRampButton::showGradientOnly ( ) const
inline

Returns true if the color ramp button only shows gradient type ramps.

See also
setShowGradientOnly

Definition at line 177 of file qgscolorrampbutton.h.

◆ showMenu()

bool QgsColorRampButton::showMenu ( ) const
inline

Returns whether the drop down menu is shown for the button.

Returns
true if drop down menu is shown
See also
setShowMenu

Definition at line 98 of file qgscolorrampbutton.h.

◆ showNull()

bool QgsColorRampButton::showNull ( ) const

Returns whether the set to null (clear) option is shown in the button's drop down menu.

See also
setShowNull()
isNull()

Definition at line 625 of file qgscolorrampbutton.cpp.

◆ showRandomColorRamp()

bool QgsColorRampButton::showRandomColorRamp ( ) const
inline

Returns whether random colors option is shown in the button's drop down menu.

See also
setShowRandom()

Definition at line 125 of file qgscolorrampbutton.h.

◆ sizeHint()

QSize QgsColorRampButton::sizeHint ( ) const
overridevirtual

Definition at line 75 of file qgscolorrampbutton.cpp.

Property Documentation

◆ acceptLiveUpdates

bool QgsColorRampButton::acceptLiveUpdates
readwrite

Definition at line 40 of file qgscolorrampbutton.h.

◆ colorRampDialogTitle

QString QgsColorRampButton::colorRampDialogTitle
readwrite

Definition at line 39 of file qgscolorrampbutton.h.

◆ context

QString QgsColorRampButton::context
readwrite

Definition at line 43 of file qgscolorrampbutton.h.

◆ defaultColorRamp

QgsColorRamp QgsColorRampButton::defaultColorRamp
readwrite

Definition at line 42 of file qgscolorrampbutton.h.

◆ showMenu

bool QgsColorRampButton::showMenu
readwrite

Definition at line 41 of file qgscolorrampbutton.h.


The documentation for this class was generated from the following files: