QGIS API Documentation 4.3.0-Master (91d4a333d5d)
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 void contextMenuEvent( QContextMenuEvent *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
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.
void contextMenuEvent(QContextMenuEvent *e) override
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.
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:91
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_FACTORY
Definition qgis_sip.h:83