QGIS API Documentation 3.37.0-Master (684a802617f)
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
219 void setColorRamp( QgsColorRamp *colorramp );
220
226 void setRandomColorRamp();
227
234 void setColorRampFromName( const QString &name = QString() );
235
241 void setButtonBackground( QgsColorRamp *colorramp = nullptr );
242
249 void setToDefaultColorRamp();
250
255 void setToNull();
256
257 signals:
258
264
265 private slots:
266
267 void rampWidgetUpdated();
268
269 protected:
270
271 bool event( QEvent *e ) override;
272 void changeEvent( QEvent *e ) override;
273 void showEvent( QShowEvent *e ) override;
274 void resizeEvent( QResizeEvent *event ) override;
275
279 void mousePressEvent( QMouseEvent *e ) override;
280
281 private:
282
283 QString mColorRampDialogTitle;
284 bool mShowGradientOnly = false;
285 std::unique_ptr< QgsColorRamp > mColorRamp;
286 QString mColorRampName;
287 QgsStyle *mStyle = nullptr;
288
289 std::unique_ptr< QgsColorRamp > mDefaultColorRamp;
290 QString mContext;
291 bool mAcceptLiveUpdates = true;
292 bool mShowRandomColorRamp = false;
293 bool mShowNull = false;
294
295 QMenu *mMenu = nullptr;
296 QMenu *mAllRampsMenu = nullptr;
297
298 QSize mIconSize;
299
304 QPixmap createMenuIcon( QgsColorRamp *colorramp );
305
306 private slots:
307
308 void buttonClicked();
309
313 void showColorRampDialog();
314
318 void createColorRamp();
319
323 void saveColorRamp();
324
328 void invertColorRamp();
329
333 void loadColorRamp();
334
338 void prepareMenu();
339};
340
341#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