QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
38#include "moc_qgscolorrampbutton.cpp"
39
40QgsColorRampButton::QgsColorRampButton( QWidget *parent, const QString &dialogTitle )
41 : QToolButton( parent )
42 , mColorRampDialogTitle( dialogTitle.isEmpty() ? tr( "Select Color Ramp" ) : dialogTitle )
43{
44 setAcceptDrops( true );
45 setMinimumSize( QSize( 24, 16 ) );
46 connect( this, &QPushButton::clicked, this, &QgsColorRampButton::buttonClicked );
47
48 //setup drop-down menu
49 mMenu = new QMenu( this );
50 connect( mMenu, &QMenu::aboutToShow, this, &QgsColorRampButton::prepareMenu );
51 setMenu( mMenu );
52
53 mAllRampsMenu = new QMenu( mMenu );
54 mAllRampsMenu->setTitle( tr( "All Color Ramps" ) );
55
56 setPopupMode( QToolButton::MenuButtonPopup );
57
58 mStyle = QgsStyle::defaultStyle();
59}
60
62
64{
65 //make sure height of button looks good under different platforms
66#ifdef Q_OS_WIN
67 return QSize( 120, static_cast<int>( std::max( Qgis::UI_SCALE_FACTOR * fontMetrics().height(), 22.0 ) ) );
68#else
69 // Adjust height for HiDPI screens
70 return QSize( 120, static_cast<int>( std::max( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.4, 28.0 ) ) );
71#endif
72}
73
74void QgsColorRampButton::showColorRampDialog()
75{
77 const bool panelMode = panel && panel->dockMode();
78
79 std::unique_ptr<QgsColorRamp> currentRamp( colorRamp() );
80 if ( !currentRamp )
81 return;
82
83 setColorRampName( QString() );
84
85 if ( currentRamp->type() == QgsGradientColorRamp::typeString() )
86 {
87 QgsGradientColorRamp *gradRamp = static_cast<QgsGradientColorRamp *>( currentRamp.get() );
88 QgsGradientColorRampDialog dlg( *gradRamp, this );
89 dlg.setWindowTitle( mColorRampDialogTitle );
90 if ( dlg.exec() )
91 {
92 setColorRamp( dlg.ramp().clone() );
93 }
94 }
95 else if ( currentRamp->type() == QgsLimitedRandomColorRamp::typeString() )
96 {
97 QgsLimitedRandomColorRamp *randRamp = static_cast<QgsLimitedRandomColorRamp *>( currentRamp.get() );
98 if ( panelMode )
99 {
100 QgsLimitedRandomColorRampWidget *widget = new QgsLimitedRandomColorRampWidget( *randRamp, this );
101 widget->setPanelTitle( tr( "Edit Ramp" ) );
102 connect( widget, &QgsLimitedRandomColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated );
103 panel->openPanel( widget );
104 }
105 else
106 {
107 QgsLimitedRandomColorRampDialog dlg( *randRamp, this );
108 if ( dlg.exec() )
109 {
110 setColorRamp( dlg.ramp().clone() );
111 }
112 }
113 }
114 else if ( currentRamp->type() == QgsPresetSchemeColorRamp::typeString() )
115 {
116 QgsPresetSchemeColorRamp *presetRamp = static_cast<QgsPresetSchemeColorRamp *>( currentRamp.get() );
117 if ( panelMode )
118 {
119 QgsPresetColorRampWidget *widget = new QgsPresetColorRampWidget( *presetRamp, this );
120 widget->setPanelTitle( tr( "Edit Ramp" ) );
121 connect( widget, &QgsPresetColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated );
122 panel->openPanel( widget );
123 }
124 else
125 {
126 QgsPresetColorRampDialog dlg( *presetRamp, this );
127 if ( dlg.exec() )
128 {
129 setColorRamp( dlg.ramp().clone() );
130 }
131 }
132 }
133 else if ( currentRamp->type() == QgsColorBrewerColorRamp::typeString() )
134 {
135 QgsColorBrewerColorRamp *brewerRamp = static_cast<QgsColorBrewerColorRamp *>( currentRamp.get() );
136 if ( panelMode )
137 {
138 QgsColorBrewerColorRampWidget *widget = new QgsColorBrewerColorRampWidget( *brewerRamp, this );
139 widget->setPanelTitle( tr( "Edit Ramp" ) );
140 connect( widget, &QgsColorBrewerColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated );
141 panel->openPanel( widget );
142 }
143 else
144 {
145 QgsColorBrewerColorRampDialog dlg( *brewerRamp, this );
146 if ( dlg.exec() )
147 {
148 setColorRamp( dlg.ramp().clone() );
149 }
150 }
151 }
152 else if ( currentRamp->type() == QgsCptCityColorRamp::typeString() )
153 {
154 QgsCptCityColorRamp *cptCityRamp = static_cast<QgsCptCityColorRamp *>( currentRamp.get() );
155 QgsCptCityColorRampDialog dlg( *cptCityRamp, this );
156 if ( dlg.exec() )
157 {
158 if ( dlg.saveAsGradientRamp() )
159 {
160 setColorRamp( dlg.ramp().cloneGradientRamp() );
161 }
162 else
163 {
164 setColorRamp( dlg.ramp().clone() );
165 }
166 }
167 }
168}
169
171{
172 if ( !mDefaultColorRamp )
173 {
174 return;
175 }
176
177 setColorRamp( mDefaultColorRamp.get() );
178}
179
181{
182 setColorRamp( nullptr );
183}
184
186{
187 if ( e->type() == QEvent::ToolTip )
188 {
189 if ( !colorRampName().isEmpty() )
190 {
191 setToolTip( colorRampName() );
192 }
193 }
194 return QToolButton::event( e );
195}
196
198{
199 if ( e->button() == Qt::RightButton )
200 {
201 QToolButton::showMenu();
202 return;
203 }
204 QToolButton::mousePressEvent( e );
205}
206
207QPixmap QgsColorRampButton::createMenuIcon( QgsColorRamp *colorramp )
208{
209 //create an icon pixmap
210 const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
211 const QPixmap pixmap = QgsSymbolLayerUtils::colorRampPreviewPixmap( colorramp, QSize( iconSize, iconSize ) );
212 return pixmap;
213}
214
215void QgsColorRampButton::buttonClicked()
216{
217 if ( !isRandomColorRamp() && !isNull() )
218 {
219 showColorRampDialog();
220 }
221 else
222 {
223 QToolButton::showMenu();
224 }
225}
226
227void QgsColorRampButton::prepareMenu()
228{
229 mMenu->clear();
230
231 QAction *invertAction = new QAction( tr( "Invert Color Ramp" ), this );
232 invertAction->setEnabled( !isNull() && !isRandomColorRamp() );
233 mMenu->addAction( invertAction );
234 connect( invertAction, &QAction::triggered, this, &QgsColorRampButton::invertColorRamp );
235
236 if ( mShowNull )
237 {
238 QAction *nullAction = new QAction( tr( "Clear Current Ramp" ), this );
239 nullAction->setEnabled( !isNull() );
240 mMenu->addAction( nullAction );
241 connect( nullAction, &QAction::triggered, this, &QgsColorRampButton::setToNull );
242 }
243
244 mMenu->addSeparator();
245
246 //show default color option if set
247 if ( mDefaultColorRamp )
248 {
249 QAction *defaultColorRampAction = new QAction( tr( "Default Color Ramp" ), this );
250 defaultColorRampAction->setIcon( createMenuIcon( mDefaultColorRamp.get() ) );
251 mMenu->addAction( defaultColorRampAction );
252 connect( defaultColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setToDefaultColorRamp );
253 }
254
255 if ( mShowRandomColorRamp )
256 {
257 QAction *randomColorRampAction = new QAction( tr( "Random Color Ramp" ), this );
258 randomColorRampAction->setCheckable( true );
259 randomColorRampAction->setChecked( isRandomColorRamp() );
260 mMenu->addAction( randomColorRampAction );
261 connect( randomColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setRandomColorRamp );
262
263 if ( isRandomColorRamp() || dynamic_cast<QgsLimitedRandomColorRamp *>( mColorRamp.get() ) )
264 {
265 QAction *shuffleRandomColorRampAction = new QAction( tr( "Shuffle Random Colors" ), this );
266 mMenu->addAction( shuffleRandomColorRampAction );
267 connect( shuffleRandomColorRampAction, &QAction::triggered, this, &QgsColorRampButton::colorRampChanged );
268 }
269 }
270
271 mMenu->addSeparator();
272
273 QStringList rampNames = mStyle->symbolsOfFavorite( QgsStyle::ColorrampEntity );
274 rampNames.sort();
275 const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
276 for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
277 {
278 std::unique_ptr<QgsColorRamp> ramp( mStyle->colorRamp( *it ) );
279
280 if ( !mShowGradientOnly || ( ramp->type() == QgsGradientColorRamp::typeString() || ramp->type() == QgsCptCityColorRamp::typeString() ) )
281 {
282 const QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( iconSize, iconSize ) );
283 QAction *ra = new QAction( *it, this );
284 ra->setIcon( icon );
285 connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
286 mMenu->addAction( ra );
287 }
288 }
289
290 mMenu->addSeparator();
291
292 mAllRampsMenu->clear();
293 mMenu->addMenu( mAllRampsMenu );
294 rampNames = mStyle->colorRampNames();
295 rampNames.sort();
296 for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
297 {
298 std::unique_ptr<QgsColorRamp> ramp( mStyle->colorRamp( *it ) );
299
300 if ( !mShowGradientOnly || ( ramp->type() == QgsGradientColorRamp::typeString() || ramp->type() == QgsCptCityColorRamp::typeString() ) )
301 {
302 const QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), QSize( iconSize, iconSize ) );
303 QAction *ra = new QAction( *it, this );
304 ra->setIcon( icon );
305 connect( ra, &QAction::triggered, this, &QgsColorRampButton::loadColorRamp );
306 mAllRampsMenu->addAction( ra );
307 }
308 }
309
310 mMenu->addSeparator();
311
312 QAction *newColorRampAction = new QAction( tr( "Create New Color Ramp…" ), this );
313 connect( newColorRampAction, &QAction::triggered, this, &QgsColorRampButton::createColorRamp );
314 mMenu->addAction( newColorRampAction );
315
316 QAction *editColorRampAction = new QAction( tr( "Edit Color Ramp…" ), this );
317 editColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
318 connect( editColorRampAction, &QAction::triggered, this, &QgsColorRampButton::showColorRampDialog );
319 mMenu->addAction( editColorRampAction );
320
321 QAction *saveColorRampAction = new QAction( tr( "Save Color Ramp…" ), this );
322 saveColorRampAction->setEnabled( !isNull() && !isRandomColorRamp() );
323 connect( saveColorRampAction, &QAction::triggered, this, &QgsColorRampButton::saveColorRamp );
324 mMenu->addAction( saveColorRampAction );
325}
326
327void QgsColorRampButton::loadColorRamp()
328{
329 QAction *selectedItem = qobject_cast<QAction *>( sender() );
330 if ( selectedItem )
331 {
332 const QString name = selectedItem->iconText();
333 setColorRampName( name );
334 setColorRampFromName( name );
335 }
336}
337
338void QgsColorRampButton::createColorRamp()
339{
340 bool ok = true;
341
342 QList<QPair<QString, QString>> rampTypes = QgsColorRamp::rampTypes();
343 QStringList rampTypeNames;
344 rampTypeNames.reserve( rampTypes.size() );
345 if ( mShowGradientOnly )
346 {
347 rampTypes.erase( std::remove_if( rampTypes.begin(), rampTypes.end(), []( const QPair<QString, QString> &type ) {
348 return type.first != QgsGradientColorRamp::typeString() && type.first != QgsCptCityColorRamp::typeString();
349 } ),
350 rampTypes.end() );
351 }
352
353 for ( const QPair<QString, QString> &type : rampTypes )
354 rampTypeNames << type.second;
355
356 const QString selectedRampTypeName = QInputDialog::getItem( this, tr( "Color ramp type" ), 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{
398 QgsStyleSaveDialog saveDlg( this, QgsStyle::ColorrampEntity );
399 if ( !saveDlg.exec() || saveDlg.name().isEmpty() )
400 {
401 return;
402 }
403
404 QgsStyle *destinationStyle = saveDlg.destinationStyle();
405
406 // check if there is no symbol with same name
407 if ( destinationStyle->symbolNames().contains( saveDlg.name() ) )
408 {
409 const int res = QMessageBox::warning( this, tr( "Save Color Ramp" ), tr( "Color ramp with name '%1' already exists. Overwrite?" ).arg( saveDlg.name() ), QMessageBox::Yes | QMessageBox::No );
410 if ( res != QMessageBox::Yes )
411 {
412 return;
413 }
414 destinationStyle->removeColorRamp( saveDlg.name() );
415 }
416
417 const QStringList colorRampTags = saveDlg.tags().split( ',' );
418
419 // add new symbol to style and re-populate the list
420 QgsColorRamp *ramp = colorRamp();
421 destinationStyle->addColorRamp( saveDlg.name(), ramp );
422 destinationStyle->saveColorRamp( saveDlg.name(), ramp, saveDlg.isFavorite(), colorRampTags );
423
424 setColorRampName( saveDlg.name() );
425}
426
427void QgsColorRampButton::invertColorRamp()
428{
429 mColorRamp->invert();
431 emit colorRampChanged();
432}
433
435{
436 if ( e->type() == QEvent::EnabledChange )
437 {
439 }
440 QToolButton::changeEvent( e );
441}
442
443#if 0 // causes too many cyclical updates, but may be needed on some platforms
444void QgsColorRampButton::paintEvent( QPaintEvent *e )
445{
446 QToolButton::paintEvent( e );
447
448 if ( !mBackgroundSet )
449 {
451 }
452}
453#endif
454
455void QgsColorRampButton::showEvent( QShowEvent *e )
456{
458 QToolButton::showEvent( e );
459}
460
462{
463 QToolButton::resizeEvent( event );
464 //recalculate icon size and redraw icon
465 mIconSize = QSize();
466 setButtonBackground( mColorRamp.get() );
467}
468
470{
471 if ( colorramp == mColorRamp.get() )
472 return;
473
474 mColorRamp.reset( colorramp ? colorramp->clone() : nullptr );
475
477 if ( isEnabled() )
478 {
479 emit colorRampChanged();
480 }
481}
482
484{
485 if ( !name.isEmpty() )
486 {
487 const std::unique_ptr<QgsColorRamp> ramp( mStyle->colorRamp( name ) );
488 if ( ramp )
489 {
490 setColorRamp( ramp.get() );
491 }
492 }
493}
494
496{
497 if ( !isRandomColorRamp() )
498 {
499 const std::unique_ptr<QgsRandomColorRamp> newRamp( new QgsRandomColorRamp() );
500 setColorRamp( newRamp.get() );
501 }
502}
503
505{
506 QgsColorRamp *backgroundColorRamp = colorramp;
507 if ( !colorramp )
508 {
509 backgroundColorRamp = mColorRamp.get();
510 }
511
512 QSize currentIconSize;
513 //icon size is button size with a small margin
514 if ( menu() )
515 {
516 if ( !mIconSize.isValid() )
517 {
518 //calculate size of push button part of widget (ie, without the menu drop-down button part)
519 QStyleOptionToolButton opt;
520 initStyleOption( &opt );
521 const QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton, this );
522 //make sure height of icon looks good under different platforms
523#ifdef Q_OS_WIN
524 mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
525#else
526 mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
527#endif
528 }
529 currentIconSize = mIconSize;
530 }
531 else
532 {
533 //no menu
534#ifdef Q_OS_WIN
535 currentIconSize = QSize( width() - 10, height() - 6 );
536#else
537 currentIconSize = QSize( width() - 10, height() - 12 );
538#endif
539 }
540
541 if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
542 {
543 return;
544 }
545
546 QPixmap pm;
547 if ( isRandomColorRamp() )
548 {
549 //create a "random colors" label
550 pm = QPixmap( currentIconSize );
551 pm.fill( Qt::transparent );
552
553 QPainter painter;
554 const QPen pen = ( palette().buttonText().color() );
555
556 painter.begin( &pm );
557 painter.setPen( pen );
558 painter.drawText( QRect( 0, 0, currentIconSize.width(), currentIconSize.height() ), Qt::AlignCenter, QStringLiteral( "Random colors" ) );
559 painter.end();
560 }
561 else
562 {
563 //create an icon pixmap
564 if ( backgroundColorRamp )
565 {
566 pm = QgsSymbolLayerUtils::colorRampPreviewPixmap( backgroundColorRamp, currentIconSize );
567 }
568 }
569
570 setIconSize( currentIconSize );
571 setIcon( pm );
572}
573
575{
576 return mColorRamp ? mColorRamp->clone() : nullptr;
577}
578
580{
581 mColorRampDialogTitle = title;
582}
583
585{
586 return mColorRampDialogTitle;
587}
588
590{
591 setMenu( showMenu ? mMenu : nullptr );
592 setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
593 //force recalculation of icon size
594 mIconSize = QSize();
595 setButtonBackground( mColorRamp.get() );
596}
597
599{
600 return menu() ? true : false;
601}
602
604{
605 mDefaultColorRamp.reset( colorramp ? colorramp->clone() : nullptr );
606}
607
609{
610 return mDefaultColorRamp ? mDefaultColorRamp->clone() : nullptr;
611}
612
614{
615 return dynamic_cast<QgsRandomColorRamp *>( mColorRamp.get() );
616}
617
619{
620 mShowNull = showNull;
621}
622
624{
625 return mShowNull;
626}
627
629{
630 return !mColorRamp;
631}
632
633void QgsColorRampButton::rampWidgetUpdated()
634{
635 QgsLimitedRandomColorRampWidget *limitedRampWidget = qobject_cast<QgsLimitedRandomColorRampWidget *>( sender() );
636 if ( limitedRampWidget )
637 {
638 setColorRamp( limitedRampWidget->ramp().clone() );
639 emit colorRampChanged();
640 return;
641 }
642 QgsColorBrewerColorRampWidget *colorBrewerRampWidget = qobject_cast<QgsColorBrewerColorRampWidget *>( sender() );
643 if ( colorBrewerRampWidget )
644 {
645 setColorRamp( colorBrewerRampWidget->ramp().clone() );
646 emit colorRampChanged();
647 return;
648 }
649 QgsPresetColorRampWidget *presetRampWidget = qobject_cast<QgsPresetColorRampWidget *>( sender() );
650 if ( presetRampWidget )
651 {
652 setColorRamp( presetRampWidget->ramp().clone() );
653 emit colorRampChanged();
654 return;
655 }
656}
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition qgis.h:6222
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:207
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:147
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:497
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:57