QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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
35class GUI_EXPORT QgsColorRampButton : public QToolButton
36{
37 Q_OBJECT
38 Q_PROPERTY( QString colorRampDialogTitle READ colorRampDialogTitle WRITE setColorRampDialogTitle )
39 Q_PROPERTY( bool acceptLiveUpdates READ acceptLiveUpdates WRITE setAcceptLiveUpdates )
40 Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
41 Q_PROPERTY( QgsColorRamp *defaultColorRamp READ defaultColorRamp WRITE setDefaultColorRamp )
42 Q_PROPERTY( QString context READ context WRITE setContext )
43
44 public:
45
51 QgsColorRampButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
52
53 ~QgsColorRampButton() override;
54
55 QSize sizeHint() const override;
56
61 QgsColorRamp *colorRamp() const SIP_FACTORY;
62
68 void setColorRampDialogTitle( const QString &title );
69
75 QString colorRampDialogTitle() const;
76
82 bool acceptLiveUpdates() const { return mAcceptLiveUpdates; }
83
90 void setAcceptLiveUpdates( const bool accept ) { mAcceptLiveUpdates = accept; }
91
98 void setShowMenu( bool showMenu );
99
105 bool showMenu() const;
106
114 void setDefaultColorRamp( QgsColorRamp *colorramp );
115
123 QgsColorRamp *defaultColorRamp() const SIP_FACTORY;
124
130 void setShowRandomColorRamp( bool showRandom ) { mShowRandomColorRamp = showRandom; }
131
136 bool showRandomColorRamp() const { return mShowRandomColorRamp; }
137
143 bool isRandomColorRamp() const;
144
151 void setShowNull( bool showNull );
152
158 bool showNull() const;
159
165 bool isNull() const;
166
174 void setContext( const QString &context ) { mContext = context; }
175
183 QString context() const { return mContext; }
184
190 void setShowGradientOnly( bool gradientonly ) { mShowGradientOnly = gradientonly; }
191
196 bool showGradientOnly() const { return mShowGradientOnly; }
197
203 void setColorRampName( const QString &name ) { mColorRampName = name; }
204
209 QString colorRampName() const { return mColorRampName; }
210
211 public slots:
212
221 void setColorRamp( QgsColorRamp *colorramp );
222
230 void setRandomColorRamp();
231
240 void setColorRampFromName( const QString &name = QString() );
241
247 void setButtonBackground( QgsColorRamp *colorramp = nullptr );
248
255 void setToDefaultColorRamp();
256
261 void setToNull();
262
263 signals:
264
270
271 private slots:
272
273 void rampWidgetUpdated();
274
275 protected:
276
277 bool event( QEvent *e ) override;
278 void changeEvent( QEvent *e ) override;
279 void showEvent( QShowEvent *e ) override;
280 void resizeEvent( QResizeEvent *event ) override;
281
285 void mousePressEvent( QMouseEvent *e ) override;
286
287 private:
288
289 QString mColorRampDialogTitle;
290 bool mShowGradientOnly = false;
291 std::unique_ptr< QgsColorRamp > mColorRamp;
292 QString mColorRampName;
293 QgsStyle *mStyle = nullptr;
294
295 std::unique_ptr< QgsColorRamp > mDefaultColorRamp;
296 QString mContext;
297 bool mAcceptLiveUpdates = true;
298 bool mShowRandomColorRamp = false;
299 bool mShowNull = false;
300
301 QMenu *mMenu = nullptr;
302 QMenu *mAllRampsMenu = nullptr;
303
304 QSize mIconSize;
305
310 QPixmap createMenuIcon( QgsColorRamp *colorramp );
311
312 private slots:
313
314 void buttonClicked();
315
319 void showColorRampDialog();
320
324 void createColorRamp();
325
329 void saveColorRamp();
330
334 void invertColorRamp();
335
339 void loadColorRamp();
340
344 void prepareMenu();
345};
346
347#endif
A cross platform button subclass for selecting color ramps.
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.
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