QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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 "qgslogger.h"
19#include "qgssymbollayerutils.h"
20#include "qgsstyle.h"
21#include "qgsguiutils.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
38QgsColorRampButton::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
72void 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
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
205QPixmap 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
213void QgsColorRampButton::buttonClicked()
214{
215 if ( !isRandomColorRamp() && !isNull() )
216 {
217 showColorRampDialog();
218 }
219 else
220 {
221 QToolButton::showMenu();
222 }
223}
224
225void 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
325void 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
336void 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 QgsDebugError( "invalid ramp type " + rampType );
387 return;
388 }
389
390 setColorRamp( ramp );
391 delete ramp;
392
393 showColorRampDialog();
394}
395
396void QgsColorRampButton::saveColorRamp()
397{
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
430void 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
447void QgsColorRampButton::paintEvent( QPaintEvent *e )
448{
449 QToolButton::paintEvent( e );
450
451 if ( !mBackgroundSet )
452 {
454 }
455}
456#endif
457
458void QgsColorRampButton::showEvent( QShowEvent *e )
459{
461 QToolButton::showEvent( e );
462}
463
464void 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
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
593void 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
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
623{
624 mShowNull = showNull;
625}
626
628{
629 return mShowNull;
630}
631
633{
634 return !mColorRamp;
635}
636
637void 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}
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition: qgis.h:4927
A dialog which allows users to modify the properties of a QgsColorBrewerColorRamp.
A widget which allows users to modify the properties of a QgsColorBrewerColorRamp.
void changed()
Emitted when the dialog settings change.
Color ramp utilising "Color Brewer" preset color schemes.
QgsColorBrewerColorRamp * clone() const override
Creates a clone of the color ramp.
static QString typeString()
Returns the string identifier for QgsColorBrewerColorRamp.
bool isNull() const
Returns true if the current color ramp is null.
void changeEvent(QEvent *e) override
QgsColorRamp * defaultColorRamp
void setColorRampDialogTitle(const QString &title)
Set the title for the color ramp dialog window.
~QgsColorRampButton() override
void setRandomColorRamp()
Sets the current color ramp for the button to random colors.
void setColorRamp(QgsColorRamp *colorramp)
Sets the current color ramp for the button.
void setButtonBackground(QgsColorRamp *colorramp=nullptr)
Sets the background pixmap for the button based upon current color ramp.
QgsColorRamp * colorRamp() const
Returns a copy of the current color ramp.
void setDefaultColorRamp(QgsColorRamp *colorramp)
Sets the default color ramp for the button, which is shown in the button's drop-down menu for the "de...
void setShowNull(bool showNull)
Sets whether a set to null (clear) option is shown in the button's drop-down menu.
void resizeEvent(QResizeEvent *event) override
void colorRampChanged()
Emitted whenever a new color ramp is set for the button.
void setShowMenu(bool showMenu)
Sets whether the drop-down menu should be shown for the button.
bool showNull() const
Returns whether the set to null (clear) option is shown in the button's drop-down menu.
QSize sizeHint() const override
QgsColorRampButton(QWidget *parent=nullptr, const QString &dialogTitle=QString())
Construct a new color ramp button.
void setToDefaultColorRamp()
Sets color ramp to the button's default color ramp, if set.
void setColorRampName(const QString &name)
Sets the name of the current color ramp when it's available in the style manager.
void setToNull()
Sets color ramp to null.
void showEvent(QShowEvent *e) override
QString colorRampName() const
Returns the name of the current color ramp when it's available in the style manager.
bool isRandomColorRamp() const
Returns true if the current color ramp is random.
void mousePressEvent(QMouseEvent *e) override
Reimplemented to detect right mouse button clicks on the color ramp button.
void setColorRampFromName(const QString &name=QString())
Sets the current color ramp for the button using a saved color ramp name.
bool event(QEvent *e) override
Abstract base class for color ramps.
Definition: qgscolorramp.h:29
static QList< QPair< QString, QString > > rampTypes()
Returns a list of available ramp types, where the first value in each item is the QgsColorRamp::type(...
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
A dialog which allows users to modify the properties of a QgsCptCityColorRamp.
static QString typeString()
Returns the string identifier for QgsCptCityColorRamp.
A dialog which allows users to modify the properties of a QgsGradientColorRamp.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
static QString typeString()
Returns the string identifier for QgsGradientColorRamp.
A dialog which allows users to modify the properties of a QgsLimitedRandomColorRamp.
A widget which allows users to modify the properties of a QgsLimitedRandomColorRamp.
void changed()
Emitted when the dialog settings change.
Constrained random color ramp, which returns random colors based on preset parameters.
static QString typeString()
Returns the string identifier for QgsLimitedRandomColorRamp.
QgsLimitedRandomColorRamp * clone() const override
Creates a clone of the color ramp.
Base class for any widget that can be shown as a inline panel.
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
bool dockMode()
Returns the dock mode state.
A dialog which allows users to modify the properties of a QgsPresetSchemeColorRamp.
A widget which allows users to modify the properties of a QgsPresetSchemeColorRamp.
QgsPresetSchemeColorRamp ramp
void changed()
Emitted when the dialog settings change.
A scheme based color ramp consisting of a list of predefined colors.
static QString typeString()
Returns the string identifier for QgsPresetSchemeColorRamp.
QgsPresetSchemeColorRamp * clone() const override
Creates a clone of the color ramp.
Totally random color ramp.
a dialog for setting properties of a newly saved style.
bool saveColorRamp(const QString &name, QgsColorRamp *ramp, bool favorite, const QStringList &tags)
Adds the colorramp to the database.
Definition: qgsstyle.cpp:453
bool addColorRamp(const QString &name, QgsColorRamp *colorRamp, bool update=false)
Adds a color ramp to the style.
Definition: qgsstyle.cpp:345
@ ColorrampEntity
Color ramps.
Definition: qgsstyle.h:182
QStringList colorRampNames() const
Returns a list of names of color ramps.
Definition: qgsstyle.cpp:510
QgsColorRamp * colorRamp(const QString &name) const
Returns a new copy of the specified color ramp.
Definition: qgsstyle.cpp:494
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition: qgsstyle.cpp:145
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
Definition: qgsstyle.cpp:1333
bool removeColorRamp(const QString &name)
Removes color ramp from style (and delete it)
Definition: qgsstyle.cpp:489
QStringList symbolNames() const
Returns a list of names of symbols.
Definition: qgsstyle.cpp:339
static QIcon colorRampPreviewIcon(QgsColorRamp *ramp, QSize size, int padding=0)
Returns an icon preview for a color ramp.
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.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
#define QgsDebugError(str)
Definition: qgslogger.h:38