QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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  const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
214  QPixmap pixmap = QgsSymbolLayerUtils::colorRampPreviewPixmap( colorramp, QSize( iconSize, iconSize ) );
215  return pixmap;
216 }
217 
218 void QgsColorRampButton::buttonClicked()
219 {
220  if ( !isRandomColorRamp() && !isNull() )
221  {
222  showColorRampDialog();
223  }
224  else
225  {
226  QToolButton::showMenu();
227  }
228 }
229 
230 void QgsColorRampButton::prepareMenu()
231 {
232  mMenu->clear();
233 
234  QAction *invertAction = new QAction( tr( "Invert Color Ramp" ), this );
235  invertAction->setEnabled( !isNull() && !isRandomColorRamp() );
236  mMenu->addAction( invertAction );
237  connect( invertAction, &QAction::triggered, this, &QgsColorRampButton::invertColorRamp );
238 
239  if ( mShowNull )
240  {
241  QAction *nullAction = new QAction( tr( "Clear Current Ramp" ), this );
242  mMenu->addAction( nullAction );
243  connect( nullAction, &QAction::triggered, this, &QgsColorRampButton::setToNull );
244  }
245 
246  mMenu->addSeparator();
247 
248  //show default color option if set
249  if ( mDefaultColorRamp )
250  {
251  QAction *defaultColorRampAction = new QAction( tr( "Default Color Ramp" ), this );
252  defaultColorRampAction->setIcon( createMenuIcon( mDefaultColorRamp ) );
253  mMenu->addAction( defaultColorRampAction );
254  connect( defaultColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setToDefaultColorRamp );
255  }
256 
257  if ( mShowRandomColorRamp )
258  {
259  QAction *randomColorRampAction = new QAction( tr( "Random Color Ramp" ), this );
260  randomColorRampAction->setCheckable( true );
261  randomColorRampAction->setChecked( isRandomColorRamp() );
262  mMenu->addAction( randomColorRampAction );
263  connect( randomColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setRandomColorRamp );
264 
265  if ( isRandomColorRamp() || dynamic_cast<QgsLimitedRandomColorRamp *>( mColorRamp ) )
266  {
267  QAction *shuffleRandomColorRampAction = new QAction( tr( "Shuffle Random Colors" ), this );
268  mMenu->addAction( shuffleRandomColorRampAction );
269  connect( shuffleRandomColorRampAction, &QAction::triggered, this, &QgsColorRampButton::colorRampChanged );
270  }
271  }
272 
273  mMenu->addSeparator();
274 
275  QStringList rampNames = mStyle->symbolsOfFavorite( QgsStyle::ColorrampEntity );
276  rampNames.sort();
277  const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
278  for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
279  {
280  std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( *it ) );
281 
282  if ( !mShowGradientOnly || ( ramp->type() == QLatin1String( "gradient" ) || ramp->type() == QLatin1String( "cpt-city" ) ) )
283  {
284  QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( iconSize, iconSize ) );
285  QAction *ra = new QAction( *it, this );
286  ra->setIcon( icon );
287  connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
288  mMenu->addAction( ra );
289  }
290  }
291 
292  mMenu->addSeparator();
293 
294  mAllRampsMenu->clear();
295  mMenu->addMenu( mAllRampsMenu );
296  rampNames = mStyle->colorRampNames();
297  rampNames.sort();
298  for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
299  {
300  std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( *it ) );
301 
302  if ( !mShowGradientOnly || ( ramp->type() == QLatin1String( "gradient" ) || ramp->type() == QLatin1String( "cpt-city" ) ) )
303  {
304  QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( iconSize, iconSize ) );
305  QAction *ra = new QAction( *it, this );
306  ra->setIcon( icon );
307  connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
308  mAllRampsMenu->addAction( ra );
309  }
310  }
311 
312  mMenu->addSeparator();
313 
314  QAction *newColorRampAction = new QAction( tr( "Create New Color Ramp…" ), this );
315  connect( newColorRampAction, &QAction::triggered, this, &QgsColorRampButton::createColorRamp );
316  mMenu->addAction( newColorRampAction );
317 
318  QAction *editColorRampAction = new QAction( tr( "Edit Color Ramp…" ), this );
319  editColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
320  connect( editColorRampAction, &QAction::triggered, this, &QgsColorRampButton::showColorRampDialog );
321  mMenu->addAction( editColorRampAction );
322 
323  QAction *saveColorRampAction = new QAction( tr( "Save Color Ramp…" ), this );
324  saveColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
325  connect( saveColorRampAction, &QAction::triggered, this, &QgsColorRampButton::saveColorRamp );
326  mMenu->addAction( saveColorRampAction );
327 }
328 
329 void QgsColorRampButton::loadColorRamp()
330 {
331  QAction *selectedItem = qobject_cast<QAction *>( sender() );
332  if ( selectedItem )
333  {
334  QString name = selectedItem->iconText();
335  setColorRampName( name );
336  setColorRampFromName( name );
337  }
338 }
339 
340 void QgsColorRampButton::createColorRamp()
341 {
342  QStringList rampTypes;
343  QString rampType;
344  bool ok = true;
345 
346  if ( mShowGradientOnly )
347  {
348  rampTypes << tr( "Gradient" ) << tr( "Catalog: cpt-city" );
349  }
350  else
351  {
352  rampTypes << tr( "Gradient" ) << tr( "Color presets" ) << tr( "Random" ) << tr( "Catalog: cpt-city" );
353  rampTypes << tr( "Catalog: ColorBrewer" );
354  }
355  rampType = QInputDialog::getItem( this, tr( "Color ramp type" ),
356  tr( "Please select color ramp type:" ), rampTypes, 0, false, &ok );
357 
358  if ( !ok || rampType.isEmpty() )
359  return;
360 
361  QgsColorRamp *ramp = nullptr;
362  if ( rampType == tr( "Gradient" ) )
363  {
364  ramp = new QgsGradientColorRamp();
365  }
366  else if ( rampType == tr( "Random" ) )
367  {
368  ramp = new QgsLimitedRandomColorRamp();
369  }
370  else if ( rampType == tr( "Catalog: ColorBrewer" ) )
371  {
372  ramp = new QgsColorBrewerColorRamp();
373  }
374  else if ( rampType == tr( "Color presets" ) )
375  {
376  ramp = new QgsPresetSchemeColorRamp();
377  }
378  else if ( rampType == tr( "Catalog: cpt-city" ) )
379  {
380  ramp = new QgsCptCityColorRamp( QString(), QString() );
381  }
382  else
383  {
384  QgsDebugMsg( "invalid ramp type " + rampType );
385  return;
386  }
387 
388  setColorRamp( ramp );
389  delete ramp;
390 
391  showColorRampDialog();
392 }
393 
394 void QgsColorRampButton::saveColorRamp()
395 {
396  QgsStyleSaveDialog saveDlg( this, QgsStyle::ColorrampEntity );
397  if ( !saveDlg.exec() || saveDlg.name().isEmpty() )
398  {
399  return;
400  }
401 
402  // check if there is no symbol with same name
403  if ( mStyle->symbolNames().contains( saveDlg.name() ) )
404  {
405  int res = QMessageBox::warning( this, tr( "Save Color Ramp" ),
406  tr( "Color ramp with name '%1' already exists. Overwrite?" )
407  .arg( saveDlg.name() ),
408  QMessageBox::Yes | QMessageBox::No );
409  if ( res != QMessageBox::Yes )
410  {
411  return;
412  }
413  mStyle->removeColorRamp( saveDlg.name() );
414  }
415 
416  QStringList colorRampTags = saveDlg.tags().split( ',' );
417 
418  // add new symbol to style and re-populate the list
419  QgsColorRamp *ramp = colorRamp();
420  mStyle->addColorRamp( saveDlg.name(), ramp );
421  mStyle->saveColorRamp( saveDlg.name(), ramp, saveDlg.isFavorite(), colorRampTags );
422 
423  setColorRampName( saveDlg.name() );
424 }
425 
426 void QgsColorRampButton::invertColorRamp()
427 {
428  mColorRamp->invert();
430  emit colorRampChanged();
431 }
432 
434 {
435  if ( e->type() == QEvent::EnabledChange )
436  {
438  }
439  QToolButton::changeEvent( e );
440 }
441 
442 #if 0 // causes too many cyclical updates, but may be needed on some platforms
443 void QgsColorRampButton::paintEvent( QPaintEvent *e )
444 {
445  QToolButton::paintEvent( e );
446 
447  if ( !mBackgroundSet )
448  {
450  }
451 }
452 #endif
453 
454 void QgsColorRampButton::showEvent( QShowEvent *e )
455 {
457  QToolButton::showEvent( e );
458 }
459 
461 {
462  QToolButton::resizeEvent( event );
463  //recalculate icon size and redraw icon
464  mIconSize = QSize();
465  setButtonBackground( mColorRamp );
466 }
467 
469 {
470  QgsColorRamp *oldColorRamp = mColorRamp;
471  mColorRamp = colorramp->clone();
472 
473  // handle when initially set color is same as default (Qt::black); consider it a color change
474  if ( ( oldColorRamp != mColorRamp ) || !mColorRampSet )
475  {
477  if ( isEnabled() )
478  {
479  emit colorRampChanged();
480  }
481  }
482  delete oldColorRamp;
483  mColorRampSet = true;
484 }
485 
486 void QgsColorRampButton::setColorRampFromName( const QString &name )
487 {
488  if ( !name.isEmpty() )
489  {
490  std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
491  if ( ramp )
492  {
493  setColorRamp( ramp.get() );
494  }
495  }
496 }
497 
499 {
500  if ( !isRandomColorRamp() )
501  {
502  std::unique_ptr< QgsRandomColorRamp > newRamp( new QgsRandomColorRamp() );
503  setColorRamp( newRamp.get() );
504  }
505 }
506 
508 {
509  QgsColorRamp *backgroundColorRamp = colorramp;
510  if ( !colorramp )
511  {
512  backgroundColorRamp = mColorRamp;
513  }
514 
515  QSize currentIconSize;
516  //icon size is button size with a small margin
517  if ( menu() )
518  {
519  if ( !mIconSize.isValid() )
520  {
521  //calculate size of push button part of widget (ie, without the menu drop-down button part)
522  QStyleOptionToolButton opt;
523  initStyleOption( &opt );
524  QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
525  this );
526  //make sure height of icon looks good under different platforms
527 #ifdef Q_OS_WIN
528  mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
529 #else
530  mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
531 #endif
532  }
533  currentIconSize = mIconSize;
534  }
535  else
536  {
537  //no menu
538 #ifdef Q_OS_WIN
539  currentIconSize = QSize( width() - 10, height() - 6 );
540 #else
541  currentIconSize = QSize( width() - 10, height() - 12 );
542 #endif
543  }
544 
545  if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
546  {
547  return;
548  }
549 
550  QPixmap pm;
551  if ( isRandomColorRamp() )
552  {
553  //create a "random colors" label
554  pm = QPixmap( currentIconSize );
555  pm.fill( Qt::transparent );
556 
557  QPainter painter;
558  QPen pen = ( palette().buttonText().color() );
559 
560  painter.begin( &pm );
561  painter.setPen( pen );
562  painter.drawText( QRect( 0, 0, currentIconSize.width(), currentIconSize.height() ), Qt::AlignCenter, QStringLiteral( "Random colors" ) );
563  painter.end();
564  }
565  else
566  {
567  //create an icon pixmap
568  if ( backgroundColorRamp )
569  {
570  pm = QgsSymbolLayerUtils::colorRampPreviewPixmap( backgroundColorRamp, currentIconSize );
571  }
572  }
573 
574  setIconSize( currentIconSize );
575  setIcon( pm );
576 }
577 
579 {
580  return mColorRamp ? mColorRamp->clone() : nullptr;
581 }
582 
584 {
585  mColorRampDialogTitle = title;
586 }
587 
589 {
590  return mColorRampDialogTitle;
591 }
592 
594 {
595  setMenu( showMenu ? mMenu : nullptr );
596  setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
597  //force recalculation of icon size
598  mIconSize = QSize();
599  setButtonBackground( mColorRamp );
600 }
601 
603 {
604  delete mDefaultColorRamp;
605  mDefaultColorRamp = colorramp->clone();
606 }
607 
609 {
610  return dynamic_cast<QgsRandomColorRamp *>( mColorRamp );
611 }
612 
614 {
615  mShowNull = showNull;
616 }
617 
619 {
620  return mShowNull;
621 }
622 
624 {
625  return !mColorRamp;
626 }
627 
628 void QgsColorRampButton::rampWidgetUpdated()
629 {
630  QgsLimitedRandomColorRampWidget *limitedRampWidget = qobject_cast< QgsLimitedRandomColorRampWidget * >( sender() );
631  if ( limitedRampWidget )
632  {
633  setColorRamp( limitedRampWidget->ramp().clone() );
634  emit colorRampChanged();
635  return;
636  }
637  QgsColorBrewerColorRampWidget *colorBrewerRampWidget = qobject_cast< QgsColorBrewerColorRampWidget * >( sender() );
638  if ( colorBrewerRampWidget )
639  {
640  setColorRamp( colorBrewerRampWidget->ramp().clone() );
641  emit colorRampChanged();
642  return;
643  }
644  QgsPresetColorRampWidget *presetRampWidget = qobject_cast< QgsPresetColorRampWidget * >( sender() );
645  if ( presetRampWidget )
646  {
647  setColorRamp( presetRampWidget->ramp().clone() );
648  emit colorRampChanged();
649  return;
650  }
651 }
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.
bool addColorRamp(const QString &name, QgsColorRamp *colorRamp, bool update=false)
Adds a color ramp to the style.
Definition: qgsstyle.cpp:236
bool dockMode()
Returns the dock mode state.
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:154
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.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly...
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.
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:302
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:356
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:335
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:74
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
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
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window&#39;s toolbar icons.
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.
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.
QStringList colorRampNames() const
Returns a list of names of color ramps.
Definition: qgsstyle.cpp:372
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
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:887
bool event(QEvent *e) override
bool saveAsGradientRamp() const
Returns true if the ramp should be converted to a QgsGradientColorRamp.
QStringList symbolNames() const
Returns a list of names of symbols.
Definition: qgsstyle.cpp:230