QGIS API Documentation 3.41.0-Master (cea29feecf2)
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:
50 QgsColorRampButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
51
52 ~QgsColorRampButton() override;
53
54 QSize sizeHint() const override;
55
60 QgsColorRamp *colorRamp() const SIP_FACTORY;
61
67 void setColorRampDialogTitle( const QString &title );
68
74 QString colorRampDialogTitle() const;
75
81 bool acceptLiveUpdates() const { return mAcceptLiveUpdates; }
82
89 void setAcceptLiveUpdates( const bool accept ) { mAcceptLiveUpdates = accept; }
90
97 void setShowMenu( bool showMenu );
98
104 bool showMenu() const;
105
113 void setDefaultColorRamp( QgsColorRamp *colorramp );
114
122 QgsColorRamp *defaultColorRamp() const SIP_FACTORY;
123
129 void setShowRandomColorRamp( bool showRandom ) { mShowRandomColorRamp = showRandom; }
130
135 bool showRandomColorRamp() const { return mShowRandomColorRamp; }
136
142 bool isRandomColorRamp() const;
143
150 void setShowNull( bool showNull );
151
157 bool showNull() const;
158
164 bool isNull() const;
165
173 void setContext( const QString &context ) { mContext = context; }
174
182 QString context() const { return mContext; }
183
189 void setShowGradientOnly( bool gradientonly ) { mShowGradientOnly = gradientonly; }
190
195 bool showGradientOnly() const { return mShowGradientOnly; }
196
202 void setColorRampName( const QString &name ) { mColorRampName = name; }
203
208 QString colorRampName() const { return mColorRampName; }
209
210 public slots:
211
220 void setColorRamp( QgsColorRamp *colorramp );
221
229 void setRandomColorRamp();
230
239 void setColorRampFromName( const QString &name = QString() );
240
246 void setButtonBackground( QgsColorRamp *colorramp = nullptr );
247
254 void setToDefaultColorRamp();
255
260 void setToNull();
261
262 signals:
263
269
270 private slots:
271
272 void rampWidgetUpdated();
273
274 protected:
275 bool event( QEvent *e ) override;
276 void changeEvent( QEvent *e ) override;
277 void showEvent( QShowEvent *e ) override;
278 void resizeEvent( QResizeEvent *event ) override;
279
283 void mousePressEvent( QMouseEvent *e ) override;
284
285 private:
286 QString mColorRampDialogTitle;
287 bool mShowGradientOnly = false;
288 std::unique_ptr<QgsColorRamp> mColorRamp;
289 QString mColorRampName;
290 QgsStyle *mStyle = nullptr;
291
292 std::unique_ptr<QgsColorRamp> mDefaultColorRamp;
293 QString mContext;
294 bool mAcceptLiveUpdates = true;
295 bool mShowRandomColorRamp = false;
296 bool mShowNull = false;
297
298 QMenu *mMenu = nullptr;
299 QMenu *mAllRampsMenu = nullptr;
300
301 QSize mIconSize;
302
307 QPixmap createMenuIcon( QgsColorRamp *colorramp );
308
309 private slots:
310
311 void buttonClicked();
312
316 void showColorRampDialog();
317
321 void createColorRamp();
322
326 void saveColorRamp();
327
331 void invertColorRamp();
332
336 void loadColorRamp();
337
341 void prepareMenu();
342};
343
344#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