QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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#include "moc_qgscolorrampbutton.cpp"
30
31#include <QAction>
32#include <QInputDialog>
33#include <QMessageBox>
34#include <QMouseEvent>
35#include <QMenu>
36#include <QPainter>
37#include <QPushButton>
38
39QgsColorRampButton::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
63{
64 //make sure height of button looks good under different platforms
65#ifdef Q_OS_WIN
66 return QSize( 120, static_cast<int>( std::max( Qgis::UI_SCALE_FACTOR * fontMetrics().height(), 22.0 ) ) );
67#else
68 // Adjust height for HiDPI screens
69 return QSize( 120, static_cast<int>( std::max( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.4, 28.0 ) ) );
70#endif
71}
72
73void QgsColorRampButton::showColorRampDialog()
74{
76 const bool panelMode = panel && panel->dockMode();
77
78 std::unique_ptr<QgsColorRamp> currentRamp( colorRamp() );
79 if ( !currentRamp )
80 return;
81
82 setColorRampName( QString() );
83
84 if ( currentRamp->type() == QgsGradientColorRamp::typeString() )
85 {
86 QgsGradientColorRamp *gradRamp = static_cast<QgsGradientColorRamp *>( currentRamp.get() );
87 QgsGradientColorRampDialog dlg( *gradRamp, this );
88 dlg.setWindowTitle( mColorRampDialogTitle );
89 if ( dlg.exec() )
90 {
91 setColorRamp( dlg.ramp().clone() );
92 }
93 }
94 else if ( currentRamp->type() == QgsLimitedRandomColorRamp::typeString() )
95 {
96 QgsLimitedRandomColorRamp *randRamp = static_cast<QgsLimitedRandomColorRamp *>( currentRamp.get() );
97 if ( panelMode )
98 {
100 widget->setPanelTitle( tr( "Edit Ramp" ) );
101 connect( widget, &QgsLimitedRandomColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated );
102 panel->openPanel( widget );
103 }
104 else
105 {
106 QgsLimitedRandomColorRampDialog dlg( *randRamp, this );
107 if ( dlg.exec() )
108 {
109 setColorRamp( dlg.ramp().clone() );
110 }
111 }
112 }
113 else if ( currentRamp->type() == QgsPresetSchemeColorRamp::typeString() )
114 {
115 QgsPresetSchemeColorRamp *presetRamp = static_cast<QgsPresetSchemeColorRamp *>( currentRamp.get() );
116 if ( panelMode )
117 {
118 QgsPresetColorRampWidget *widget = new QgsPresetColorRampWidget( *presetRamp, this );
119 widget->setPanelTitle( tr( "Edit Ramp" ) );
120 connect( widget, &QgsPresetColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated );
121 panel->openPanel( widget );
122 }
123 else
124 {
125 QgsPresetColorRampDialog dlg( *presetRamp, this );
126 if ( dlg.exec() )
127 {
128 setColorRamp( dlg.ramp().clone() );
129 }
130 }
131 }
132 else if ( currentRamp->type() == QgsColorBrewerColorRamp::typeString() )
133 {
134 QgsColorBrewerColorRamp *brewerRamp = static_cast<QgsColorBrewerColorRamp *>( currentRamp.get() );
135 if ( panelMode )
136 {
137 QgsColorBrewerColorRampWidget *widget = new QgsColorBrewerColorRampWidget( *brewerRamp, this );
138 widget->setPanelTitle( tr( "Edit Ramp" ) );
139 connect( widget, &QgsColorBrewerColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated );
140 panel->openPanel( widget );
141 }
142 else
143 {
144 QgsColorBrewerColorRampDialog dlg( *brewerRamp, this );
145 if ( dlg.exec() )
146 {
147 setColorRamp( dlg.ramp().clone() );
148 }
149 }
150 }
151 else if ( currentRamp->type() == QgsCptCityColorRamp::typeString() )
152 {
153 QgsCptCityColorRamp *cptCityRamp = static_cast<QgsCptCityColorRamp *>( currentRamp.get() );
154 QgsCptCityColorRampDialog dlg( *cptCityRamp, this );
155 if ( dlg.exec() )
156 {
157 if ( dlg.saveAsGradientRamp() )
158 {
159 setColorRamp( dlg.ramp().cloneGradientRamp() );
160 }
161 else
162 {
163 setColorRamp( dlg.ramp().clone() );
164 }
165 }
166 }
167}
168
170{
171 if ( !mDefaultColorRamp )
172 {
173 return;
174 }
175
176 setColorRamp( mDefaultColorRamp.get() );
177}
178
180{
181 setColorRamp( nullptr );
182}
183
185{
186 if ( e->type() == QEvent::ToolTip )
187 {
188 if ( !colorRampName().isEmpty() )
189 {
190 setToolTip( colorRampName() );
191 }
192 }
193 return QToolButton::event( e );
194}
195
197{
198 if ( e->button() == Qt::RightButton )
199 {
200 QToolButton::showMenu();
201 return;
202 }
203 QToolButton::mousePressEvent( e );
204}
205
206QPixmap QgsColorRampButton::createMenuIcon( QgsColorRamp *colorramp )
207{
208 //create an icon pixmap
209 const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
210 const QPixmap pixmap = QgsSymbolLayerUtils::colorRampPreviewPixmap( colorramp, QSize( iconSize, iconSize ) );
211 return pixmap;
212}
213
214void QgsColorRampButton::buttonClicked()
215{
216 if ( !isRandomColorRamp() && !isNull() )
217 {
218 showColorRampDialog();
219 }
220 else
221 {
222 QToolButton::showMenu();
223 }
224}
225
226void QgsColorRampButton::prepareMenu()
227{
228 mMenu->clear();
229
230 QAction *invertAction = new QAction( tr( "Invert Color Ramp" ), this );
231 invertAction->setEnabled( !isNull() && !isRandomColorRamp() );
232 mMenu->addAction( invertAction );
233 connect( invertAction, &QAction::triggered, this, &QgsColorRampButton::invertColorRamp );
234
235 if ( mShowNull )
236 {
237 QAction *nullAction = new QAction( tr( "Clear Current Ramp" ), this );
238 nullAction->setEnabled( !isNull() );
239 mMenu->addAction( nullAction );
240 connect( nullAction, &QAction::triggered, this, &QgsColorRampButton::setToNull );
241 }
242
243 mMenu->addSeparator();
244
245 //show default color option if set
246 if ( mDefaultColorRamp )
247 {
248 QAction *defaultColorRampAction = new QAction( tr( "Default Color Ramp" ), this );
249 defaultColorRampAction->setIcon( createMenuIcon( mDefaultColorRamp.get() ) );
250 mMenu->addAction( defaultColorRampAction );
251 connect( defaultColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setToDefaultColorRamp );
252 }
253
254 if ( mShowRandomColorRamp )
255 {
256 QAction *randomColorRampAction = new QAction( tr( "Random Color Ramp" ), this );
257 randomColorRampAction->setCheckable( true );
258 randomColorRampAction->setChecked( isRandomColorRamp() );
259 mMenu->addAction( randomColorRampAction );
260 connect( randomColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setRandomColorRamp );
261
262 if ( isRandomColorRamp() || dynamic_cast<QgsLimitedRandomColorRamp *>( mColorRamp.get() ) )
263 {
264 QAction *shuffleRandomColorRampAction = new QAction( tr( "Shuffle Random Colors" ), this );
265 mMenu->addAction( shuffleRandomColorRampAction );
266 connect( shuffleRandomColorRampAction, &QAction::triggered, this, &QgsColorRampButton::colorRampChanged );
267 }
268 }
269
270 mMenu->addSeparator();
271
272 QStringList rampNames = mStyle->symbolsOfFavorite( QgsStyle::ColorrampEntity );
273 rampNames.sort();
274 const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
275 for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
276 {
277 std::unique_ptr<QgsColorRamp> ramp( mStyle->colorRamp( *it ) );
278
279 if ( !mShowGradientOnly || ( ramp->type() == QgsGradientColorRamp::typeString() || ramp->type() == QgsCptCityColorRamp::typeString() ) )
280 {
281 const QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( iconSize, iconSize ) );
282 QAction *ra = new QAction( *it, this );
283 ra->setIcon( icon );
284 connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
285 mMenu->addAction( ra );
286 }
287 }
288
289 mMenu->addSeparator();
290
291 mAllRampsMenu->clear();
292 mMenu->addMenu( mAllRampsMenu );
293 rampNames = mStyle->colorRampNames();
294 rampNames.sort();
295 for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
296 {
297 std::unique_ptr<QgsColorRamp> ramp( mStyle->colorRamp( *it ) );
298
299 if ( !mShowGradientOnly || ( ramp->type() == QgsGradientColorRamp::typeString() || ramp->type() == QgsCptCityColorRamp::typeString() ) )
300 {
301 const QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( iconSize, iconSize ) );
302 QAction *ra = new QAction( *it, this );
303 ra->setIcon( icon );
304 connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
305 mAllRampsMenu->addAction( ra );
306 }
307 }
308
309 mMenu->addSeparator();
310
311 QAction *newColorRampAction = new QAction( tr( "Create New Color Ramp…" ), this );
312 connect( newColorRampAction, &QAction::triggered, this, &QgsColorRampButton::createColorRamp );
313 mMenu->addAction( newColorRampAction );
314
315 QAction *editColorRampAction = new QAction( tr( "Edit Color Ramp…" ), this );
316 editColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
317 connect( editColorRampAction, &QAction::triggered, this, &QgsColorRampButton::showColorRampDialog );
318 mMenu->addAction( editColorRampAction );
319
320 QAction *saveColorRampAction = new QAction( tr( "Save Color Ramp…" ), this );
321 saveColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
322 connect( saveColorRampAction, &QAction::triggered, this, &QgsColorRampButton::saveColorRamp );
323 mMenu->addAction( saveColorRampAction );
324}
325
326void QgsColorRampButton::loadColorRamp()
327{
328 QAction *selectedItem = qobject_cast<QAction *>( sender() );
329 if ( selectedItem )
330 {
331 const QString name = selectedItem->iconText();
332 setColorRampName( name );
333 setColorRampFromName( name );
334 }
335}
336
337void QgsColorRampButton::createColorRamp()
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 return type.first != QgsGradientColorRamp::typeString() && type.first != QgsCptCityColorRamp::typeString();
348 } ),
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" ), tr( "Please select color ramp type:" ), rampTypeNames, 0, false, &ok );
356
357 if ( !ok || selectedRampTypeName.isEmpty() )
358 return;
359
360 const QString rampType = rampTypes.value( rampTypeNames.indexOf( selectedRampTypeName ) ).first;
361
362 QgsColorRamp *ramp = nullptr;
363 if ( rampType == QgsGradientColorRamp::typeString() )
364 {
365 ramp = new QgsGradientColorRamp();
366 }
367 else if ( rampType == QgsLimitedRandomColorRamp::typeString() )
368 {
369 ramp = new QgsLimitedRandomColorRamp();
370 }
371 else if ( rampType == QgsColorBrewerColorRamp::typeString() )
372 {
373 ramp = new QgsColorBrewerColorRamp();
374 }
375 else if ( rampType == QgsPresetSchemeColorRamp::typeString() )
376 {
377 ramp = new QgsPresetSchemeColorRamp();
378 }
379 else if ( rampType == QgsCptCityColorRamp::typeString() )
380 {
381 ramp = new QgsCptCityColorRamp( QString(), QString() );
382 }
383 else
384 {
385 QgsDebugError( "invalid ramp type " + rampType );
386 return;
387 }
388
389 setColorRamp( ramp );
390 delete ramp;
391
392 showColorRampDialog();
393}
394
395void QgsColorRampButton::saveColorRamp()
396{
398 if ( !saveDlg.exec() || saveDlg.name().isEmpty() )
399 {
400 return;
401 }
402
403 QgsStyle *destinationStyle = saveDlg.destinationStyle();
404
405 // check if there is no symbol with same name
406 if ( destinationStyle->symbolNames().contains( saveDlg.name() ) )
407 {
408 const int res = QMessageBox::warning( this, tr( "Save Color Ramp" ), tr( "Color ramp with name '%1' already exists. Overwrite?" ).arg( saveDlg.name() ), QMessageBox::Yes | QMessageBox::No );
409 if ( res != QMessageBox::Yes )
410 {
411 return;
412 }
413 destinationStyle->removeColorRamp( saveDlg.name() );
414 }
415
416 const QStringList colorRampTags = saveDlg.tags().split( ',' );
417
418 // add new symbol to style and re-populate the list
419 QgsColorRamp *ramp = colorRamp();
420 destinationStyle->addColorRamp( saveDlg.name(), ramp );
421 destinationStyle->saveColorRamp( saveDlg.name(), ramp, saveDlg.isFavorite(), colorRampTags );
422
423 setColorRampName( saveDlg.name() );
424}
425
426void 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
443void QgsColorRampButton::paintEvent( QPaintEvent *e )
444{
445 QToolButton::paintEvent( e );
446
447 if ( !mBackgroundSet )
448 {
450 }
451}
452#endif
453
454void QgsColorRampButton::showEvent( QShowEvent *e )
455{
457 QToolButton::showEvent( e );
458}
459
460void QgsColorRampButton::resizeEvent( QResizeEvent *event )
461{
462 QToolButton::resizeEvent( event );
463 //recalculate icon size and redraw icon
464 mIconSize = QSize();
465 setButtonBackground( mColorRamp.get() );
466}
467
469{
470 if ( colorramp == mColorRamp.get() )
471 return;
472
473 mColorRamp.reset( colorramp ? colorramp->clone() : nullptr );
474
476 if ( isEnabled() )
477 {
478 emit colorRampChanged();
479 }
480}
481
483{
484 if ( !name.isEmpty() )
485 {
486 const std::unique_ptr<QgsColorRamp> ramp( mStyle->colorRamp( name ) );
487 if ( ramp )
488 {
489 setColorRamp( ramp.get() );
490 }
491 }
492}
493
495{
496 if ( !isRandomColorRamp() )
497 {
498 const std::unique_ptr<QgsRandomColorRamp> newRamp( new QgsRandomColorRamp() );
499 setColorRamp( newRamp.get() );
500 }
501}
502
504{
505 QgsColorRamp *backgroundColorRamp = colorramp;
506 if ( !colorramp )
507 {
508 backgroundColorRamp = mColorRamp.get();
509 }
510
511 QSize currentIconSize;
512 //icon size is button size with a small margin
513 if ( menu() )
514 {
515 if ( !mIconSize.isValid() )
516 {
517 //calculate size of push button part of widget (ie, without the menu drop-down button part)
518 QStyleOptionToolButton opt;
519 initStyleOption( &opt );
520 const QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton, this );
521 //make sure height of icon looks good under different platforms
522#ifdef Q_OS_WIN
523 mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
524#else
525 mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
526#endif
527 }
528 currentIconSize = mIconSize;
529 }
530 else
531 {
532 //no menu
533#ifdef Q_OS_WIN
534 currentIconSize = QSize( width() - 10, height() - 6 );
535#else
536 currentIconSize = QSize( width() - 10, height() - 12 );
537#endif
538 }
539
540 if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
541 {
542 return;
543 }
544
545 QPixmap pm;
546 if ( isRandomColorRamp() )
547 {
548 //create a "random colors" label
549 pm = QPixmap( currentIconSize );
550 pm.fill( Qt::transparent );
551
552 QPainter painter;
553 const QPen pen = ( palette().buttonText().color() );
554
555 painter.begin( &pm );
556 painter.setPen( pen );
557 painter.drawText( QRect( 0, 0, currentIconSize.width(), currentIconSize.height() ), Qt::AlignCenter, QStringLiteral( "Random colors" ) );
558 painter.end();
559 }
560 else
561 {
562 //create an icon pixmap
563 if ( backgroundColorRamp )
564 {
565 pm = QgsSymbolLayerUtils::colorRampPreviewPixmap( backgroundColorRamp, currentIconSize );
566 }
567 }
568
569 setIconSize( currentIconSize );
570 setIcon( pm );
571}
572
574{
575 return mColorRamp ? mColorRamp->clone() : nullptr;
576}
577
579{
580 mColorRampDialogTitle = title;
581}
582
584{
585 return mColorRampDialogTitle;
586}
587
588void QgsColorRampButton::setShowMenu( const bool showMenu )
589{
590 setMenu( showMenu ? mMenu : nullptr );
591 setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
592 //force recalculation of icon size
593 mIconSize = QSize();
594 setButtonBackground( mColorRamp.get() );
595}
596
598{
599 return menu() ? true : false;
600}
601
603{
604 mDefaultColorRamp.reset( colorramp ? colorramp->clone() : nullptr );
605}
606
608{
609 return mDefaultColorRamp ? mDefaultColorRamp->clone() : nullptr;
610}
611
613{
614 return dynamic_cast<QgsRandomColorRamp *>( mColorRamp.get() );
615}
616
618{
619 mShowNull = showNull;
620}
621
623{
624 return mShowNull;
625}
626
628{
629 return !mColorRamp;
630}
631
632void QgsColorRampButton::rampWidgetUpdated()
633{
634 QgsLimitedRandomColorRampWidget *limitedRampWidget = qobject_cast<QgsLimitedRandomColorRampWidget *>( sender() );
635 if ( limitedRampWidget )
636 {
637 setColorRamp( limitedRampWidget->ramp().clone() );
638 emit colorRampChanged();
639 return;
640 }
641 QgsColorBrewerColorRampWidget *colorBrewerRampWidget = qobject_cast<QgsColorBrewerColorRampWidget *>( sender() );
642 if ( colorBrewerRampWidget )
643 {
644 setColorRamp( colorBrewerRampWidget->ramp().clone() );
645 emit colorRampChanged();
646 return;
647 }
648 QgsPresetColorRampWidget *presetRampWidget = qobject_cast<QgsPresetColorRampWidget *>( sender() );
649 if ( presetRampWidget )
650 {
651 setColorRamp( presetRampWidget->ramp().clone() );
652 emit colorRampChanged();
653 return;
654 }
655}
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition qgis.h:5733
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.
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.
A color ramp from the CPT City collection.
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:454
bool addColorRamp(const QString &name, QgsColorRamp *colorRamp, bool update=false)
Adds a color ramp to the style.
Definition qgsstyle.cpp:346
@ ColorrampEntity
Color ramps.
Definition qgsstyle.h:206
QStringList colorRampNames() const
Returns a list of names of color ramps.
Definition qgsstyle.cpp:511
QgsColorRamp * colorRamp(const QString &name) const
Returns a new copy of the specified color ramp.
Definition qgsstyle.cpp:495
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:146
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
bool removeColorRamp(const QString &name)
Removes color ramp from style (and delete it)
Definition qgsstyle.cpp:490
QStringList symbolNames() const
Returns a list of names of symbols.
Definition qgsstyle.cpp:340
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