QGIS API Documentation 3.99.0-Master (d270888f95f)
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
19#include "qgscolorramp.h"
22#include "qgsguiutils.h"
24#include "qgslogger.h"
26#include "qgsstyle.h"
27#include "qgsstylesavedialog.h"
28#include "qgssymbollayerutils.h"
29
30#include <QAction>
31#include <QInputDialog>
32#include <QMenu>
33#include <QMessageBox>
34#include <QMouseEvent>
35#include <QPainter>
36#include <QPushButton>
37#include <QString>
38
39#include "moc_qgscolorrampbutton.cpp"
40
41using namespace Qt::StringLiterals;
42
43QgsColorRampButton::QgsColorRampButton( QWidget *parent, const QString &dialogTitle )
44 : QToolButton( parent )
45 , mColorRampDialogTitle( dialogTitle.isEmpty() ? tr( "Select Color Ramp" ) : dialogTitle )
46{
47 setAcceptDrops( true );
48 setMinimumSize( QSize( 24, 16 ) );
49 connect( this, &QPushButton::clicked, this, &QgsColorRampButton::buttonClicked );
50
51 //setup drop-down menu
52 mMenu = new QMenu( this );
53 connect( mMenu, &QMenu::aboutToShow, this, &QgsColorRampButton::prepareMenu );
54 setMenu( mMenu );
55
56 mAllRampsMenu = new QMenu( mMenu );
57 mAllRampsMenu->setTitle( tr( "All Color Ramps" ) );
58
59 setPopupMode( QToolButton::MenuButtonPopup );
60
61 mStyle = QgsStyle::defaultStyle();
62}
63
65
67{
68 //make sure height of button looks good under different platforms
69#ifdef Q_OS_WIN
70 return QSize( 120, static_cast<int>( std::max( Qgis::UI_SCALE_FACTOR * fontMetrics().height(), 22.0 ) ) );
71#else
72 // Adjust height for HiDPI screens
73 return QSize( 120, static_cast<int>( std::max( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.4, 28.0 ) ) );
74#endif
75}
76
77void QgsColorRampButton::showColorRampDialog()
78{
80 const bool panelMode = panel && panel->dockMode();
81
82 std::unique_ptr<QgsColorRamp> currentRamp( colorRamp() );
83 if ( !currentRamp )
84 return;
85
86 setColorRampName( QString() );
87
88 if ( currentRamp->type() == QgsGradientColorRamp::typeString() )
89 {
90 QgsGradientColorRamp *gradRamp = static_cast<QgsGradientColorRamp *>( currentRamp.get() );
91 QgsGradientColorRampDialog dlg( *gradRamp, this );
92 dlg.setWindowTitle( mColorRampDialogTitle );
93 if ( dlg.exec() )
94 {
95 setColorRamp( dlg.ramp().clone() );
96 }
97 }
98 else if ( currentRamp->type() == QgsLimitedRandomColorRamp::typeString() )
99 {
100 QgsLimitedRandomColorRamp *randRamp = static_cast<QgsLimitedRandomColorRamp *>( currentRamp.get() );
101 if ( panelMode )
102 {
103 QgsLimitedRandomColorRampWidget *widget = new QgsLimitedRandomColorRampWidget( *randRamp, this );
104 widget->setPanelTitle( tr( "Edit Ramp" ) );
105 connect( widget, &QgsLimitedRandomColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated );
106 panel->openPanel( widget );
107 }
108 else
109 {
110 QgsLimitedRandomColorRampDialog dlg( *randRamp, this );
111 if ( dlg.exec() )
112 {
113 setColorRamp( dlg.ramp().clone() );
114 }
115 }
116 }
117 else if ( currentRamp->type() == QgsPresetSchemeColorRamp::typeString() )
118 {
119 QgsPresetSchemeColorRamp *presetRamp = static_cast<QgsPresetSchemeColorRamp *>( currentRamp.get() );
120 if ( panelMode )
121 {
122 QgsPresetColorRampWidget *widget = new QgsPresetColorRampWidget( *presetRamp, this );
123 widget->setPanelTitle( tr( "Edit Ramp" ) );
124 connect( widget, &QgsPresetColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated );
125 panel->openPanel( widget );
126 }
127 else
128 {
129 QgsPresetColorRampDialog dlg( *presetRamp, this );
130 if ( dlg.exec() )
131 {
132 setColorRamp( dlg.ramp().clone() );
133 }
134 }
135 }
136 else if ( currentRamp->type() == QgsColorBrewerColorRamp::typeString() )
137 {
138 QgsColorBrewerColorRamp *brewerRamp = static_cast<QgsColorBrewerColorRamp *>( currentRamp.get() );
139 if ( panelMode )
140 {
141 QgsColorBrewerColorRampWidget *widget = new QgsColorBrewerColorRampWidget( *brewerRamp, this );
142 widget->setPanelTitle( tr( "Edit Ramp" ) );
143 connect( widget, &QgsColorBrewerColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated );
144 panel->openPanel( widget );
145 }
146 else
147 {
148 QgsColorBrewerColorRampDialog dlg( *brewerRamp, this );
149 if ( dlg.exec() )
150 {
151 setColorRamp( dlg.ramp().clone() );
152 }
153 }
154 }
155 else if ( currentRamp->type() == QgsCptCityColorRamp::typeString() )
156 {
157 QgsCptCityColorRamp *cptCityRamp = static_cast<QgsCptCityColorRamp *>( currentRamp.get() );
158 QgsCptCityColorRampDialog dlg( *cptCityRamp, this );
159 if ( dlg.exec() )
160 {
161 if ( dlg.saveAsGradientRamp() )
162 {
163 setColorRamp( dlg.ramp().cloneGradientRamp() );
164 }
165 else
166 {
167 setColorRamp( dlg.ramp().clone() );
168 }
169 }
170 }
171}
172
174{
175 if ( !mDefaultColorRamp )
176 {
177 return;
178 }
179
180 setColorRamp( mDefaultColorRamp.get() );
181}
182
184{
185 setColorRamp( nullptr );
186}
187
189{
190 if ( e->type() == QEvent::ToolTip )
191 {
192 if ( !colorRampName().isEmpty() )
193 {
194 setToolTip( colorRampName() );
195 }
196 }
197 return QToolButton::event( e );
198}
199
201{
202 if ( e->button() == Qt::RightButton )
203 {
204 QToolButton::showMenu();
205 return;
206 }
207 QToolButton::mousePressEvent( e );
208}
209
210QPixmap QgsColorRampButton::createMenuIcon( QgsColorRamp *colorramp )
211{
212 //create an icon pixmap
213 const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
214 const QPixmap pixmap = QgsSymbolLayerUtils::colorRampPreviewPixmap( colorramp, QSize( iconSize, iconSize ) );
215 return pixmap;
216}
217
218void QgsColorRampButton::buttonClicked()
219{
220 if ( !isRandomColorRamp() && !isNull() )
221 {
222 showColorRampDialog();
223 }
224 else
225 {
226 QToolButton::showMenu();
227 }
228}
229
230void QgsColorRampButton::prepareMenu()
231{
232 mMenu->clear();
233
234 QAction *invertAction = new QAction( tr( "Invert Color Ramp" ), this );
235 invertAction->setEnabled( !isNull() && !isRandomColorRamp() );
236 mMenu->addAction( invertAction );
237 connect( invertAction, &QAction::triggered, this, &QgsColorRampButton::invertColorRamp );
238
239 if ( mShowNull )
240 {
241 QAction *nullAction = new QAction( tr( "Clear Current Ramp" ), this );
242 nullAction->setEnabled( !isNull() );
243 mMenu->addAction( nullAction );
244 connect( nullAction, &QAction::triggered, this, &QgsColorRampButton::setToNull );
245 }
246
247 mMenu->addSeparator();
248
249 //show default color option if set
250 if ( mDefaultColorRamp )
251 {
252 QAction *defaultColorRampAction = new QAction( tr( "Default Color Ramp" ), this );
253 defaultColorRampAction->setIcon( createMenuIcon( mDefaultColorRamp.get() ) );
254 mMenu->addAction( defaultColorRampAction );
255 connect( defaultColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setToDefaultColorRamp );
256 }
257
258 if ( mShowRandomColorRamp )
259 {
260 QAction *randomColorRampAction = new QAction( tr( "Random Color Ramp" ), this );
261 randomColorRampAction->setCheckable( true );
262 randomColorRampAction->setChecked( isRandomColorRamp() );
263 mMenu->addAction( randomColorRampAction );
264 connect( randomColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setRandomColorRamp );
265
266 if ( isRandomColorRamp() || dynamic_cast<QgsLimitedRandomColorRamp *>( mColorRamp.get() ) )
267 {
268 QAction *shuffleRandomColorRampAction = new QAction( tr( "Shuffle Random Colors" ), this );
269 mMenu->addAction( shuffleRandomColorRampAction );
270 connect( shuffleRandomColorRampAction, &QAction::triggered, this, &QgsColorRampButton::colorRampChanged );
271 }
272 }
273
274 mMenu->addSeparator();
275
276 QStringList rampNames = mStyle->symbolsOfFavorite( QgsStyle::ColorrampEntity );
277 rampNames.sort();
278 const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
279 for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
280 {
281 std::unique_ptr<QgsColorRamp> ramp( mStyle->colorRamp( *it ) );
282
283 if ( !mShowGradientOnly || ( ramp->type() == QgsGradientColorRamp::typeString() || ramp->type() == QgsCptCityColorRamp::typeString() ) )
284 {
285 const QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( iconSize, iconSize ) );
286 QAction *ra = new QAction( *it, this );
287 ra->setIcon( icon );
288 connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
289 mMenu->addAction( ra );
290 }
291 }
292
293 mMenu->addSeparator();
294
295 mAllRampsMenu->clear();
296 mMenu->addMenu( mAllRampsMenu );
297 rampNames = mStyle->colorRampNames();
298 rampNames.sort();
299 for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
300 {
301 std::unique_ptr<QgsColorRamp> ramp( mStyle->colorRamp( *it ) );
302
303 if ( !mShowGradientOnly || ( ramp->type() == QgsGradientColorRamp::typeString() || ramp->type() == QgsCptCityColorRamp::typeString() ) )
304 {
305 const QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( iconSize, iconSize ) );
306 QAction *ra = new QAction( *it, this );
307 ra->setIcon( icon );
308 connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
309 mAllRampsMenu->addAction( ra );
310 }
311 }
312
313 mMenu->addSeparator();
314
315 QAction *newColorRampAction = new QAction( tr( "Create New Color Ramp…" ), this );
316 connect( newColorRampAction, &QAction::triggered, this, &QgsColorRampButton::createColorRamp );
317 mMenu->addAction( newColorRampAction );
318
319 QAction *editColorRampAction = new QAction( tr( "Edit Color Ramp…" ), this );
320 editColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
321 connect( editColorRampAction, &QAction::triggered, this, &QgsColorRampButton::showColorRampDialog );
322 mMenu->addAction( editColorRampAction );
323
324 QAction *saveColorRampAction = new QAction( tr( "Save Color Ramp…" ), this );
325 saveColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
326 connect( saveColorRampAction, &QAction::triggered, this, &QgsColorRampButton::saveColorRamp );
327 mMenu->addAction( saveColorRampAction );
328}
329
330void QgsColorRampButton::loadColorRamp()
331{
332 QAction *selectedItem = qobject_cast<QAction *>( sender() );
333 if ( selectedItem )
334 {
335 const QString name = selectedItem->iconText();
336 setColorRampName( name );
337 setColorRampFromName( name );
338 }
339}
340
341void QgsColorRampButton::createColorRamp()
342{
343 bool ok = true;
344
345 QList<QPair<QString, QString>> rampTypes = QgsColorRamp::rampTypes();
346 QStringList rampTypeNames;
347 rampTypeNames.reserve( rampTypes.size() );
348 if ( mShowGradientOnly )
349 {
350 rampTypes.erase( std::remove_if( rampTypes.begin(), rampTypes.end(), []( const QPair<QString, QString> &type ) {
351 return type.first != QgsGradientColorRamp::typeString() && type.first != QgsCptCityColorRamp::typeString();
352 } ),
353 rampTypes.end() );
354 }
355
356 for ( const QPair<QString, QString> &type : rampTypes )
357 rampTypeNames << type.second;
358
359 const QString selectedRampTypeName = QInputDialog::getItem( this, tr( "Color ramp type" ), tr( "Please select color ramp type:" ), rampTypeNames, 0, false, &ok );
360
361 if ( !ok || selectedRampTypeName.isEmpty() )
362 return;
363
364 const QString rampType = rampTypes.value( rampTypeNames.indexOf( selectedRampTypeName ) ).first;
365
366 QgsColorRamp *ramp = nullptr;
367 if ( rampType == QgsGradientColorRamp::typeString() )
368 {
369 ramp = new QgsGradientColorRamp();
370 }
371 else if ( rampType == QgsLimitedRandomColorRamp::typeString() )
372 {
373 ramp = new QgsLimitedRandomColorRamp();
374 }
375 else if ( rampType == QgsColorBrewerColorRamp::typeString() )
376 {
377 ramp = new QgsColorBrewerColorRamp();
378 }
379 else if ( rampType == QgsPresetSchemeColorRamp::typeString() )
380 {
381 ramp = new QgsPresetSchemeColorRamp();
382 }
383 else if ( rampType == QgsCptCityColorRamp::typeString() )
384 {
385 ramp = new QgsCptCityColorRamp( QString(), QString() );
386 }
387 else
388 {
389 QgsDebugError( "invalid ramp type " + rampType );
390 return;
391 }
392
393 setColorRamp( ramp );
394 delete ramp;
395
396 showColorRampDialog();
397}
398
399void QgsColorRampButton::saveColorRamp()
400{
401 QgsStyleSaveDialog saveDlg( this, QgsStyle::ColorrampEntity );
402 if ( !saveDlg.exec() || saveDlg.name().isEmpty() )
403 {
404 return;
405 }
406
407 QgsStyle *destinationStyle = saveDlg.destinationStyle();
408
409 // check if there is no symbol with same name
410 if ( destinationStyle->symbolNames().contains( saveDlg.name() ) )
411 {
412 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 );
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
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, this );
525 //make sure height of icon looks good under different platforms
526#ifdef Q_OS_WIN
527 mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
528#else
529 mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
530#endif
531 }
532 currentIconSize = mIconSize;
533 }
534 else
535 {
536 //no menu
537#ifdef Q_OS_WIN
538 currentIconSize = QSize( width() - 10, height() - 6 );
539#else
540 currentIconSize = QSize( width() - 10, height() - 12 );
541#endif
542 }
543
544 if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
545 {
546 return;
547 }
548
549 QPixmap pm;
550 if ( isRandomColorRamp() )
551 {
552 //create a "random colors" label
553 pm = QPixmap( currentIconSize );
554 pm.fill( Qt::transparent );
555
556 QPainter painter;
557 const QPen pen = ( palette().buttonText().color() );
558
559 painter.begin( &pm );
560 painter.setPen( pen );
561 painter.drawText( QRect( 0, 0, currentIconSize.width(), currentIconSize.height() ), Qt::AlignCenter, u"Random colors"_s );
562 painter.end();
563 }
564 else
565 {
566 //create an icon pixmap
567 if ( backgroundColorRamp )
568 {
569 pm = QgsSymbolLayerUtils::colorRampPreviewPixmap( backgroundColorRamp, currentIconSize );
570 }
571 }
572
573 setIconSize( currentIconSize );
574 setIcon( pm );
575}
576
578{
579 return mColorRamp ? mColorRamp->clone() : nullptr;
580}
581
583{
584 mColorRampDialogTitle = title;
585}
586
588{
589 return mColorRampDialogTitle;
590}
591
593{
594 setMenu( showMenu ? mMenu : nullptr );
595 setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
596 //force recalculation of icon size
597 mIconSize = QSize();
598 setButtonBackground( mColorRamp.get() );
599}
600
602{
603 return menu() ? true : false;
604}
605
607{
608 mDefaultColorRamp.reset( colorramp ? colorramp->clone() : nullptr );
609}
610
612{
613 return mDefaultColorRamp ? mDefaultColorRamp->clone() : nullptr;
614}
615
617{
618 return dynamic_cast<QgsRandomColorRamp *>( mColorRamp.get() );
619}
620
622{
623 mShowNull = showNull;
624}
625
627{
628 return mShowNull;
629}
630
632{
633 return !mColorRamp;
634}
635
636void QgsColorRampButton::rampWidgetUpdated()
637{
638 QgsLimitedRandomColorRampWidget *limitedRampWidget = qobject_cast<QgsLimitedRandomColorRampWidget *>( sender() );
639 if ( limitedRampWidget )
640 {
641 setColorRamp( limitedRampWidget->ramp().clone() );
642 emit colorRampChanged();
643 return;
644 }
645 QgsColorBrewerColorRampWidget *colorBrewerRampWidget = qobject_cast<QgsColorBrewerColorRampWidget *>( sender() );
646 if ( colorBrewerRampWidget )
647 {
648 setColorRamp( colorBrewerRampWidget->ramp().clone() );
649 emit colorRampChanged();
650 return;
651 }
652 QgsPresetColorRampWidget *presetRampWidget = qobject_cast<QgsPresetColorRampWidget *>( sender() );
653 if ( presetRampWidget )
654 {
655 setColorRamp( presetRampWidget->ramp().clone() );
656 emit colorRampChanged();
657 return;
658 }
659}
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition qgis.h:6499
void changed()
Emitted when the dialog settings change.
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.
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 widget which allows users to modify the properties of a QgsLimitedRandomColorRamp.
void changed()
Emitted when the dialog settings change.
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 an 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 ...
bool dockMode() const
Returns the dock mode state.
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.
QgsPresetSchemeColorRamp ramp
void changed()
Emitted when the dialog settings change.
static QString typeString()
Returns the string identifier for QgsPresetSchemeColorRamp.
QgsPresetSchemeColorRamp * clone() const override
Creates a clone of the color ramp.
A color ramp consisting of random colors, constrained within component ranges.
bool addColorRamp(const QString &name, QgsColorRamp *colorRamp, bool update=false)
Adds a color ramp to the style.
Definition qgsstyle.cpp:348
@ ColorrampEntity
Color ramps.
Definition qgsstyle.h:208
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:150
bool saveColorRamp(const QString &name, const QgsColorRamp *ramp, bool favorite, const QStringList &tags)
Adds the colorramp to the database.
Definition qgsstyle.cpp:461
bool removeColorRamp(const QString &name)
Removes color ramp from style (and delete it).
Definition qgsstyle.cpp:494
QStringList symbolNames() const
Returns a list of names of symbols.
Definition qgsstyle.cpp:342
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:59