QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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  const 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() == QgsGradientColorRamp::typeString() )
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() == QgsLimitedRandomColorRamp::typeString() )
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() == QgsPresetSchemeColorRamp::typeString() )
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() == QgsColorBrewerColorRamp::typeString() )
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() == QgsCptCityColorRamp::typeString() )
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  const 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  nullAction->setEnabled( !isNull() );
238  mMenu->addAction( nullAction );
239  connect( nullAction, &QAction::triggered, this, &QgsColorRampButton::setToNull );
240  }
241 
242  mMenu->addSeparator();
243 
244  //show default color option if set
245  if ( mDefaultColorRamp )
246  {
247  QAction *defaultColorRampAction = new QAction( tr( "Default Color Ramp" ), this );
248  defaultColorRampAction->setIcon( createMenuIcon( mDefaultColorRamp.get() ) );
249  mMenu->addAction( defaultColorRampAction );
250  connect( defaultColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setToDefaultColorRamp );
251  }
252 
253  if ( mShowRandomColorRamp )
254  {
255  QAction *randomColorRampAction = new QAction( tr( "Random Color Ramp" ), this );
256  randomColorRampAction->setCheckable( true );
257  randomColorRampAction->setChecked( isRandomColorRamp() );
258  mMenu->addAction( randomColorRampAction );
259  connect( randomColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setRandomColorRamp );
260 
261  if ( isRandomColorRamp() || dynamic_cast<QgsLimitedRandomColorRamp *>( mColorRamp.get() ) )
262  {
263  QAction *shuffleRandomColorRampAction = new QAction( tr( "Shuffle Random Colors" ), this );
264  mMenu->addAction( shuffleRandomColorRampAction );
265  connect( shuffleRandomColorRampAction, &QAction::triggered, this, &QgsColorRampButton::colorRampChanged );
266  }
267  }
268 
269  mMenu->addSeparator();
270 
271  QStringList rampNames = mStyle->symbolsOfFavorite( QgsStyle::ColorrampEntity );
272  rampNames.sort();
273  const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
274  for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
275  {
276  std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( *it ) );
277 
278  if ( !mShowGradientOnly || ( ramp->type() == QgsGradientColorRamp::typeString() || ramp->type() == QgsCptCityColorRamp::typeString() ) )
279  {
280  const QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( iconSize, iconSize ) );
281  QAction *ra = new QAction( *it, this );
282  ra->setIcon( icon );
283  connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
284  mMenu->addAction( ra );
285  }
286  }
287 
288  mMenu->addSeparator();
289 
290  mAllRampsMenu->clear();
291  mMenu->addMenu( mAllRampsMenu );
292  rampNames = mStyle->colorRampNames();
293  rampNames.sort();
294  for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
295  {
296  std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( *it ) );
297 
298  if ( !mShowGradientOnly || ( ramp->type() == QgsGradientColorRamp::typeString() || ramp->type() == QgsCptCityColorRamp::typeString() ) )
299  {
300  const QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( iconSize, iconSize ) );
301  QAction *ra = new QAction( *it, this );
302  ra->setIcon( icon );
303  connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
304  mAllRampsMenu->addAction( ra );
305  }
306  }
307 
308  mMenu->addSeparator();
309 
310  QAction *newColorRampAction = new QAction( tr( "Create New Color Ramp…" ), this );
311  connect( newColorRampAction, &QAction::triggered, this, &QgsColorRampButton::createColorRamp );
312  mMenu->addAction( newColorRampAction );
313 
314  QAction *editColorRampAction = new QAction( tr( "Edit Color Ramp…" ), this );
315  editColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
316  connect( editColorRampAction, &QAction::triggered, this, &QgsColorRampButton::showColorRampDialog );
317  mMenu->addAction( editColorRampAction );
318 
319  QAction *saveColorRampAction = new QAction( tr( "Save Color Ramp…" ), this );
320  saveColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
321  connect( saveColorRampAction, &QAction::triggered, this, &QgsColorRampButton::saveColorRamp );
322  mMenu->addAction( saveColorRampAction );
323 }
324 
325 void QgsColorRampButton::loadColorRamp()
326 {
327  QAction *selectedItem = qobject_cast<QAction *>( sender() );
328  if ( selectedItem )
329  {
330  const QString name = selectedItem->iconText();
331  setColorRampName( name );
332  setColorRampFromName( name );
333  }
334 }
335 
336 void QgsColorRampButton::createColorRamp()
337 {
338 
339  bool ok = true;
340 
341  QList< QPair< QString, QString > > rampTypes = QgsColorRamp::rampTypes();
342  QStringList rampTypeNames;
343  rampTypeNames.reserve( rampTypes.size() );
344  if ( mShowGradientOnly )
345  {
346  rampTypes.erase( std::remove_if( rampTypes.begin(), rampTypes.end(), []( const QPair< QString, QString > &type )
347  {
348  return type.first != QgsGradientColorRamp::typeString() && type.first != QgsCptCityColorRamp::typeString();
349  } ), rampTypes.end() );
350  }
351 
352  for ( const QPair< QString, QString > &type : rampTypes )
353  rampTypeNames << type.second;
354 
355  const QString selectedRampTypeName = QInputDialog::getItem( this, tr( "Color ramp type" ),
356  tr( "Please select color ramp type:" ), rampTypeNames, 0, false, &ok );
357 
358  if ( !ok || selectedRampTypeName.isEmpty() )
359  return;
360 
361  const QString rampType = rampTypes.value( rampTypeNames.indexOf( selectedRampTypeName ) ).first;
362 
363  QgsColorRamp *ramp = nullptr;
364  if ( rampType == QgsGradientColorRamp::typeString() )
365  {
366  ramp = new QgsGradientColorRamp();
367  }
368  else if ( rampType == QgsLimitedRandomColorRamp::typeString() )
369  {
370  ramp = new QgsLimitedRandomColorRamp();
371  }
372  else if ( rampType == QgsColorBrewerColorRamp::typeString() )
373  {
374  ramp = new QgsColorBrewerColorRamp();
375  }
376  else if ( rampType == QgsPresetSchemeColorRamp::typeString() )
377  {
378  ramp = new QgsPresetSchemeColorRamp();
379  }
380  else if ( rampType == QgsCptCityColorRamp::typeString() )
381  {
382  ramp = new QgsCptCityColorRamp( QString(), QString() );
383  }
384  else
385  {
386  QgsDebugMsg( "invalid ramp type " + rampType );
387  return;
388  }
389 
390  setColorRamp( ramp );
391  delete ramp;
392 
393  showColorRampDialog();
394 }
395 
396 void QgsColorRampButton::saveColorRamp()
397 {
398  QgsStyleSaveDialog saveDlg( this, QgsStyle::ColorrampEntity );
399  if ( !saveDlg.exec() || saveDlg.name().isEmpty() )
400  {
401  return;
402  }
403 
404  QgsStyle *destinationStyle = saveDlg.destinationStyle();
405 
406  // check if there is no symbol with same name
407  if ( destinationStyle->symbolNames().contains( saveDlg.name() ) )
408  {
409  const int res = QMessageBox::warning( this, tr( "Save Color Ramp" ),
410  tr( "Color ramp with name '%1' already exists. Overwrite?" )
411  .arg( saveDlg.name() ),
412  QMessageBox::Yes | QMessageBox::No );
413  if ( res != QMessageBox::Yes )
414  {
415  return;
416  }
417  destinationStyle->removeColorRamp( saveDlg.name() );
418  }
419 
420  const QStringList colorRampTags = saveDlg.tags().split( ',' );
421 
422  // add new symbol to style and re-populate the list
423  QgsColorRamp *ramp = colorRamp();
424  destinationStyle->addColorRamp( saveDlg.name(), ramp );
425  destinationStyle->saveColorRamp( saveDlg.name(), ramp, saveDlg.isFavorite(), colorRampTags );
426 
427  setColorRampName( saveDlg.name() );
428 }
429 
430 void QgsColorRampButton::invertColorRamp()
431 {
432  mColorRamp->invert();
434  emit colorRampChanged();
435 }
436 
438 {
439  if ( e->type() == QEvent::EnabledChange )
440  {
442  }
443  QToolButton::changeEvent( e );
444 }
445 
446 #if 0 // causes too many cyclical updates, but may be needed on some platforms
447 void QgsColorRampButton::paintEvent( QPaintEvent *e )
448 {
449  QToolButton::paintEvent( e );
450 
451  if ( !mBackgroundSet )
452  {
454  }
455 }
456 #endif
457 
458 void QgsColorRampButton::showEvent( QShowEvent *e )
459 {
461  QToolButton::showEvent( e );
462 }
463 
464 void QgsColorRampButton::resizeEvent( QResizeEvent *event )
465 {
466  QToolButton::resizeEvent( event );
467  //recalculate icon size and redraw icon
468  mIconSize = QSize();
469  setButtonBackground( mColorRamp.get() );
470 }
471 
473 {
474  if ( colorramp == mColorRamp.get() )
475  return;
476 
477  mColorRamp.reset( colorramp ? colorramp->clone() : nullptr );
478 
480  if ( isEnabled() )
481  {
482  emit colorRampChanged();
483  }
484 }
485 
486 void QgsColorRampButton::setColorRampFromName( const QString &name )
487 {
488  if ( !name.isEmpty() )
489  {
490  const 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  const 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.get();
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  const 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  const 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 
593 void QgsColorRampButton::setShowMenu( const bool showMenu )
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.get() );
600 }
601 
602 bool QgsColorRampButton::showMenu() const
603 {
604  return menu() ? true : false;
605 }
606 
608 {
609  mDefaultColorRamp.reset( colorramp ? colorramp->clone() : nullptr );
610 }
611 
613 {
614  return mDefaultColorRamp ? mDefaultColorRamp->clone() : nullptr;
615 }
616 
618 {
619  return dynamic_cast<QgsRandomColorRamp *>( mColorRamp.get() );
620 }
621 
622 void QgsColorRampButton::setShowNull( bool showNull )
623 {
624  mShowNull = showNull;
625 }
626 
628 {
629  return mShowNull;
630 }
631 
633 {
634  return !mColorRamp;
635 }
636 
637 void QgsColorRampButton::rampWidgetUpdated()
638 {
639  QgsLimitedRandomColorRampWidget *limitedRampWidget = qobject_cast< QgsLimitedRandomColorRampWidget * >( sender() );
640  if ( limitedRampWidget )
641  {
642  setColorRamp( limitedRampWidget->ramp().clone() );
643  emit colorRampChanged();
644  return;
645  }
646  QgsColorBrewerColorRampWidget *colorBrewerRampWidget = qobject_cast< QgsColorBrewerColorRampWidget * >( sender() );
647  if ( colorBrewerRampWidget )
648  {
649  setColorRamp( colorBrewerRampWidget->ramp().clone() );
650  emit colorRampChanged();
651  return;
652  }
653  QgsPresetColorRampWidget *presetRampWidget = qobject_cast< QgsPresetColorRampWidget * >( sender() );
654  if ( presetRampWidget )
655  {
656  setColorRamp( presetRampWidget->ramp().clone() );
657  emit colorRampChanged();
658  return;
659  }
660 }
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:607
QgsColorRamp
Abstract base class for color ramps.
Definition: qgscolorramp.h:29
QgsPresetSchemeColorRamp::clone
QgsPresetSchemeColorRamp * clone() const override
Creates a clone of the color ramp.
Definition: qgscolorrampimpl.cpp:1231
QgsColorRampButton::setShowMenu
void setShowMenu(bool showMenu)
Sets whether the drop-down menu should be shown for the button.
Definition: qgscolorrampbutton.cpp:593
QgsPresetColorRampDialog
A dialog which allows users to modify the properties of a QgsPresetSchemeColorRamp.
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: qgscolorrampimpl.h:136
QgsColorBrewerColorRamp::clone
QgsColorBrewerColorRamp * clone() const override
Creates a clone of the color ramp.
Definition: qgscolorrampimpl.cpp:896
QgsPresetColorRampWidget::ramp
QgsPresetSchemeColorRamp ramp
Definition: qgspresetcolorrampdialog.h:37
QgsColorRamp::rampTypes
static QList< QPair< QString, QString > > rampTypes()
Returns a list of available ramp types, where the first value in each item is the QgsColorRamp::type(...
Definition: qgscolorramp.cpp:21
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:54
QgsStyle::symbolsOfFavorite
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
Definition: qgsstyle.cpp:1301
QgsColorRampButton::colorRamp
QgsColorRamp * colorRamp() const
Returns a copy of the current color ramp.
Definition: qgscolorrampbutton.cpp:578
QgsColorRampButton::isRandomColorRamp
bool isRandomColorRamp() const
Returns true if the current color ramp is random.
Definition: qgscolorrampbutton.cpp:617
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: qgscolorrampimpl.h:543
qgssymbollayerutils.h
QgsGradientColorRampDialog
A dialog which allows users to modify the properties of a QgsGradientColorRamp.
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:84
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:421
QgsPresetColorRampWidget
A widget which allows users to modify the properties of a QgsPresetSchemeColorRamp.
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:507
QgsColorBrewerColorRamp::typeString
static QString typeString()
Returns the string identifier for QgsColorBrewerColorRamp.
Definition: qgscolorrampimpl.h:645
QgsLimitedRandomColorRamp
Constrained random color ramp, which returns random colors based on preset parameters.
Definition: qgscolorrampimpl.h:340
QgsPanelWidget::dockMode
bool dockMode()
Returns the dock mode state.
Definition: qgspanelwidget.h:93
QgsColorRampButton::setRandomColorRamp
void setRandomColorRamp()
Sets the current color ramp for the button to random colors.
Definition: qgscolorrampbutton.cpp:498
qgsstylesavedialog.h
QgsColorBrewerColorRamp
Color ramp utilising "Color Brewer" preset color schemes.
Definition: qgscolorrampimpl.h:615
QgsStyle::addColorRamp
bool addColorRamp(const QString &name, QgsColorRamp *colorRamp, bool update=false)
Adds a color ramp to the style.
Definition: qgsstyle.cpp:313
QgsGuiUtils::iconSize
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
Definition: qgsguiutils.cpp:264
QgsColorBrewerColorRampWidget
A widget which allows users to modify the properties of a QgsColorBrewerColorRamp.
Definition: qgscolorbrewercolorrampdialog.h:35
QgsStyle::defaultStyle
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:145
QgsRandomColorRamp
Totally random color ramp. Returns colors generated at random, but constrained to some hardcoded satu...
Definition: qgscolorrampimpl.h:492
qgsapplication.h
QgsCptCityColorRamp::typeString
static QString typeString()
Returns the string identifier for QgsCptCityColorRamp.
Definition: qgscolorrampimpl.h:750
QgsGradientColorRamp::typeString
static QString typeString()
Returns the string identifier for QgsGradientColorRamp.
Definition: qgscolorrampimpl.h:165
QgsPresetSchemeColorRamp::typeString
static QString typeString()
Returns the string identifier for QgsPresetSchemeColorRamp.
Definition: qgscolorrampimpl.h:588
qgscolorbrewercolorrampdialog.h
QgsPresetColorRampWidget::changed
void changed()
Emitted when the dialog settings change.
QgsColorRampButton::event
bool event(QEvent *e) override
Definition: qgscolorrampbutton.cpp:183
QgsColorBrewerColorRampDialog
A dialog which allows users to modify the properties of a QgsColorBrewerColorRamp.
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:622
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: qgscolorrampimpl.cpp:675
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
A dialog which allows users to modify the properties of a QgsCptCityColorRamp.
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 ramp is null.
Definition: qgscolorrampbutton.cpp:632
QgsColorRampButton::changeEvent
void changeEvent(QEvent *e) override
Definition: qgscolorrampbutton.cpp:437
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:627
QgsSymbolLayerUtils::colorRampPreviewPixmap
static QPixmap colorRampPreviewPixmap(QgsColorRamp *ramp, QSize size, int padding=0, Qt::Orientation direction=Qt::Horizontal, bool flipDirection=false, bool drawTransparentBackground=true)
Returns a pixmap preview for a color ramp.
Definition: qgssymbollayerutils.cpp:1026
QgsColorBrewerColorRampWidget::ramp
QgsColorBrewerColorRamp ramp
Definition: qgscolorbrewercolorrampdialog.h:38
Qgis::UI_SCALE_FACTOR
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition: qgis.h:2043
QgsLimitedRandomColorRampDialog
A dialog which allows users to modify the properties of a QgsLimitedRandomColorRamp.
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:486
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:307
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:457
QgsStyle
Definition: qgsstyle.h:159
QgsColorRampButton::resizeEvent
void resizeEvent(QResizeEvent *event) override
Definition: qgscolorrampbutton.cpp:464
qgslimitedrandomcolorrampdialog.h
qgsgradientcolorrampdialog.h
QgsStyle::colorRampNames
QStringList colorRampNames() const
Returns a list of names of color ramps.
Definition: qgsstyle.cpp:478
QgsLimitedRandomColorRampWidget
A widget which allows users to modify the properties of a QgsLimitedRandomColorRamp.
Definition: qgslimitedrandomcolorrampdialog.h:34
QgsCptCityColorRamp
Definition: qgscolorrampimpl.h:714
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:259
qgspresetcolorrampdialog.h
QgsLimitedRandomColorRamp::typeString
static QString typeString()
Returns the string identifier for QgsLimitedRandomColorRamp.
Definition: qgscolorrampimpl.h:375
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:462
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:583
QgsColorRampButton::setColorRamp
void setColorRamp(QgsColorRamp *colorramp)
Sets the current color ramp for the button.
Definition: qgscolorrampbutton.cpp:472
QgsSymbolLayerUtils::colorRampPreviewIcon
static QIcon colorRampPreviewIcon(QgsColorRamp *ramp, QSize size, int padding=0)
Returns an icon preview for a color ramp.
Definition: qgssymbollayerutils.cpp:1021
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:458