QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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:
54 QgsColorRampButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
55
56 ~QgsColorRampButton() override;
57
58 QSize sizeHint() const override;
59
65
71 void setColorRampDialogTitle( const QString &title );
72
78 QString colorRampDialogTitle() const;
79
85 bool acceptLiveUpdates() const { return mAcceptLiveUpdates; }
86
93 void setAcceptLiveUpdates( const bool accept ) { mAcceptLiveUpdates = accept; }
94
101 void setShowMenu( bool showMenu );
102
108 bool showMenu() const;
109
117 void setDefaultColorRamp( QgsColorRamp *colorramp );
118
126 QgsColorRamp *defaultColorRamp() const SIP_FACTORY;
127
133 void setShowRandomColorRamp( bool showRandom ) { mShowRandomColorRamp = showRandom; }
134
139 bool showRandomColorRamp() const { return mShowRandomColorRamp; }
140
146 bool isRandomColorRamp() const;
147
154 void setShowNull( bool showNull );
155
161 bool showNull() const;
162
168 bool isNull() const;
169
177 void setContext( const QString &context ) { mContext = context; }
178
186 QString context() const { return mContext; }
187
193 void setShowGradientOnly( bool gradientonly ) { mShowGradientOnly = gradientonly; }
194
199 bool showGradientOnly() const { return mShowGradientOnly; }
200
206 void setColorRampName( const QString &name ) { mColorRampName = name; }
207
212 QString colorRampName() const { return mColorRampName; }
213
214 public slots:
215
224 void setColorRamp( QgsColorRamp *colorramp );
225
233 void setRandomColorRamp();
234
243 void setColorRampFromName( const QString &name = QString() );
244
250 void setButtonBackground( QgsColorRamp *colorramp = nullptr );
251
258 void setToDefaultColorRamp();
259
264 void setToNull();
265
266 signals:
267
273
274 private slots:
275
276 void rampWidgetUpdated();
277
278 protected:
279 bool event( QEvent *e ) override;
280 void changeEvent( QEvent *e ) override;
281 void showEvent( QShowEvent *e ) override;
282 void resizeEvent( QResizeEvent *event ) override;
283
287 void mousePressEvent( QMouseEvent *e ) override;
288
289 private:
290 QString mColorRampDialogTitle;
291 bool mShowGradientOnly = false;
292 std::unique_ptr<QgsColorRamp> mColorRamp;
293 QString mColorRampName;
294 QgsStyle *mStyle = nullptr;
295
296 std::unique_ptr<QgsColorRamp> mDefaultColorRamp;
297 QString mContext;
298 bool mAcceptLiveUpdates = true;
299 bool mShowRandomColorRamp = false;
300 bool mShowNull = false;
301
302 QMenu *mMenu = nullptr;
303 QMenu *mAllRampsMenu = nullptr;
304
305 QSize mIconSize;
306
311 QPixmap createMenuIcon( QgsColorRamp *colorramp );
312
313 private slots:
314
315 void buttonClicked();
316
320 void showColorRampDialog();
321
325 void createColorRamp();
326
330 void saveColorRamp();
331
335 void invertColorRamp();
336
340 void loadColorRamp();
341
345 void prepareMenu();
346};
347
348#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