QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  spinCount->setClearValue( 10 );
32  spinHue1->setClearValue( 0 );
33  spinHue2->setClearValue( 359 );
34  spinSat1->setClearValue( 100 );
35  spinSat2->setClearValue( 240 );
36  spinVal1->setClearValue( 200 );
37  spinVal2->setClearValue( 240 );
38 
39  updateUi();
40 
41  connect( spinCount, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setCount );
42  connect( spinHue1, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setHue1 );
43  connect( spinHue2, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setHue2 );
44  connect( spinSat1, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setSat1 );
45  connect( spinSat2, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setSat2 );
46  connect( spinVal1, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setVal1 );
47  connect( spinVal2, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setVal2 );
48 }
49 
51 {
52  mRamp = ramp;
53  updateUi();
54  emit changed();
55 }
56 
57 void QgsLimitedRandomColorRampWidget::updatePreview()
58 {
59  mRamp.updateColors();
60 
61  QSize size( 300, 40 );
62  lblPreview->setPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( &mRamp, size ) );
63 }
64 
65 void QgsLimitedRandomColorRampWidget::updateUi()
66 {
67  spinCount->setValue( mRamp.count() );
68  spinHue1->setValue( mRamp.hueMin() );
69  spinHue2->setValue( mRamp.hueMax() );
70  spinSat1->setValue( mRamp.satMin() );
71  spinSat2->setValue( mRamp.satMax() );
72  spinVal1->setValue( mRamp.valMin() );
73  spinVal2->setValue( mRamp.valMax() );
74  updatePreview();
75 }
76 
78 {
79  mRamp.setCount( val );
80  updatePreview();
81  emit changed();
82 }
83 
85 {
86  mRamp.setHueMin( val );
87  updatePreview();
88  emit changed();
89 }
90 
92 {
93  mRamp.setHueMax( val );
94  updatePreview();
95  emit changed();
96 }
97 
99 {
100  mRamp.setSatMin( val );
101  updatePreview();
102  emit changed();
103 }
104 
106 {
107  mRamp.setSatMax( val );
108  updatePreview();
109  emit changed();
110 }
111 
113 {
114  mRamp.setValMin( val );
115  updatePreview();
116  emit changed();
117 }
118 
120 {
121  mRamp.setValMax( val );
122  updatePreview();
123  emit changed();
124 }
125 
127  : QDialog( parent )
128 {
129  QVBoxLayout *vLayout = new QVBoxLayout();
130  mWidget = new QgsLimitedRandomColorRampWidget( ramp );
131 
132  connect( mWidget, &QgsPanelWidget::panelAccepted, this, &QDialog::reject );
133 
134  vLayout->addWidget( mWidget );
135  mButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
136  connect( mButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
137  connect( mButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
138  connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsLimitedRandomColorRampDialog::showHelp );
139  vLayout->addWidget( mButtonBox );
140  setLayout( vLayout );
141  setWindowTitle( tr( "Random Color Ramp" ) );
143 }
144 
146 {
147  return mButtonBox;
148 }
149 
150 void QgsLimitedRandomColorRampDialog::showHelp()
151 {
152  QgsHelp::openHelp( QStringLiteral( "style_library/style_manager.html#setting-a-color-ramp" ) );
153 }
QgsLimitedRandomColorRamp::hueMin
int hueMin() const
Returns the minimum hue for generated colors.
Definition: qgscolorramp.h:363
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:105
QgsLimitedRandomColorRampWidget::setRamp
void setRamp(const QgsLimitedRandomColorRamp &ramp)
Sets the color ramp to show in the dialog.
Definition: qgslimitedrandomcolorrampdialog.cpp:50
qgssymbollayerutils.h
QgsLimitedRandomColorRamp::setSatMax
void setSatMax(int val)
Sets the maximum saturation for generated colors.
Definition: qgscolorramp.h:422
QgsLimitedRandomColorRampWidget::ramp
QgsLimitedRandomColorRamp ramp
Definition: qgslimitedrandomcolorrampdialog.h:37
QgsLimitedRandomColorRamp::setValMin
void setValMin(int val)
Sets the minimum value for generated colors.
Definition: qgscolorramp.h:428
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:303
QgsLimitedRandomColorRamp::satMax
int satMax() const
Returns the maximum saturation for generated colors.
Definition: qgscolorramp.h:381
QgsLimitedRandomColorRamp::setSatMin
void setSatMin(int val)
Sets the minimum saturation for generated colors.
Definition: qgscolorramp.h:416
QgsSymbolLayerUtils::colorRampPreviewPixmap
static QPixmap colorRampPreviewPixmap(QgsColorRamp *ramp, QSize size, int padding=0)
Returns a pixmap preview for a color ramp.
Definition: qgssymbollayerutils.cpp:877
QgsLimitedRandomColorRampDialog::buttonBox
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
Definition: qgslimitedrandomcolorrampdialog.cpp:145
QgsLimitedRandomColorRamp::setHueMax
void setHueMax(int val)
Sets the maximum hue for generated colors.
Definition: qgscolorramp.h:410
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:419
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:30
QgsLimitedRandomColorRamp::valMax
int valMax() const
Returns the maximum value for generated colors.
Definition: qgscolorramp.h:393
QgsLimitedRandomColorRamp::satMin
int satMin() const
Returns the minimum saturation for generated colors.
Definition: qgscolorramp.h:375
qgscolorramp.h
QgsPanelWidget::panelAccepted
void panelAccepted(QgsPanelWidget *panel)
Emitted when the panel is accepted by the user.
QgsLimitedRandomColorRampWidget::setVal2
void setVal2(int val)
Sets the maximum value for colors in the ramp.
Definition: qgslimitedrandomcolorrampdialog.cpp:119
QgsLimitedRandomColorRampWidget::setCount
void setCount(int val)
Sets the number of colors to create in the ramp.
Definition: qgslimitedrandomcolorrampdialog.cpp:77
QgsLimitedRandomColorRampDialog::QgsLimitedRandomColorRampDialog
QgsLimitedRandomColorRampDialog(const QgsLimitedRandomColorRamp &ramp, QWidget *parent=nullptr)
Constructor for QgsLimitedRandomColorRampDialog.
Definition: qgslimitedrandomcolorrampdialog.cpp:126
QgsLimitedRandomColorRamp::setCount
void setCount(int val)
Sets the number of colors contained in the ramp.
Definition: qgscolorramp.h:398
QgsLimitedRandomColorRampWidget::setHue2
void setHue2(int val)
Sets the maximum hue for colors in the ramp.
Definition: qgslimitedrandomcolorrampdialog.cpp:91
QgsLimitedRandomColorRampWidget::setHue1
void setHue1(int val)
Sets the minimum hue for colors in the ramp.
Definition: qgslimitedrandomcolorrampdialog.cpp:84
QgsLimitedRandomColorRampWidget::setSat1
void setSat1(int val)
Sets the minimum saturation for colors in the ramp.
Definition: qgslimitedrandomcolorrampdialog.cpp:98
QgsLimitedRandomColorRampWidget::setVal1
void setVal1(int val)
Sets the minimum value for colors in the ramp.
Definition: qgslimitedrandomcolorrampdialog.cpp:112
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:369
QgsLimitedRandomColorRamp::setHueMin
void setHueMin(int val)
Sets the minimum hue for generated colors.
Definition: qgscolorramp.h:404
qgslimitedrandomcolorrampdialog.h
QgsLimitedRandomColorRampWidget
A widget which allows users to modify the properties of a QgsLimitedRandomColorRamp.
Definition: qgslimitedrandomcolorrampdialog.h:35
QgsLimitedRandomColorRamp::setValMax
void setValMax(int val)
Sets the maximum value for generated colors.
Definition: qgscolorramp.h:434
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:387
QgsLimitedRandomColorRamp::count
int count() const override
Returns number of defined colors, or -1 if undefined.
Definition: qgscolorramp.h:342