QGIS API Documentation 4.3.0-Master (91d4a333d5d)
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
200void QgsColorRampButton::contextMenuEvent( QContextMenuEvent *e )
201{
202 QToolButton::showMenu();
203 e->accept();
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(
347 std::remove_if(
348 rampTypes.begin(), rampTypes.end(), []( const QPair<QString, QString> &type ) { return type.first != QgsGradientColorRamp::typeString() && type.first != QgsCptCityColorRamp::typeString(); }
349 ),
350 rampTypes.end()
351 );
352 }
353
354 for ( const QPair<QString, QString> &type : rampTypes )
355 rampTypeNames << type.second;
356
357 const QString selectedRampTypeName = QInputDialog::getItem( this, tr( "Color ramp type" ), tr( "Please select color ramp type:" ), rampTypeNames, 0, false, &ok );
358
359 if ( !ok || selectedRampTypeName.isEmpty() )
360 return;
361
362 const QString rampType = rampTypes.value( rampTypeNames.indexOf( selectedRampTypeName ) ).first;
363
364 QgsColorRamp *ramp = nullptr;
365 if ( rampType == QgsGradientColorRamp::typeString() )
366 {
367 ramp = new QgsGradientColorRamp();
368 }
369 else if ( rampType == QgsLimitedRandomColorRamp::typeString() )
370 {
371 ramp = new QgsLimitedRandomColorRamp();
372 }
373 else if ( rampType == QgsColorBrewerColorRamp::typeString() )
374 {
375 ramp = new QgsColorBrewerColorRamp();
376 }
377 else if ( rampType == QgsPresetSchemeColorRamp::typeString() )
378 {
379 ramp = new QgsPresetSchemeColorRamp();
380 }
381 else if ( rampType == QgsCptCityColorRamp::typeString() )
382 {
383 ramp = new QgsCptCityColorRamp( QString(), QString() );
384 }
385 else
386 {
387 QgsDebugError( "invalid ramp type " + rampType );
388 return;
389 }
390
391 setColorRamp( ramp );
392 delete ramp;
393
394 showColorRampDialog();
395}
396
397void QgsColorRampButton::saveColorRamp()
398{
399 QgsStyleSaveDialog saveDlg( this, QgsStyle::ColorrampEntity );
400 if ( !saveDlg.exec() || saveDlg.name().isEmpty() )
401 {
402 return;
403 }
404
405 QgsStyle *destinationStyle = saveDlg.destinationStyle();
406
407 // check if there is no symbol with same name
408 if ( destinationStyle->symbolNames().contains( saveDlg.name() ) )
409 {
410 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 );
411 if ( res != QMessageBox::Yes )
412 {
413 return;
414 }
415 destinationStyle->removeColorRamp( saveDlg.name() );
416 }
417
418 const QStringList colorRampTags = saveDlg.tags().split( ',' );
419
420 // add new symbol to style and re-populate the list
421 QgsColorRamp *ramp = colorRamp();
422 destinationStyle->addColorRamp( saveDlg.name(), ramp );
423 destinationStyle->saveColorRamp( saveDlg.name(), ramp, saveDlg.isFavorite(), colorRampTags );
424
425 setColorRampName( saveDlg.name() );
426}
427
428void QgsColorRampButton::invertColorRamp()
429{
430 mColorRamp->invert();
432 emit colorRampChanged();
433}
434
436{
437 if ( e->type() == QEvent::EnabledChange )
438 {
440 }
441 QToolButton::changeEvent( e );
442}
443
444#if 0 // causes too many cyclical updates, but may be needed on some platforms
445void QgsColorRampButton::paintEvent( QPaintEvent *e )
446{
447 QToolButton::paintEvent( e );
448
449 if ( !mBackgroundSet )
450 {
452 }
453}
454#endif
455
456void QgsColorRampButton::showEvent( QShowEvent *e )
457{
459 QToolButton::showEvent( e );
460}
461
463{
464 QToolButton::resizeEvent( event );
465 //recalculate icon size and redraw icon
466 mIconSize = QSize();
467 setButtonBackground( mColorRamp.get() );
468}
469
471{
472 if ( colorramp == mColorRamp.get() )
473 return;
474
475 mColorRamp.reset( colorramp ? colorramp->clone() : nullptr );
476
478 if ( isEnabled() )
479 {
480 emit colorRampChanged();
481 }
482}
483
485{
486 if ( !name.isEmpty() )
487 {
488 const std::unique_ptr<QgsColorRamp> ramp( mStyle->colorRamp( name ) );
489 if ( ramp )
490 {
491 setColorRamp( ramp.get() );
492 }
493 }
494}
495
497{
498 if ( !isRandomColorRamp() )
499 {
500 const std::unique_ptr<QgsRandomColorRamp> newRamp( new QgsRandomColorRamp() );
501 setColorRamp( newRamp.get() );
502 }
503}
504
506{
507 QgsColorRamp *backgroundColorRamp = colorramp;
508 if ( !colorramp )
509 {
510 backgroundColorRamp = mColorRamp.get();
511 }
512
513 QSize currentIconSize;
514 //icon size is button size with a small margin
515 if ( menu() )
516 {
517 if ( !mIconSize.isValid() )
518 {
519 //calculate size of push button part of widget (ie, without the menu drop-down button part)
520 QStyleOptionToolButton opt;
521 initStyleOption( &opt );
522 const QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton, this );
523 //make sure height of icon looks good under different platforms
524#ifdef Q_OS_WIN
525 mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
526#else
527 mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
528#endif
529 }
530 currentIconSize = mIconSize;
531 }
532 else
533 {
534 //no menu
535#ifdef Q_OS_WIN
536 currentIconSize = QSize( width() - 10, height() - 6 );
537#else
538 currentIconSize = QSize( width() - 10, height() - 12 );
539#endif
540 }
541
542 if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
543 {
544 return;
545 }
546
547 QPixmap pm;
548 if ( isRandomColorRamp() )
549 {
550 //create a "random colors" label
551 pm = QPixmap( currentIconSize );
552 pm.fill( Qt::transparent );
553
554 QPainter painter;
555 const QPen pen = ( palette().buttonText().color() );
556
557 painter.begin( &pm );
558 painter.setPen( pen );
559 painter.drawText( QRect( 0, 0, currentIconSize.width(), currentIconSize.height() ), Qt::AlignCenter, u"Random colors"_s );
560 painter.end();
561 }
562 else
563 {
564 //create an icon pixmap
565 if ( backgroundColorRamp )
566 {
567 pm = QgsSymbolLayerUtils::colorRampPreviewPixmap( backgroundColorRamp, currentIconSize );
568 }
569 }
570
571 setIconSize( currentIconSize );
572 setIcon( pm );
573}
574
576{
577 return mColorRamp ? mColorRamp->clone() : nullptr;
578}
579
581{
582 mColorRampDialogTitle = title;
583}
584
586{
587 return mColorRampDialogTitle;
588}
589
591{
592 setMenu( showMenu ? mMenu : nullptr );
593 setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
594 //force recalculation of icon size
595 mIconSize = QSize();
596 setButtonBackground( mColorRamp.get() );
597}
598
600{
601 return menu() ? true : false;
602}
603
605{
606 mDefaultColorRamp.reset( colorramp ? colorramp->clone() : nullptr );
607}
608
610{
611 return mDefaultColorRamp ? mDefaultColorRamp->clone() : nullptr;
612}
613
615{
616 return dynamic_cast<QgsRandomColorRamp *>( mColorRamp.get() );
617}
618
620{
621 mShowNull = showNull;
622}
623
625{
626 return mShowNull;
627}
628
630{
631 return !mColorRamp;
632}
633
634void QgsColorRampButton::rampWidgetUpdated()
635{
636 QgsLimitedRandomColorRampWidget *limitedRampWidget = qobject_cast<QgsLimitedRandomColorRampWidget *>( sender() );
637 if ( limitedRampWidget )
638 {
639 setColorRamp( limitedRampWidget->ramp().clone() );
640 emit colorRampChanged();
641 return;
642 }
643 QgsColorBrewerColorRampWidget *colorBrewerRampWidget = qobject_cast<QgsColorBrewerColorRampWidget *>( sender() );
644 if ( colorBrewerRampWidget )
645 {
646 setColorRamp( colorBrewerRampWidget->ramp().clone() );
647 emit colorRampChanged();
648 return;
649 }
650 QgsPresetColorRampWidget *presetRampWidget = qobject_cast<QgsPresetColorRampWidget *>( sender() );
651 if ( presetRampWidget )
652 {
653 setColorRamp( presetRampWidget->ramp().clone() );
654 emit colorRampChanged();
655 return;
656 }
657}
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition qgis.h:7405
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.
void contextMenuEvent(QContextMenuEvent *e) override
bool isRandomColorRamp() const
Returns true if the current color ramp is random.
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.
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.
void changed()
Emitted when the widget state changes.
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
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:365
@ ColorrampEntity
Color ramps.
Definition qgsstyle.h:209
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:164
bool saveColorRamp(const QString &name, const QgsColorRamp *ramp, bool favorite, const QStringList &tags)
Adds the colorramp to the database.
Definition qgsstyle.cpp:500
bool removeColorRamp(const QString &name)
Removes color ramp from style (and delete it).
Definition qgsstyle.cpp:532
QStringList symbolNames() const
Returns a list of names of symbols.
Definition qgsstyle.cpp:360
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.
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:71