QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgslimitedrandomcolorrampdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslimitedrandomcolorrampdialog.cpp
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk 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 
17 
18 #include "qgssymbollayerutils.h"
19 #include "qgscolorramp.h"
20 #include "qgshelp.h"
21 
22 #include <QColorDialog>
23 #include <QDialogButtonBox>
24 
25 
27  : QgsPanelWidget( parent )
28  , mRamp( ramp )
29 {
30  setupUi( this );
31 
32  updateUi();
33 
34  connect( spinCount, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setCount );
35  connect( spinHue1, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setHue1 );
36  connect( spinHue2, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setHue2 );
37  connect( spinSat1, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setSat1 );
38  connect( spinSat2, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setSat2 );
39  connect( spinVal1, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setVal1 );
40  connect( spinVal2, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setVal2 );
41 }
42 
44 {
45  mRamp = ramp;
46  updateUi();
47  emit changed();
48 }
49 
50 void QgsLimitedRandomColorRampWidget::updatePreview()
51 {
52  mRamp.updateColors();
53 
54  QSize size( 300, 40 );
55  lblPreview->setPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( &mRamp, size ) );
56 }
57 
58 void QgsLimitedRandomColorRampWidget::updateUi()
59 {
60  spinCount->setValue( mRamp.count() );
61  spinHue1->setValue( mRamp.hueMin() );
62  spinHue2->setValue( mRamp.hueMax() );
63  spinSat1->setValue( mRamp.satMin() );
64  spinSat2->setValue( mRamp.satMax() );
65  spinVal1->setValue( mRamp.valMin() );
66  spinVal2->setValue( mRamp.valMax() );
67  updatePreview();
68 }
69 
71 {
72  mRamp.setCount( val );
73  updatePreview();
74  emit changed();
75 }
76 
78 {
79  mRamp.setHueMin( val );
80  updatePreview();
81  emit changed();
82 }
83 
85 {
86  mRamp.setHueMax( val );
87  updatePreview();
88  emit changed();
89 }
90 
92 {
93  mRamp.setSatMin( val );
94  updatePreview();
95  emit changed();
96 }
97 
99 {
100  mRamp.setSatMax( val );
101  updatePreview();
102  emit changed();
103 }
104 
106 {
107  mRamp.setValMin( val );
108  updatePreview();
109  emit changed();
110 }
111 
113 {
114  mRamp.setValMax( val );
115  updatePreview();
116  emit changed();
117 }
118 
120  : QDialog( parent )
121 {
122  QVBoxLayout *vLayout = new QVBoxLayout();
123  mWidget = new QgsLimitedRandomColorRampWidget( ramp );
124  vLayout->addWidget( mWidget );
125  mButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
126  connect( mButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
127  connect( mButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
128  connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsLimitedRandomColorRampDialog::showHelp );
129  vLayout->addWidget( mButtonBox );
130  setLayout( vLayout );
131  setWindowTitle( tr( "Random Color Ramp" ) );
133 }
134 
136 {
137  return mButtonBox;
138 }
139 
140 void QgsLimitedRandomColorRampDialog::showHelp()
141 {
142  QgsHelp::openHelp( QStringLiteral( "style_library/style_manager.html#setting-a-color-ramp" ) );
143 }
QgsLimitedRandomColorRamp::hueMin
int hueMin() const
Returns the minimum hue for generated colors.
Definition: qgscolorramp.h:336
QgsLimitedRandomColorRampDialog::changed
void changed()
Emitted when the dialog settings change.
QgsLimitedRandomColorRampDialog::ramp
QgsLimitedRandomColorRamp ramp
Definition: qgslimitedrandomcolorrampdialog.h:101
QgsLimitedRandomColorRampWidget::setSat2
void setSat2(int val)
Sets the maximum saturation for colors in the ramp.
Definition: qgslimitedrandomcolorrampdialog.cpp:98
QgsLimitedRandomColorRampWidget::setRamp
void setRamp(const QgsLimitedRandomColorRamp &ramp)
Sets the color ramp to show in the dialog.
Definition: qgslimitedrandomcolorrampdialog.cpp:43
qgssymbollayerutils.h
QgsLimitedRandomColorRamp::setSatMax
void setSatMax(int val)
Sets the maximum saturation for generated colors.
Definition: qgscolorramp.h:395
QgsLimitedRandomColorRampWidget::ramp
QgsLimitedRandomColorRamp ramp
Definition: qgslimitedrandomcolorrampdialog.h:37
QgsLimitedRandomColorRamp::setValMin
void setValMin(int val)
Sets the minimum value for generated colors.
Definition: qgscolorramp.h:401
QgsLimitedRandomColorRampWidget::QgsLimitedRandomColorRampWidget
QgsLimitedRandomColorRampWidget(const QgsLimitedRandomColorRamp &ramp, QWidget *parent=nullptr)
Constructor for QgsLimitedRandomColorRampWidget.
Definition: qgslimitedrandomcolorrampdialog.cpp:26
QgsLimitedRandomColorRamp
Constrained random color ramp, which returns random colors based on preset parameters.
Definition: qgscolorramp.h:283
QgsLimitedRandomColorRamp::satMax
int satMax() const
Returns the maximum saturation for generated colors.
Definition: qgscolorramp.h:354
QgsLimitedRandomColorRamp::setSatMin
void setSatMin(int val)
Sets the minimum saturation for generated colors.
Definition: qgscolorramp.h:389
QgsSymbolLayerUtils::colorRampPreviewPixmap
static QPixmap colorRampPreviewPixmap(QgsColorRamp *ramp, QSize size, int padding=0)
Returns a pixmap preview for a color ramp.
Definition: qgssymbollayerutils.cpp:875
QgsLimitedRandomColorRampDialog::buttonBox
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
Definition: qgslimitedrandomcolorrampdialog.cpp:135
QgsLimitedRandomColorRamp::setHueMax
void setHueMax(int val)
Sets the maximum hue for generated colors.
Definition: qgscolorramp.h:383
QgsLimitedRandomColorRamp::updateColors
void updateColors()
Must be called after changing the properties of the color ramp to regenerate the list of random color...
Definition: qgscolorramp.cpp:409
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:29
QgsLimitedRandomColorRamp::valMax
int valMax() const
Returns the maximum value for generated colors.
Definition: qgscolorramp.h:366
QgsLimitedRandomColorRamp::satMin
int satMin() const
Returns the minimum saturation for generated colors.
Definition: qgscolorramp.h:348
qgscolorramp.h
QgsLimitedRandomColorRampWidget::setVal2
void setVal2(int val)
Sets the maximum value for colors in the ramp.
Definition: qgslimitedrandomcolorrampdialog.cpp:112
QgsLimitedRandomColorRampWidget::setCount
void setCount(int val)
Sets the number of colors to create in the ramp.
Definition: qgslimitedrandomcolorrampdialog.cpp:70
QgsLimitedRandomColorRampDialog::QgsLimitedRandomColorRampDialog
QgsLimitedRandomColorRampDialog(const QgsLimitedRandomColorRamp &ramp, QWidget *parent=nullptr)
Constructor for QgsLimitedRandomColorRampDialog.
Definition: qgslimitedrandomcolorrampdialog.cpp:119
QgsLimitedRandomColorRamp::setCount
void setCount(int val)
Sets the number of colors contained in the ramp.
Definition: qgscolorramp.h:371
QgsLimitedRandomColorRampWidget::setHue2
void setHue2(int val)
Sets the maximum hue for colors in the ramp.
Definition: qgslimitedrandomcolorrampdialog.cpp:84
QgsLimitedRandomColorRampWidget::setHue1
void setHue1(int val)
Sets the minimum hue for colors in the ramp.
Definition: qgslimitedrandomcolorrampdialog.cpp:77
QgsLimitedRandomColorRampWidget::setSat1
void setSat1(int val)
Sets the minimum saturation for colors in the ramp.
Definition: qgslimitedrandomcolorrampdialog.cpp:91
QgsLimitedRandomColorRampWidget::setVal1
void setVal1(int val)
Sets the minimum value for colors in the ramp.
Definition: qgslimitedrandomcolorrampdialog.cpp:105
QgsHelp::openHelp
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:36
QgsLimitedRandomColorRamp::hueMax
int hueMax() const
Returns the maximum hue for generated colors.
Definition: qgscolorramp.h:342
QgsLimitedRandomColorRamp::setHueMin
void setHueMin(int val)
Sets the minimum hue for generated colors.
Definition: qgscolorramp.h:377
qgslimitedrandomcolorrampdialog.h
QgsLimitedRandomColorRampWidget
Definition: qgslimitedrandomcolorrampdialog.h:34
QgsLimitedRandomColorRamp::setValMax
void setValMax(int val)
Sets the maximum value for generated colors.
Definition: qgscolorramp.h:407
qgshelp.h
QgsLimitedRandomColorRampWidget::changed
void changed()
Emitted when the dialog settings change.
QgsLimitedRandomColorRamp::valMin
int valMin() const
Returns the minimum value for generated colors.
Definition: qgscolorramp.h:360
QgsLimitedRandomColorRamp::count
int count() const override
Returns number of defined colors, or -1 if undefined.
Definition: qgscolorramp.h:315