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