QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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
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 {
349 return type.first != QgsGradientColorRamp::typeString() && type.first != QgsCptCityColorRamp::typeString();
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" ),
357 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{
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" ),
411 tr( "Color ramp with name '%1' already exists. Overwrite?" )
412 .arg( saveDlg.name() ),
413 QMessageBox::Yes | QMessageBox::No );
414 if ( res != QMessageBox::Yes )
415 {
416 return;
417 }
418 destinationStyle->removeColorRamp( saveDlg.name() );
419 }
420
421 const QStringList colorRampTags = saveDlg.tags().split( ',' );
422
423 // add new symbol to style and re-populate the list
424 QgsColorRamp *ramp = colorRamp();
425 destinationStyle->addColorRamp( saveDlg.name(), ramp );
426 destinationStyle->saveColorRamp( saveDlg.name(), ramp, saveDlg.isFavorite(), colorRampTags );
427
428 setColorRampName( saveDlg.name() );
429}
430
431void QgsColorRampButton::invertColorRamp()
432{
433 mColorRamp->invert();
435 emit colorRampChanged();
436}
437
439{
440 if ( e->type() == QEvent::EnabledChange )
441 {
443 }
444 QToolButton::changeEvent( e );
445}
446
447#if 0 // causes too many cyclical updates, but may be needed on some platforms
448void QgsColorRampButton::paintEvent( QPaintEvent *e )
449{
450 QToolButton::paintEvent( e );
451
452 if ( !mBackgroundSet )
453 {
455 }
456}
457#endif
458
459void QgsColorRampButton::showEvent( QShowEvent *e )
460{
462 QToolButton::showEvent( e );
463}
464
465void QgsColorRampButton::resizeEvent( QResizeEvent *event )
466{
467 QToolButton::resizeEvent( event );
468 //recalculate icon size and redraw icon
469 mIconSize = QSize();
470 setButtonBackground( mColorRamp.get() );
471}
472
474{
475 if ( colorramp == mColorRamp.get() )
476 return;
477
478 mColorRamp.reset( colorramp ? colorramp->clone() : nullptr );
479
481 if ( isEnabled() )
482 {
483 emit colorRampChanged();
484 }
485}
486
488{
489 if ( !name.isEmpty() )
490 {
491 const std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
492 if ( ramp )
493 {
494 setColorRamp( ramp.get() );
495 }
496 }
497}
498
500{
501 if ( !isRandomColorRamp() )
502 {
503 const std::unique_ptr< QgsRandomColorRamp > newRamp( new QgsRandomColorRamp() );
504 setColorRamp( newRamp.get() );
505 }
506}
507
509{
510 QgsColorRamp *backgroundColorRamp = colorramp;
511 if ( !colorramp )
512 {
513 backgroundColorRamp = mColorRamp.get();
514 }
515
516 QSize currentIconSize;
517 //icon size is button size with a small margin
518 if ( menu() )
519 {
520 if ( !mIconSize.isValid() )
521 {
522 //calculate size of push button part of widget (ie, without the menu drop-down button part)
523 QStyleOptionToolButton opt;
524 initStyleOption( &opt );
525 const QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
526 this );
527 //make sure height of icon looks good under different platforms
528#ifdef Q_OS_WIN
529 mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
530#else
531 mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
532#endif
533 }
534 currentIconSize = mIconSize;
535 }
536 else
537 {
538 //no menu
539#ifdef Q_OS_WIN
540 currentIconSize = QSize( width() - 10, height() - 6 );
541#else
542 currentIconSize = QSize( width() - 10, height() - 12 );
543#endif
544 }
545
546 if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
547 {
548 return;
549 }
550
551 QPixmap pm;
552 if ( isRandomColorRamp() )
553 {
554 //create a "random colors" label
555 pm = QPixmap( currentIconSize );
556 pm.fill( Qt::transparent );
557
558 QPainter painter;
559 const QPen pen = ( palette().buttonText().color() );
560
561 painter.begin( &pm );
562 painter.setPen( pen );
563 painter.drawText( QRect( 0, 0, currentIconSize.width(), currentIconSize.height() ), Qt::AlignCenter, QStringLiteral( "Random colors" ) );
564 painter.end();
565 }
566 else
567 {
568 //create an icon pixmap
569 if ( backgroundColorRamp )
570 {
571 pm = QgsSymbolLayerUtils::colorRampPreviewPixmap( backgroundColorRamp, currentIconSize );
572 }
573 }
574
575 setIconSize( currentIconSize );
576 setIcon( pm );
577}
578
580{
581 return mColorRamp ? mColorRamp->clone() : nullptr;
582}
583
585{
586 mColorRampDialogTitle = title;
587}
588
590{
591 return mColorRampDialogTitle;
592}
593
594void QgsColorRampButton::setShowMenu( const bool showMenu )
595{
596 setMenu( showMenu ? mMenu : nullptr );
597 setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
598 //force recalculation of icon size
599 mIconSize = QSize();
600 setButtonBackground( mColorRamp.get() );
601}
602
604{
605 return menu() ? true : false;
606}
607
609{
610 mDefaultColorRamp.reset( colorramp ? colorramp->clone() : nullptr );
611}
612
614{
615 return mDefaultColorRamp ? mDefaultColorRamp->clone() : nullptr;
616}
617
619{
620 return dynamic_cast<QgsRandomColorRamp *>( mColorRamp.get() );
621}
622
624{
625 mShowNull = showNull;
626}
627
629{
630 return mShowNull;
631}
632
634{
635 return !mColorRamp;
636}
637
638void QgsColorRampButton::rampWidgetUpdated()
639{
640 QgsLimitedRandomColorRampWidget *limitedRampWidget = qobject_cast< QgsLimitedRandomColorRampWidget * >( sender() );
641 if ( limitedRampWidget )
642 {
643 setColorRamp( limitedRampWidget->ramp().clone() );
644 emit colorRampChanged();
645 return;
646 }
647 QgsColorBrewerColorRampWidget *colorBrewerRampWidget = qobject_cast< QgsColorBrewerColorRampWidget * >( sender() );
648 if ( colorBrewerRampWidget )
649 {
650 setColorRamp( colorBrewerRampWidget->ramp().clone() );
651 emit colorRampChanged();
652 return;
653 }
654 QgsPresetColorRampWidget *presetRampWidget = qobject_cast< QgsPresetColorRampWidget * >( sender() );
655 if ( presetRampWidget )
656 {
657 setColorRamp( presetRampWidget->ramp().clone() );
658 emit colorRampChanged();
659 return;
660 }
661}
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition qgis.h:5667
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