QGIS API Documentation  3.2.0-Bonn (bc43194)
qgscolorrampbutton.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscolorrampbutton.cpp - 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 
16 #include "qgscolorrampbutton.h"
17 #include "qgscolorramp.h"
18 #include "qgsapplication.h"
19 #include "qgslogger.h"
20 #include "qgssymbollayerutils.h"
21 #include "qgsstyle.h"
22 
23 #include "qgsstylesavedialog.h"
29 
30 #include <QAction>
31 #include <QInputDialog>
32 #include <QMessageBox>
33 #include <QMouseEvent>
34 #include <QMenu>
35 #include <QPainter>
36 #include <QPushButton>
37 #include <QWidget>
38 
39 QgsColorRampButton::QgsColorRampButton( QWidget *parent, const QString &dialogTitle )
40  : QToolButton( parent )
41  , mColorRampDialogTitle( dialogTitle.isEmpty() ? tr( "Select Color Ramp" ) : dialogTitle )
42 {
43  setAcceptDrops( true );
44  setMinimumSize( QSize( 24, 16 ) );
45  connect( this, &QPushButton::clicked, this, &QgsColorRampButton::buttonClicked );
46 
47  //setup drop-down menu
48  mMenu = new QMenu( this );
49  connect( mMenu, &QMenu::aboutToShow, this, &QgsColorRampButton::prepareMenu );
50  setMenu( mMenu );
51 
52  mAllRampsMenu = new QMenu( mMenu );
53  mAllRampsMenu->setTitle( tr( "All color ramps" ) );
54 
55  setPopupMode( QToolButton::MenuButtonPopup );
56 
57  mStyle = QgsStyle::defaultStyle();
58 }
59 
61 {
62  delete mColorRamp;
63  delete mDefaultColorRamp;
64 }
65 
67 {
68  //make sure height of button looks good under different platforms
69 #ifdef Q_OS_WIN
70  return QSize( 120, static_cast<int>( std::max( Qgis::UI_SCALE_FACTOR * fontMetrics().height( ), 22.0 ) ) );
71 #else
72  // Adjust height for HiDPI screens
73  return QSize( 120, static_cast<int>( std::max( Qgis::UI_SCALE_FACTOR * fontMetrics().height( ) * 1.4, 28.0 ) ) );
74 #endif
75 }
76 
77 void QgsColorRampButton::showColorRampDialog()
78 {
80  bool panelMode = panel && panel->dockMode();
81 
82  std::unique_ptr< QgsColorRamp > currentRamp( colorRamp() );
83  if ( !currentRamp )
84  return;
85 
86  setColorRampName( QString() );
87 
88  if ( currentRamp->type() == QLatin1String( "gradient" ) )
89  {
90  QgsGradientColorRamp *gradRamp = static_cast<QgsGradientColorRamp *>( currentRamp.get() );
91  QgsGradientColorRampDialog dlg( *gradRamp, this );
92  dlg.setWindowTitle( mColorRampDialogTitle );
93  if ( dlg.exec() )
94  {
95  setColorRamp( dlg.ramp().clone() );
96  }
97  }
98  else if ( currentRamp->type() == QLatin1String( "random" ) )
99  {
100  QgsLimitedRandomColorRamp *randRamp = static_cast<QgsLimitedRandomColorRamp *>( currentRamp.get() );
101  if ( panelMode )
102  {
103  QgsLimitedRandomColorRampWidget *widget = new QgsLimitedRandomColorRampWidget( *randRamp, this );
104  widget->setPanelTitle( tr( "Edit Ramp" ) );
105  connect( widget, &QgsLimitedRandomColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated );
106  panel->openPanel( widget );
107  }
108  else
109  {
110  QgsLimitedRandomColorRampDialog dlg( *randRamp, this );
111  if ( dlg.exec() )
112  {
113  setColorRamp( dlg.ramp().clone() );
114  }
115  }
116  }
117  else if ( currentRamp->type() == QLatin1String( "preset" ) )
118  {
119  QgsPresetSchemeColorRamp *presetRamp = static_cast<QgsPresetSchemeColorRamp *>( currentRamp.get() );
120  if ( panelMode )
121  {
122  QgsPresetColorRampWidget *widget = new QgsPresetColorRampWidget( *presetRamp, this );
123  widget->setPanelTitle( tr( "Edit Ramp" ) );
124  connect( widget, &QgsPresetColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated );
125  panel->openPanel( widget );
126  }
127  else
128  {
129  QgsPresetColorRampDialog dlg( *presetRamp, this );
130  if ( dlg.exec() )
131  {
132  setColorRamp( dlg.ramp().clone() );
133  }
134  }
135  }
136  else if ( currentRamp->type() == QLatin1String( "colorbrewer" ) )
137  {
138  QgsColorBrewerColorRamp *brewerRamp = static_cast<QgsColorBrewerColorRamp *>( currentRamp.get() );
139  if ( panelMode )
140  {
141  QgsColorBrewerColorRampWidget *widget = new QgsColorBrewerColorRampWidget( *brewerRamp, this );
142  widget->setPanelTitle( tr( "Edit Ramp" ) );
143  connect( widget, &QgsColorBrewerColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated );
144  panel->openPanel( widget );
145  }
146  else
147  {
148  QgsColorBrewerColorRampDialog dlg( *brewerRamp, this );
149  if ( dlg.exec() )
150  {
151  setColorRamp( dlg.ramp().clone() );
152  }
153  }
154  }
155  else if ( currentRamp->type() == QLatin1String( "cpt-city" ) )
156  {
157  QgsCptCityColorRamp *cptCityRamp = static_cast<QgsCptCityColorRamp *>( currentRamp.get() );
158  QgsCptCityColorRampDialog dlg( *cptCityRamp, this );
159  if ( dlg.exec() )
160  {
161  if ( dlg.saveAsGradientRamp() )
162  {
164  }
165  else
166  {
167  setColorRamp( dlg.ramp().clone() );
168  }
169  }
170  }
171 }
172 
174 {
175  if ( !mDefaultColorRamp )
176  {
177  return;
178  }
179 
180  setColorRamp( mDefaultColorRamp );
181 }
182 
184 {
185  setColorRamp( nullptr );
186 }
187 
188 bool QgsColorRampButton::event( QEvent *e )
189 {
190  if ( e->type() == QEvent::ToolTip )
191  {
192  if ( !colorRampName().isEmpty() )
193  {
194  setToolTip( colorRampName() );
195  }
196  }
197  return QToolButton::event( e );
198 }
199 
201 {
202  if ( e->button() == Qt::RightButton )
203  {
204  QToolButton::showMenu();
205  return;
206  }
207  QToolButton::mousePressEvent( e );
208 }
209 
210 QPixmap QgsColorRampButton::createMenuIcon( QgsColorRamp *colorramp )
211 {
212  //create an icon pixmap
213  QPixmap pixmap = QgsSymbolLayerUtils::colorRampPreviewPixmap( colorramp, QSize( 16, 16 ) );
214  return pixmap;
215 }
216 
217 void QgsColorRampButton::buttonClicked()
218 {
219  if ( !isRandomColorRamp() && !isNull() )
220  {
221  showColorRampDialog();
222  }
223  else
224  {
225  QToolButton::showMenu();
226  }
227 }
228 
229 void QgsColorRampButton::prepareMenu()
230 {
231  mMenu->clear();
232 
233  QAction *invertAction = new QAction( tr( "Invert Color Ramp" ), this );
234  invertAction->setEnabled( !isNull() && !isRandomColorRamp() );
235  mMenu->addAction( invertAction );
236  connect( invertAction, &QAction::triggered, this, &QgsColorRampButton::invertColorRamp );
237 
238  if ( mShowNull )
239  {
240  QAction *nullAction = new QAction( tr( "Clear Current Ramp" ), this );
241  mMenu->addAction( nullAction );
242  connect( nullAction, &QAction::triggered, this, &QgsColorRampButton::setToNull );
243  }
244 
245  mMenu->addSeparator();
246 
247  //show default color option if set
248  if ( mDefaultColorRamp )
249  {
250  QAction *defaultColorRampAction = new QAction( tr( "Default Color Ramp" ), this );
251  defaultColorRampAction->setIcon( createMenuIcon( mDefaultColorRamp ) );
252  mMenu->addAction( defaultColorRampAction );
253  connect( defaultColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setToDefaultColorRamp );
254  }
255 
256  if ( mShowRandomColorRamp )
257  {
258  QAction *randomColorRampAction = new QAction( tr( "Random Color Ramp" ), this );
259  randomColorRampAction->setCheckable( true );
260  randomColorRampAction->setChecked( isRandomColorRamp() );
261  mMenu->addAction( randomColorRampAction );
262  connect( randomColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setRandomColorRamp );
263 
264  if ( isRandomColorRamp() || dynamic_cast<QgsLimitedRandomColorRamp *>( mColorRamp ) )
265  {
266  QAction *shuffleRandomColorRampAction = new QAction( tr( "Shuffle Random Colors" ), this );
267  mMenu->addAction( shuffleRandomColorRampAction );
268  connect( shuffleRandomColorRampAction, &QAction::triggered, this, &QgsColorRampButton::colorRampChanged );
269  }
270  }
271 
272  mMenu->addSeparator();
273 
274  QStringList rampNames = mStyle->symbolsOfFavorite( QgsStyle::ColorrampEntity );
275  rampNames.sort();
276  for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
277  {
278  std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( *it ) );
279 
280  if ( !mShowGradientOnly || ( ramp->type() == QLatin1String( "gradient" ) || ramp->type() == QLatin1String( "cpt-city" ) ) )
281  {
282  QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( 16, 16 ) );
283  QAction *ra = new QAction( *it, this );
284  ra->setIcon( icon );
285  connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
286  mMenu->addAction( ra );
287  }
288  }
289 
290  mMenu->addSeparator();
291 
292  mAllRampsMenu->clear();
293  mMenu->addMenu( mAllRampsMenu );
294  rampNames = mStyle->colorRampNames();
295  rampNames.sort();
296  for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
297  {
298  std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( *it ) );
299 
300  if ( !mShowGradientOnly || ( ramp->type() == QLatin1String( "gradient" ) || ramp->type() == QLatin1String( "cpt-city" ) ) )
301  {
302  QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( 16, 16 ) );
303  QAction *ra = new QAction( *it, this );
304  ra->setIcon( icon );
305  connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
306  mAllRampsMenu->addAction( ra );
307  }
308  }
309 
310  mMenu->addSeparator();
311 
312  QAction *newColorRampAction = new QAction( tr( "Create New Color Ramp…" ), this );
313  connect( newColorRampAction, &QAction::triggered, this, &QgsColorRampButton::createColorRamp );
314  mMenu->addAction( newColorRampAction );
315 
316  QAction *editColorRampAction = new QAction( tr( "Edit Color Ramp…" ), this );
317  editColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
318  connect( editColorRampAction, &QAction::triggered, this, &QgsColorRampButton::showColorRampDialog );
319  mMenu->addAction( editColorRampAction );
320 
321  QAction *saveColorRampAction = new QAction( tr( "Save Color Ramp…" ), this );
322  saveColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
323  connect( saveColorRampAction, &QAction::triggered, this, &QgsColorRampButton::saveColorRamp );
324  mMenu->addAction( saveColorRampAction );
325 }
326 
327 void QgsColorRampButton::loadColorRamp()
328 {
329  QAction *selectedItem = qobject_cast<QAction *>( sender() );
330  if ( selectedItem )
331  {
332  QString name = selectedItem->iconText();
333  setColorRampName( name );
334  setColorRampFromName( name );
335  }
336 }
337 
338 void QgsColorRampButton::createColorRamp()
339 {
340  QStringList rampTypes;
341  QString rampType;
342  bool ok = true;
343 
344  if ( mShowGradientOnly )
345  {
346  rampTypes << tr( "Gradient" ) << tr( "Catalog: cpt-city" );
347  }
348  else
349  {
350  rampTypes << tr( "Gradient" ) << tr( "Color presets" ) << tr( "Random" ) << tr( "Catalog: cpt-city" );
351  rampTypes << tr( "Catalog: ColorBrewer" );
352  }
353  rampType = QInputDialog::getItem( this, tr( "Color ramp type" ),
354  tr( "Please select color ramp type:" ), rampTypes, 0, false, &ok );
355 
356  if ( !ok || rampType.isEmpty() )
357  return;
358 
359  QgsColorRamp *ramp = nullptr;
360  if ( rampType == tr( "Gradient" ) )
361  {
362  ramp = new QgsGradientColorRamp();
363  }
364  else if ( rampType == tr( "Random" ) )
365  {
366  ramp = new QgsLimitedRandomColorRamp();
367  }
368  else if ( rampType == tr( "Catalog: ColorBrewer" ) )
369  {
370  ramp = new QgsColorBrewerColorRamp();
371  }
372  else if ( rampType == tr( "Color presets" ) )
373  {
374  ramp = new QgsPresetSchemeColorRamp();
375  }
376  else if ( rampType == tr( "Catalog: cpt-city" ) )
377  {
378  ramp = new QgsCptCityColorRamp( QLatin1String( "" ), QLatin1String( "" ) );
379  }
380  else
381  {
382  QgsDebugMsg( "invalid ramp type " + rampType );
383  return;
384  }
385 
386  setColorRamp( ramp );
387  delete ramp;
388 
389  showColorRampDialog();
390 }
391 
392 void QgsColorRampButton::saveColorRamp()
393 {
395  if ( !saveDlg.exec() || saveDlg.name().isEmpty() )
396  {
397  return;
398  }
399 
400  // check if there is no symbol with same name
401  if ( mStyle->symbolNames().contains( saveDlg.name() ) )
402  {
403  int res = QMessageBox::warning( this, tr( "Save Color Ramp" ),
404  tr( "Color ramp with name '%1' already exists. Overwrite?" )
405  .arg( saveDlg.name() ),
406  QMessageBox::Yes | QMessageBox::No );
407  if ( res != QMessageBox::Yes )
408  {
409  return;
410  }
411  mStyle->removeColorRamp( saveDlg.name() );
412  }
413 
414  QStringList colorRampTags = saveDlg.tags().split( ',' );
415 
416  // add new symbol to style and re-populate the list
417  QgsColorRamp *ramp = colorRamp();
418  mStyle->addColorRamp( saveDlg.name(), ramp );
419  mStyle->saveColorRamp( saveDlg.name(), ramp, saveDlg.isFavorite(), colorRampTags );
420 
421  setColorRampName( saveDlg.name() );
422 }
423 
424 void QgsColorRampButton::invertColorRamp()
425 {
426  mColorRamp->invert();
428  emit colorRampChanged();
429 }
430 
432 {
433  if ( e->type() == QEvent::EnabledChange )
434  {
436  }
437  QToolButton::changeEvent( e );
438 }
439 
440 #if 0 // causes too many cyclical updates, but may be needed on some platforms
441 void QgsColorRampButton::paintEvent( QPaintEvent *e )
442 {
443  QToolButton::paintEvent( e );
444 
445  if ( !mBackgroundSet )
446  {
448  }
449 }
450 #endif
451 
452 void QgsColorRampButton::showEvent( QShowEvent *e )
453 {
455  QToolButton::showEvent( e );
456 }
457 
459 {
460  QToolButton::resizeEvent( event );
461  //recalculate icon size and redraw icon
462  mIconSize = QSize();
463  setButtonBackground( mColorRamp );
464 }
465 
467 {
468  QgsColorRamp *oldColorRamp = mColorRamp;
469  mColorRamp = colorramp->clone();
470 
471  // handle when initially set color is same as default (Qt::black); consider it a color change
472  if ( ( oldColorRamp != mColorRamp ) || !mColorRampSet )
473  {
475  if ( isEnabled() )
476  {
477  emit colorRampChanged();
478  }
479  }
480  delete oldColorRamp;
481  mColorRampSet = true;
482 }
483 
484 void QgsColorRampButton::setColorRampFromName( const QString &name )
485 {
486  if ( !name.isEmpty() )
487  {
488  std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
489  if ( ramp )
490  {
491  setColorRamp( ramp.get() );
492  }
493  }
494 }
495 
497 {
498  if ( !isRandomColorRamp() )
499  {
500  std::unique_ptr< QgsRandomColorRamp > newRamp( new QgsRandomColorRamp() );
501  setColorRamp( newRamp.get() );
502  }
503 }
504 
506 {
507  QgsColorRamp *backgroundColorRamp = colorramp;
508  if ( !colorramp )
509  {
510  backgroundColorRamp = mColorRamp;
511  }
512 
513  QSize currentIconSize;
514  //icon size is button size with a small margin
515  if ( menu() )
516  {
517  if ( !mIconSize.isValid() )
518  {
519  //calculate size of push button part of widget (ie, without the menu drop-down button part)
520  QStyleOptionToolButton opt;
521  initStyleOption( &opt );
522  QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
523  this );
524  //make sure height of icon looks good under different platforms
525 #ifdef Q_OS_WIN
526  mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
527 #else
528  mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
529 #endif
530  }
531  currentIconSize = mIconSize;
532  }
533  else
534  {
535  //no menu
536 #ifdef Q_OS_WIN
537  currentIconSize = QSize( width() - 10, height() - 6 );
538 #else
539  currentIconSize = QSize( width() - 10, height() - 12 );
540 #endif
541  }
542 
543  if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
544  {
545  return;
546  }
547 
548  QPixmap pm;
549  if ( isRandomColorRamp() )
550  {
551  //create a "random colors" label
552  pm = QPixmap( currentIconSize );
553  pm.fill( Qt::transparent );
554 
555  QPainter painter;
556  QPen pen = ( QApplication::palette().buttonText().color() );
557 
558  painter.begin( &pm );
559  painter.setPen( pen );
560  painter.drawText( QRect( 0, 0, currentIconSize.width(), currentIconSize.height() ), Qt::AlignCenter, QStringLiteral( "Random colors" ) );
561  painter.end();
562  }
563  else
564  {
565  //create an icon pixmap
566  if ( backgroundColorRamp )
567  {
568  pm = QgsSymbolLayerUtils::colorRampPreviewPixmap( backgroundColorRamp, currentIconSize );
569  }
570  }
571 
572  setIconSize( currentIconSize );
573  setIcon( pm );
574 }
575 
577 {
578  return mColorRamp ? mColorRamp->clone() : nullptr;
579 }
580 
582 {
583  mColorRampDialogTitle = title;
584 }
585 
587 {
588  return mColorRampDialogTitle;
589 }
590 
592 {
593  setMenu( showMenu ? mMenu : nullptr );
594  setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
595  //force recalculation of icon size
596  mIconSize = QSize();
597  setButtonBackground( mColorRamp );
598 }
599 
601 {
602  delete mDefaultColorRamp;
603  mDefaultColorRamp = colorramp->clone();
604 }
605 
607 {
608  return dynamic_cast<QgsRandomColorRamp *>( mColorRamp );
609 }
610 
612 {
613  mShowNull = showNull;
614 }
615 
617 {
618  return mShowNull;
619 }
620 
622 {
623  return !mColorRamp;
624 }
625 
626 void QgsColorRampButton::rampWidgetUpdated()
627 {
628  QgsLimitedRandomColorRampWidget *limitedRampWidget = qobject_cast< QgsLimitedRandomColorRampWidget * >( sender() );
629  if ( limitedRampWidget )
630  {
631  setColorRamp( limitedRampWidget->ramp().clone() );
632  emit colorRampChanged();
633  return;
634  }
635  QgsColorBrewerColorRampWidget *colorBrewerRampWidget = qobject_cast< QgsColorBrewerColorRampWidget * >( sender() );
636  if ( colorBrewerRampWidget )
637  {
638  setColorRamp( colorBrewerRampWidget->ramp().clone() );
639  emit colorRampChanged();
640  return;
641  }
642  QgsPresetColorRampWidget *presetRampWidget = qobject_cast< QgsPresetColorRampWidget * >( sender() );
643  if ( presetRampWidget )
644  {
645  setColorRamp( presetRampWidget->ramp().clone() );
646  emit colorRampChanged();
647  return;
648  }
649 }
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
QSize sizeHint() const override
QString colorRampDialogTitle() const
Returns the title for the color ramp dialog window.
QString tags() const
returns the text value of the tags element
bool addColorRamp(const QString &name, QgsColorRamp *colorRamp, bool update=false)
Adds a color ramp to the style.
Definition: qgsstyle.cpp:191
bool dockMode()
Returns the dock mode state.
a dialog for setting properties of a newly saved style.
void setButtonBackground(QgsColorRamp *colorramp=nullptr)
Sets the background pixmap for the button based upon current color ramp.
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition: qgis.h:151
A widget which allows users to modify the properties of a QgsLimitedRandomColorRamp.
QgsColorBrewerColorRamp * clone() const override
Creates a clone of the color ramp.
QString colorRampName() const
Returns the name of the current color ramp when it&#39;s available in the style manager.
void colorRampChanged()
Emitted whenever a new color ramp is set for the button.
void changed()
Emitted when the dialog settings change.
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
A widget which allows users to modify the properties of a QgsPresetSchemeColorRamp.
void setDefaultColorRamp(QgsColorRamp *colorramp)
Sets the default color ramp for the button, which is shown in the button&#39;s drop-down menu for the "de...
void changed()
Emitted when the dialog settings change.
QString name() const
returns the text value of the name element
Abstract base class for color ramps.
Definition: qgscolorramp.h:31
bool saveColorRamp(const QString &name, QgsColorRamp *ramp, bool favorite, const QStringList &tags)
Adds the colorramp to the DB.
Definition: qgsstyle.cpp:215
QgsPresetSchemeColorRamp ramp
void setShowNull(bool showNull)
Sets whether a set to null (clear) option is shown in the button&#39;s drop-down menu.
Base class for any widget that can be shown as a inline panel.
void setShowMenu(bool showMenu)
Sets whether the drop-down menu should be shown for the button.
void resizeEvent(QResizeEvent *event) override
A dialog which allows users to modify the properties of a QgsColorBrewerColorRamp.
QgsColorRamp * colorRamp(const QString &name) const
Returns a new copy of the specified color ramp.
Definition: qgsstyle.cpp:262
virtual void invert()
Inverts the ordering of the color ramp.
Definition: qgscolorramp.h:82
bool removeColorRamp(const QString &name)
Removes color ramp from style (and delete it)
Definition: qgsstyle.cpp:244
A dialog which allows users to modify the properties of a QgsGradientColorRamp.
A dialog which allows users to modify the properties of a QgsPresetSchemeColorRamp.
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:46
A dialog which allows users to modify the properties of a QgsLimitedRandomColorRamp.
QgsGradientColorRamp * clone() const override
Creates a clone of the color ramp.
Constrained random color ramp, which returns random colors based on preset parameters.
Definition: qgscolorramp.h:283
QStringList symbolNames()
Returns a list of names of symbols.
Definition: qgsstyle.cpp:185
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget...
void setColorRamp(QgsColorRamp *colorramp)
Sets the current color ramp for the button.
void changed()
Emitted when the dialog settings change.
void mousePressEvent(QMouseEvent *e) override
Reimplemented to detect right mouse button clicks on the color ramp button.
void setRandomColorRamp()
Sets the current color ramp for the button to random colors.
bool showMenu() const
Returns whether the drop-down menu is shown for the button.
QgsPresetSchemeColorRamp * clone() const override
Creates a clone of the color ramp.
static QIcon colorRampPreviewIcon(QgsColorRamp *ramp, QSize size, int padding=0)
Returns an icon preview for a color ramp.
void showEvent(QShowEvent *e) override
A scheme based color ramp consisting of a list of predefined colors.
Definition: qgscolorramp.h:471
void setToNull()
Sets color ramp to null.
QgsColorRampButton(QWidget *parent=nullptr, const QString &dialogTitle=QString())
Construct a new color ramp button.
Totally random color ramp.
Definition: qgscolorramp.h:427
QgsGradientColorRamp * cloneGradientRamp() const
bool isRandomColorRamp() const
Returns true if the current color is null.
static QPixmap colorRampPreviewPixmap(QgsColorRamp *ramp, QSize size, int padding=0)
Returns a pixmap preview for a color ramp.
QStringList colorRampNames()
Returns a list of names of color ramps.
Definition: qgsstyle.cpp:278
QgsLimitedRandomColorRamp * clone() const override
Creates a clone of the color ramp.
A widget which allows users to modify the properties of a QgsColorBrewerColorRamp.
QgsColorRamp * colorRamp() const
Returns a copy of the current color ramp.
void setColorRampName(const QString &name)
Sets the name of the current color ramp when it&#39;s available in the style manager. ...
void changeEvent(QEvent *e) override
QgsCptCityColorRamp * clone() const override
Creates a clone of the color ramp.
bool showNull() const
Returns whether the set to null (clear) option is shown in the button&#39;s drop-down menu...
QgsPresetSchemeColorRamp ramp
void setColorRampFromName(const QString &name=QString())
Sets the current color ramp for the button using a saved color ramp name.
void setColorRampDialogTitle(const QString &title)
Set the title for the color ramp dialog window.
Color ramp utilising "Color Brewer" preset color schemes.
Definition: qgscolorramp.h:535
bool isFavorite() const
returns whether the favorite element is checked
void setToDefaultColorRamp()
Sets color ramp to the button&#39;s default color ramp, if set.
A dialog which allows users to modify the properties of a QgsCptCityColorRamp.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
Definition: qgscolorramp.h:139
bool isNull() const
Returns true if the current color is null.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
Definition: qgsstyle.cpp:525
bool event(QEvent *e) override
bool saveAsGradientRamp() const
Returns true if the ramp should be converted to a QgsGradientColorRamp.