QGIS API Documentation 3.43.0-Master (c67cf405802)
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
38class GUI_EXPORT QgsColorRampButton : public QToolButton
39{
40 Q_OBJECT
41 Q_PROPERTY( QString colorRampDialogTitle READ colorRampDialogTitle WRITE setColorRampDialogTitle )
42 Q_PROPERTY( bool acceptLiveUpdates READ acceptLiveUpdates WRITE setAcceptLiveUpdates )
43 Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
44 Q_PROPERTY( QgsColorRamp *defaultColorRamp READ defaultColorRamp WRITE setDefaultColorRamp )
45 Q_PROPERTY( QString context READ context WRITE setContext )
46
47 public:
53 QgsColorRampButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
54
55 ~QgsColorRampButton() override;
56
57 QSize sizeHint() const override;
58
63 QgsColorRamp *colorRamp() const SIP_FACTORY;
64
70 void setColorRampDialogTitle( const QString &title );
71
77 QString colorRampDialogTitle() const;
78
84 bool acceptLiveUpdates() const { return mAcceptLiveUpdates; }
85
92 void setAcceptLiveUpdates( const bool accept ) { mAcceptLiveUpdates = accept; }
93
100 void setShowMenu( bool showMenu );
101
107 bool showMenu() const;
108
116 void setDefaultColorRamp( QgsColorRamp *colorramp );
117
125 QgsColorRamp *defaultColorRamp() const SIP_FACTORY;
126
132 void setShowRandomColorRamp( bool showRandom ) { mShowRandomColorRamp = showRandom; }
133
138 bool showRandomColorRamp() const { return mShowRandomColorRamp; }
139
145 bool isRandomColorRamp() const;
146
153 void setShowNull( bool showNull );
154
160 bool showNull() const;
161
167 bool isNull() const;
168
176 void setContext( const QString &context ) { mContext = context; }
177
185 QString context() const { return mContext; }
186
192 void setShowGradientOnly( bool gradientonly ) { mShowGradientOnly = gradientonly; }
193
198 bool showGradientOnly() const { return mShowGradientOnly; }
199
205 void setColorRampName( const QString &name ) { mColorRampName = name; }
206
211 QString colorRampName() const { return mColorRampName; }
212
213 public slots:
214
223 void setColorRamp( QgsColorRamp *colorramp );
224
232 void setRandomColorRamp();
233
242 void setColorRampFromName( const QString &name = QString() );
243
249 void setButtonBackground( QgsColorRamp *colorramp = nullptr );
250
257 void setToDefaultColorRamp();
258
263 void setToNull();
264
265 signals:
266
272
273 private slots:
274
275 void rampWidgetUpdated();
276
277 protected:
278 bool event( QEvent *e ) override;
279 void changeEvent( QEvent *e ) override;
280 void showEvent( QShowEvent *e ) override;
281 void resizeEvent( QResizeEvent *event ) override;
282
286 void mousePressEvent( QMouseEvent *e ) override;
287
288 private:
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 an inline panel.
A database of saved style entities, including symbols, color ramps, text formats and others.
Definition qgsstyle.h:88
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_FACTORY
Definition qgis_sip.h:76