QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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(
351 std::remove_if(
352 rampTypes.begin(), rampTypes.end(), []( const QPair<QString, QString> &type ) { return type.first != QgsGradientColorRamp::typeString() && type.first != QgsCptCityColorRamp::typeString(); }
353 ),
354 rampTypes.end()
355 );
356 }
357
358 for ( const QPair<QString, QString> &type : rampTypes )
359 rampTypeNames << type.second;
360
361 const QString selectedRampTypeName = QInputDialog::getItem( this, tr( "Color ramp type" ), tr( "Please select color ramp type:" ), rampTypeNames, 0, false, &ok );
362
363 if ( !ok || selectedRampTypeName.isEmpty() )
364 return;
365
366 const QString rampType = rampTypes.value( rampTypeNames.indexOf( selectedRampTypeName ) ).first;
367
368 QgsColorRamp *ramp = nullptr;
369 if ( rampType == QgsGradientColorRamp::typeString() )
370 {
371 ramp = new QgsGradientColorRamp();
372 }
373 else if ( rampType == QgsLimitedRandomColorRamp::typeString() )
374 {
375 ramp = new QgsLimitedRandomColorRamp();
376 }
377 else if ( rampType == QgsColorBrewerColorRamp::typeString() )
378 {
379 ramp = new QgsColorBrewerColorRamp();
380 }
381 else if ( rampType == QgsPresetSchemeColorRamp::typeString() )
382 {
383 ramp = new QgsPresetSchemeColorRamp();
384 }
385 else if ( rampType == QgsCptCityColorRamp::typeString() )
386 {
387 ramp = new QgsCptCityColorRamp( QString(), QString() );
388 }
389 else
390 {
391 QgsDebugError( "invalid ramp type " + rampType );
392 return;
393 }
394
395 setColorRamp( ramp );
396 delete ramp;
397
398 showColorRampDialog();
399}
400
401void QgsColorRampButton::saveColorRamp()
402{
403 QgsStyleSaveDialog saveDlg( this, QgsStyle::ColorrampEntity );
404 if ( !saveDlg.exec() || saveDlg.name().isEmpty() )
405 {
406 return;
407 }
408
409 QgsStyle *destinationStyle = saveDlg.destinationStyle();
410
411 // check if there is no symbol with same name
412 if ( destinationStyle->symbolNames().contains( saveDlg.name() ) )
413 {
414 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 );
415 if ( res != QMessageBox::Yes )
416 {
417 return;
418 }
419 destinationStyle->removeColorRamp( saveDlg.name() );
420 }
421
422 const QStringList colorRampTags = saveDlg.tags().split( ',' );
423
424 // add new symbol to style and re-populate the list
425 QgsColorRamp *ramp = colorRamp();
426 destinationStyle->addColorRamp( saveDlg.name(), ramp );
427 destinationStyle->saveColorRamp( saveDlg.name(), ramp, saveDlg.isFavorite(), colorRampTags );
428
429 setColorRampName( saveDlg.name() );
430}
431
432void QgsColorRampButton::invertColorRamp()
433{
434 mColorRamp->invert();
436 emit colorRampChanged();
437}
438
440{
441 if ( e->type() == QEvent::EnabledChange )
442 {
444 }
445 QToolButton::changeEvent( e );
446}
447
448#if 0 // causes too many cyclical updates, but may be needed on some platforms
449void QgsColorRampButton::paintEvent( QPaintEvent *e )
450{
451 QToolButton::paintEvent( e );
452
453 if ( !mBackgroundSet )
454 {
456 }
457}
458#endif
459
460void QgsColorRampButton::showEvent( QShowEvent *e )
461{
463 QToolButton::showEvent( e );
464}
465
467{
468 QToolButton::resizeEvent( event );
469 //recalculate icon size and redraw icon
470 mIconSize = QSize();
471 setButtonBackground( mColorRamp.get() );
472}
473
475{
476 if ( colorramp == mColorRamp.get() )
477 return;
478
479 mColorRamp.reset( colorramp ? colorramp->clone() : nullptr );
480
482 if ( isEnabled() )
483 {
484 emit colorRampChanged();
485 }
486}
487
489{
490 if ( !name.isEmpty() )
491 {
492 const std::unique_ptr<QgsColorRamp> ramp( mStyle->colorRamp( name ) );
493 if ( ramp )
494 {
495 setColorRamp( ramp.get() );
496 }
497 }
498}
499
501{
502 if ( !isRandomColorRamp() )
503 {
504 const std::unique_ptr<QgsRandomColorRamp> newRamp( new QgsRandomColorRamp() );
505 setColorRamp( newRamp.get() );
506 }
507}
508
510{
511 QgsColorRamp *backgroundColorRamp = colorramp;
512 if ( !colorramp )
513 {
514 backgroundColorRamp = mColorRamp.get();
515 }
516
517 QSize currentIconSize;
518 //icon size is button size with a small margin
519 if ( menu() )
520 {
521 if ( !mIconSize.isValid() )
522 {
523 //calculate size of push button part of widget (ie, without the menu drop-down button part)
524 QStyleOptionToolButton opt;
525 initStyleOption( &opt );
526 const QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton, 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, u"Random colors"_s );
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
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:6591
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:345
@ ColorrampEntity
Color ramps.
Definition qgsstyle.h:207
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:148
bool saveColorRamp(const QString &name, const QgsColorRamp *ramp, bool favorite, const QStringList &tags)
Adds the colorramp to the database.
Definition qgsstyle.cpp:458
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:339
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