QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgscolorrampbutton.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscolorrampbutton.h - Color ramp button
3 --------------------------------------
4 Date : November 27, 2016
5 Copyright : (C) 2016 by Mathieu Pellerin
6 Email : nirvn dot asia at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSCOLORRAMPBUTTON_H
16#define QGSCOLORRAMPBUTTON_H
17
18#include "qgis_gui.h"
19#include "qgis_sip.h"
20
21#include <QToolButton>
22#include <memory>
23
24class QgsPanelWidget;
25class QgsColorRamp;
26class QgsStyle;
27
36class GUI_EXPORT QgsColorRampButton : public QToolButton
37{
38 Q_OBJECT
39 Q_PROPERTY( QString colorRampDialogTitle READ colorRampDialogTitle WRITE setColorRampDialogTitle )
40 Q_PROPERTY( bool acceptLiveUpdates READ acceptLiveUpdates WRITE setAcceptLiveUpdates )
41 Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
42 Q_PROPERTY( QgsColorRamp *defaultColorRamp READ defaultColorRamp WRITE setDefaultColorRamp )
43 Q_PROPERTY( QString context READ context WRITE setContext )
44
45 public:
46
52 QgsColorRampButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
53
55
56 QSize sizeHint() const override;
57
62 QgsColorRamp *colorRamp() const SIP_FACTORY;
63
69 void setColorRampDialogTitle( const QString &title );
70
76 QString colorRampDialogTitle() const;
77
83 bool acceptLiveUpdates() const { return mAcceptLiveUpdates; }
84
91 void setAcceptLiveUpdates( const bool accept ) { mAcceptLiveUpdates = accept; }
92
99 void setShowMenu( bool showMenu );
100
106 bool showMenu() const;
107
115 void setDefaultColorRamp( QgsColorRamp *colorramp );
116
124 QgsColorRamp *defaultColorRamp() const SIP_FACTORY;
125
131 void setShowRandomColorRamp( bool showRandom ) { mShowRandomColorRamp = showRandom; }
132
137 bool showRandomColorRamp() const { return mShowRandomColorRamp; }
138
144 bool isRandomColorRamp() const;
145
152 void setShowNull( bool showNull );
153
159 bool showNull() const;
160
166 bool isNull() const;
167
175 void setContext( const QString &context ) { mContext = context; }
176
184 QString context() const { return mContext; }
185
191 void setShowGradientOnly( bool gradientonly ) { mShowGradientOnly = gradientonly; }
192
197 bool showGradientOnly() const { return mShowGradientOnly; }
198
204 void setColorRampName( const QString &name ) { mColorRampName = name; }
205
210 QString colorRampName() const { return mColorRampName; }
211
212 public slots:
213
220 void setColorRamp( QgsColorRamp *colorramp );
221
227 void setRandomColorRamp();
228
235 void setColorRampFromName( const QString &name = QString() );
236
242 void setButtonBackground( QgsColorRamp *colorramp = nullptr );
243
250 void setToDefaultColorRamp();
251
256 void setToNull();
257
258 signals:
259
265
266 private slots:
267
268 void rampWidgetUpdated();
269
270 protected:
271
272 bool event( QEvent *e ) override;
273 void changeEvent( QEvent *e ) override;
274 void showEvent( QShowEvent *e ) override;
275 void resizeEvent( QResizeEvent *event ) override;
276
280 void mousePressEvent( QMouseEvent *e ) override;
281
282 private:
283
284 QString mColorRampDialogTitle;
285 bool mShowGradientOnly = false;
286 std::unique_ptr< QgsColorRamp > mColorRamp;
287 QString mColorRampName;
288 QgsStyle *mStyle = nullptr;
289
290 std::unique_ptr< QgsColorRamp > mDefaultColorRamp;
291 QString mContext;
292 bool mAcceptLiveUpdates = true;
293 bool mShowRandomColorRamp = false;
294 bool mShowNull = false;
295
296 QMenu *mMenu = nullptr;
297 QMenu *mAllRampsMenu = nullptr;
298
299 QSize mIconSize;
300
305 QPixmap createMenuIcon( QgsColorRamp *colorramp );
306
307 private slots:
308
309 void buttonClicked();
310
314 void showColorRampDialog();
315
319 void createColorRamp();
320
324 void saveColorRamp();
325
329 void invertColorRamp();
330
334 void loadColorRamp();
335
339 void prepareMenu();
340};
341
342#endif
A cross platform button subclass for selecting color ramps.
~QgsColorRampButton() override
bool showRandomColorRamp() const
Returns whether random colors option is shown in the button's drop-down menu.
void setShowGradientOnly(bool gradientonly)
Sets whether the color ramp button only shows gradient type ramps.
QString context() const
Returns the context string for the color ramp button.
void colorRampChanged()
Emitted whenever a new color ramp is set for the button.
void setAcceptLiveUpdates(const bool accept)
Sets whether the button accepts live updates from QgsColorRampDialog.
void setColorRampName(const QString &name)
Sets the name of the current color ramp when it's available in the style manager.
QString colorRampName() const
Returns the name of the current color ramp when it's available in the style manager.
bool showGradientOnly() const
Returns true if the color ramp button only shows gradient type ramps.
void setContext(const QString &context)
Sets the context string for the color ramp button.
Abstract base class for color ramps.
Definition: qgscolorramp.h:30
Base class for any widget that can be shown as a inline panel.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_FACTORY
Definition: qgis_sip.h:76