From 968c82a30b08b1ac01c31fcb4720ccf20c6d21ca Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 2 Dec 2016 09:47:35 +1000 Subject: [PATCH] Small cleanups for QgsColorRampButton --- python/gui/qgscolorrampbutton.sip | 17 ++++++++--------- src/gui/qgscolorrampbutton.cpp | 2 +- src/gui/qgscolorrampbutton.h | 15 +++++++-------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/python/gui/qgscolorrampbutton.sip b/python/gui/qgscolorrampbutton.sip index 1d9a0aa6202..50025ddf4ea 100644 --- a/python/gui/qgscolorrampbutton.sip +++ b/python/gui/qgscolorrampbutton.sip @@ -25,11 +25,10 @@ class QgsColorRampButton : QToolButton virtual QSize sizeHint() const; - /** Return the current color ramp. - * @returns currently selected color - * @see setColor + /** Return a copy of the current color ramp. + * @see setColorRamp() */ - QgsColorRamp* colorRamp() const; + QgsColorRamp* colorRamp() const /Factory/; /** Set the title for the color ramp dialog window. * @param title Title for the color ramp dialog @@ -72,18 +71,18 @@ class QgsColorRampButton : QToolButton /** 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 - * ramp option. + * ramp option. The ramp will be cloned and ownership is not transferred. * @see defaultColorRamp */ void setDefaultColorRamp( QgsColorRamp* colorramp ); - /** Returns the default color ramp for the button, which is shown in the button's drop down menu for the + /** 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 setDefaultColorRamp */ - QgsColorRamp* defaultColorRamp() const; + QgsColorRamp* defaultColorRamp() const /Factory/; /** Sets whether a random colors option is shown in the button's drop down menu. * @param showNull set to true to show a null option @@ -152,7 +151,7 @@ class QgsColorRampButton : QToolButton /** Sets the current color ramp for the button. Will emit a colorRampChanged() signal if the color ramp is different * to the previous color ramp. - * @param colorramp New color ramp for the button + * @param colorramp New color ramp for the button. The ramp will be cloned and ownership is not transferred. * @see setRandomColorRamp, setColorRampFromName, colorRamp */ void setColorRamp( QgsColorRamp* colorramp ); @@ -168,7 +167,7 @@ class QgsColorRampButton : QToolButton * @param name Name of saved color ramp * @see setColorRamp, setRandomColorRamp, colorRamp */ - void setColorRampFromName( QString name = QString() ); + void setColorRampFromName( const QString& name = QString() ); /** Sets the background pixmap for the button based upon current color ramp. * @param colorramp Color ramp for button background. If no color ramp is specified, the button's current diff --git a/src/gui/qgscolorrampbutton.cpp b/src/gui/qgscolorrampbutton.cpp index 384965bdecc..838ad36e8b8 100644 --- a/src/gui/qgscolorrampbutton.cpp +++ b/src/gui/qgscolorrampbutton.cpp @@ -412,7 +412,7 @@ void QgsColorRampButton::setColorRamp( QgsColorRamp* colorramp ) mColorRampSet = true; } -void QgsColorRampButton::setColorRampFromName( QString name ) +void QgsColorRampButton::setColorRampFromName( const QString& name ) { if ( !name.isEmpty() ) { diff --git a/src/gui/qgscolorrampbutton.h b/src/gui/qgscolorrampbutton.h index 15442d31f39..ad186275772 100644 --- a/src/gui/qgscolorrampbutton.h +++ b/src/gui/qgscolorrampbutton.h @@ -53,9 +53,8 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton virtual QSize sizeHint() const override; - /** Return the current color ramp. - * @returns currently selected color - * @see setColor + /** Return a copy of the current color ramp. + * @see setColorRamp() */ QgsColorRamp* colorRamp() const; @@ -100,18 +99,18 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton /** 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 - * ramp option. + * ramp option. The ramp will be cloned and ownership is not transferred. * @see defaultColorRamp */ void setDefaultColorRamp( QgsColorRamp* colorramp ); - /** Returns the default color ramp for the button, which is shown in the button's drop down menu for the + /** 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 setDefaultColorRamp */ - QgsColorRamp* defaultColorRamp() const { return mDefaultColorRamp; } + QgsColorRamp* defaultColorRamp() const { return mDefaultColorRamp ? mDefaultColorRamp->clone() : nullptr ; } /** Sets whether a random colors option is shown in the button's drop down menu. * @param showRandom set to true to show a random colors option @@ -180,7 +179,7 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton /** Sets the current color ramp for the button. Will emit a colorRampChanged() signal if the color ramp is different * to the previous color ramp. - * @param colorramp New color ramp for the button + * @param colorramp New color ramp for the button. The ramp will be cloned and ownership is not transferred. * @see setRandomColorRamp, setColorRampFromName, colorRamp */ void setColorRamp( QgsColorRamp* colorramp ); @@ -196,7 +195,7 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton * @param name Name of saved color ramp * @see setColorRamp, setRandomColorRamp, colorRamp */ - void setColorRampFromName( QString name = QString() ); + void setColorRampFromName( const QString& name = QString() ); /** Sets the background pixmap for the button based upon current color ramp. * @param colorramp Color ramp for button background. If no color ramp is specified, the button's current