QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 <memory>
19
20#include "qgis_gui.h"
21#include "qgis_sip.h"
22
23#include <QToolButton>
24
25class QgsPanelWidget;
26class QgsColorRamp;
27class QgsStyle;
28
39class GUI_EXPORT QgsColorRampButton : public QToolButton
40{
41 Q_OBJECT
44 Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
46 Q_PROPERTY( QString context READ context WRITE setContext )
47
48 public:
49
55 QgsColorRampButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
56
57 ~QgsColorRampButton() override;
58
59 QSize sizeHint() const override;
60
66
72 void setColorRampDialogTitle( const QString &title );
73
79 QString colorRampDialogTitle() const;
80
86 bool acceptLiveUpdates() const { return mAcceptLiveUpdates; }
87
94 void setAcceptLiveUpdates( const bool accept ) { mAcceptLiveUpdates = accept; }
95
102 void setShowMenu( bool showMenu );
103
109 bool showMenu() const;
110
118 void setDefaultColorRamp( QgsColorRamp *colorramp );
119
127 QgsColorRamp *defaultColorRamp() const SIP_FACTORY;
128
134 void setShowRandomColorRamp( bool showRandom ) { mShowRandomColorRamp = showRandom; }
135
140 bool showRandomColorRamp() const { return mShowRandomColorRamp; }
141
147 bool isRandomColorRamp() const;
148
155 void setShowNull( bool showNull );
156
162 bool showNull() const;
163
169 bool isNull() const;
170
178 void setContext( const QString &context ) { mContext = context; }
179
187 QString context() const { return mContext; }
188
194 void setShowGradientOnly( bool gradientonly ) { mShowGradientOnly = gradientonly; }
195
200 bool showGradientOnly() const { return mShowGradientOnly; }
201
207 void setColorRampName( const QString &name ) { mColorRampName = name; }
208
213 QString colorRampName() const { return mColorRampName; }
214
215 public slots:
216
225 void setColorRamp( QgsColorRamp *colorramp );
226
234 void setRandomColorRamp();
235
244 void setColorRampFromName( const QString &name = QString() );
245
251 void setButtonBackground( QgsColorRamp *colorramp = nullptr );
252
259 void setToDefaultColorRamp();
260
265 void setToNull();
266
267 signals:
268
274
275 private slots:
276
277 void rampWidgetUpdated();
278
279 protected:
280 bool event( QEvent *e ) override;
281 void changeEvent( QEvent *e ) override;
282 void showEvent( QShowEvent *e ) override;
283 void resizeEvent( QResizeEvent *event ) override;
284
288 void mousePressEvent( QMouseEvent *e ) override;
289
290 private:
291 QString mColorRampDialogTitle;
292 bool mShowGradientOnly = false;
293 std::unique_ptr<QgsColorRamp> mColorRamp;
294 QString mColorRampName;
295 QgsStyle *mStyle = nullptr;
296
297 std::unique_ptr<QgsColorRamp> mDefaultColorRamp;
298 QString mContext;
299 bool mAcceptLiveUpdates = true;
300 bool mShowRandomColorRamp = false;
301 bool mShowNull = false;
302
303 QMenu *mMenu = nullptr;
304 QMenu *mAllRampsMenu = nullptr;
305
306 QSize mIconSize;
307
312 QPixmap createMenuIcon( QgsColorRamp *colorramp );
313
314 private slots:
315
316 void buttonClicked();
317
321 void showColorRampDialog();
322
326 void createColorRamp();
327
331 void saveColorRamp();
332
336 void invertColorRamp();
337
341 void loadColorRamp();
342
346 void prepareMenu();
347};
348
349#endif
void changeEvent(QEvent *e) override
QgsColorRamp * defaultColorRamp
void setColorRampDialogTitle(const QString &title)
Set the title for the color ramp dialog window.
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 setShowRandomColorRamp(bool showRandom)
Sets whether a random colors option is shown in the button's drop-down menu.
QgsColorRamp * colorRamp() const
Returns a copy of the current color ramp.
void setDefaultColorRamp(QgsColorRamp *colorramp)
Sets the default color ramp for the button, which is shown in the button's drop-down menu for the "de...
void resizeEvent(QResizeEvent *event) override
void colorRampChanged()
Emitted whenever a new color ramp is set for the button.
void setShowMenu(bool showMenu)
Sets whether the drop-down menu should be shown for the button.
void setAcceptLiveUpdates(const bool accept)
Sets whether the button accepts live updates from QgsColorRampDialog.
QSize sizeHint() const override
QgsColorRampButton(QWidget *parent=nullptr, const QString &dialogTitle=QString())
Construct a new color ramp button.
void setColorRampName(const QString &name)
Sets the name of the current color ramp when it's available in the style manager.
void showEvent(QShowEvent *e) override
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 mousePressEvent(QMouseEvent *e) override
Reimplemented to detect right mouse button clicks on the color ramp button.
void setContext(const QString &context)
Sets the context string for the color ramp button.
bool event(QEvent *e) override
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:84