Skip to content

Commit 968c82a

Browse files
committed
Small cleanups for QgsColorRampButton
1 parent c9058ed commit 968c82a

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

python/gui/qgscolorrampbutton.sip

+8-9
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ class QgsColorRampButton : QToolButton
2525

2626
virtual QSize sizeHint() const;
2727

28-
/** Return the current color ramp.
29-
* @returns currently selected color
30-
* @see setColor
28+
/** Return a copy of the current color ramp.
29+
* @see setColorRamp()
3130
*/
32-
QgsColorRamp* colorRamp() const;
31+
QgsColorRamp* colorRamp() const /Factory/;
3332

3433
/** Set the title for the color ramp dialog window.
3534
* @param title Title for the color ramp dialog
@@ -72,18 +71,18 @@ class QgsColorRampButton : QToolButton
7271
/** Sets the default color ramp for the button, which is shown in the button's drop down menu for the
7372
* "default color ramp" option.
7473
* @param colorramp default color ramp for the button. Set to a null pointer to disable the default color
75-
* ramp option.
74+
* ramp option. The ramp will be cloned and ownership is not transferred.
7675
* @see defaultColorRamp
7776
*/
7877
void setDefaultColorRamp( QgsColorRamp* colorramp );
7978

80-
/** Returns the default color ramp for the button, which is shown in the button's drop down menu for the
79+
/** Returns a copy of the default color ramp for the button, which is shown in the button's drop down menu for the
8180
* "default color ramp" option.
8281
* @returns default color ramp for the button. Returns a null pointer if the default color ramp
8382
* option is disabled.
8483
* @see setDefaultColorRamp
8584
*/
86-
QgsColorRamp* defaultColorRamp() const;
85+
QgsColorRamp* defaultColorRamp() const /Factory/;
8786

8887
/** Sets whether a random colors option is shown in the button's drop down menu.
8988
* @param showNull set to true to show a null option
@@ -152,7 +151,7 @@ class QgsColorRampButton : QToolButton
152151

153152
/** Sets the current color ramp for the button. Will emit a colorRampChanged() signal if the color ramp is different
154153
* to the previous color ramp.
155-
* @param colorramp New color ramp for the button
154+
* @param colorramp New color ramp for the button. The ramp will be cloned and ownership is not transferred.
156155
* @see setRandomColorRamp, setColorRampFromName, colorRamp
157156
*/
158157
void setColorRamp( QgsColorRamp* colorramp );
@@ -168,7 +167,7 @@ class QgsColorRampButton : QToolButton
168167
* @param name Name of saved color ramp
169168
* @see setColorRamp, setRandomColorRamp, colorRamp
170169
*/
171-
void setColorRampFromName( QString name = QString() );
170+
void setColorRampFromName( const QString& name = QString() );
172171

173172
/** Sets the background pixmap for the button based upon current color ramp.
174173
* @param colorramp Color ramp for button background. If no color ramp is specified, the button's current

src/gui/qgscolorrampbutton.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void QgsColorRampButton::setColorRamp( QgsColorRamp* colorramp )
412412
mColorRampSet = true;
413413
}
414414

415-
void QgsColorRampButton::setColorRampFromName( QString name )
415+
void QgsColorRampButton::setColorRampFromName( const QString& name )
416416
{
417417
if ( !name.isEmpty() )
418418
{

src/gui/qgscolorrampbutton.h

+7-8
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton
5353

5454
virtual QSize sizeHint() const override;
5555

56-
/** Return the current color ramp.
57-
* @returns currently selected color
58-
* @see setColor
56+
/** Return a copy of the current color ramp.
57+
* @see setColorRamp()
5958
*/
6059
QgsColorRamp* colorRamp() const;
6160

@@ -100,18 +99,18 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton
10099
/** Sets the default color ramp for the button, which is shown in the button's drop down menu for the
101100
* "default color ramp" option.
102101
* @param colorramp default color ramp for the button. Set to a null pointer to disable the default color
103-
* ramp option.
102+
* ramp option. The ramp will be cloned and ownership is not transferred.
104103
* @see defaultColorRamp
105104
*/
106105
void setDefaultColorRamp( QgsColorRamp* colorramp );
107106

108-
/** Returns the default color ramp for the button, which is shown in the button's drop down menu for the
107+
/** Returns a copy of the default color ramp for the button, which is shown in the button's drop down menu for the
109108
* "default color ramp" option.
110109
* @returns default color ramp for the button. Returns a null pointer if the default color ramp
111110
* option is disabled.
112111
* @see setDefaultColorRamp
113112
*/
114-
QgsColorRamp* defaultColorRamp() const { return mDefaultColorRamp; }
113+
QgsColorRamp* defaultColorRamp() const { return mDefaultColorRamp ? mDefaultColorRamp->clone() : nullptr ; }
115114

116115
/** Sets whether a random colors option is shown in the button's drop down menu.
117116
* @param showRandom set to true to show a random colors option
@@ -180,7 +179,7 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton
180179

181180
/** Sets the current color ramp for the button. Will emit a colorRampChanged() signal if the color ramp is different
182181
* to the previous color ramp.
183-
* @param colorramp New color ramp for the button
182+
* @param colorramp New color ramp for the button. The ramp will be cloned and ownership is not transferred.
184183
* @see setRandomColorRamp, setColorRampFromName, colorRamp
185184
*/
186185
void setColorRamp( QgsColorRamp* colorramp );
@@ -196,7 +195,7 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton
196195
* @param name Name of saved color ramp
197196
* @see setColorRamp, setRandomColorRamp, colorRamp
198197
*/
199-
void setColorRampFromName( QString name = QString() );
198+
void setColorRampFromName( const QString& name = QString() );
200199

201200
/** Sets the background pixmap for the button based upon current color ramp.
202201
* @param colorramp Color ramp for button background. If no color ramp is specified, the button's current

0 commit comments

Comments
 (0)