QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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  QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
126  connect( bbox, &QDialogButtonBox::accepted, this, &QDialog::accept );
127  connect( bbox, &QDialogButtonBox::rejected, this, &QDialog::reject );
128  connect( bbox, &QDialogButtonBox::helpRequested, this, &QgsLimitedRandomColorRampDialog::showHelp );
129  vLayout->addWidget( bbox );
130  setLayout( vLayout );
131  setWindowTitle( tr( "Random Color Ramp" ) );
133 }
134 
135 void QgsLimitedRandomColorRampDialog::showHelp()
136 {
137  QgsHelp::openHelp( QStringLiteral( "working_with_vector/style_library.html#color-ramp" ) );
138 }
int valMin() const
Returns the minimum value for generated colors.
Definition: qgscolorramp.h:360
void setCount(int val)
Sets the number of colors contained in the ramp.
Definition: qgscolorramp.h:371
A widget which allows users to modify the properties of a QgsLimitedRandomColorRamp.
QgsLimitedRandomColorRampDialog(const QgsLimitedRandomColorRamp &ramp, QWidget *parent=nullptr)
Constructor for QgsLimitedRandomColorRampDialog.
void changed()
Emitted when the dialog settings change.
void setHueMax(int val)
Sets the maximum hue for generated colors.
Definition: qgscolorramp.h:383
void setCount(int val)
Sets the number of colors to create in the ramp.
Base class for any widget that can be shown as a inline panel.
void setHueMin(int val)
Sets the minimum hue for generated colors.
Definition: qgscolorramp.h:377
void setVal2(int val)
Sets the maximum value for colors in the ramp.
void setRamp(const QgsLimitedRandomColorRamp &ramp)
Sets the color ramp to show in the dialog.
Constrained random color ramp, which returns random colors based on preset parameters.
Definition: qgscolorramp.h:283
QgsLimitedRandomColorRamp ramp() const
Returns a color ramp representing the current settings from the dialog.
int count() const override
Returns number of defined colors, or -1 if undefined.
Definition: qgscolorramp.h:315
void setHue2(int val)
Sets the maximum hue for colors in the ramp.
int satMax() const
Returns the maximum saturation for generated colors.
Definition: qgscolorramp.h:354
int hueMin() const
Returns the minimum hue for generated colors.
Definition: qgscolorramp.h:336
int hueMax() const
Returns the maximum hue for generated colors.
Definition: qgscolorramp.h:342
void setSatMax(int val)
Sets the maximum saturation for generated colors.
Definition: qgscolorramp.h:395
void setVal1(int val)
Sets the minimum value for colors in the ramp.
static QPixmap colorRampPreviewPixmap(QgsColorRamp *ramp, QSize size, int padding=0)
Returns a pixmap preview for a color ramp.
void setSat2(int val)
Sets the maximum saturation for colors in the ramp.
void setValMin(int val)
Sets the minimum value for generated colors.
Definition: qgscolorramp.h:401
void setSat1(int val)
Sets the minimum saturation for colors in the ramp.
int satMin() const
Returns the minimum saturation for generated colors.
Definition: qgscolorramp.h:348
void changed()
Emitted when the dialog settings change.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:35
void setSatMin(int val)
Sets the minimum saturation for generated colors.
Definition: qgscolorramp.h:389
void setHue1(int val)
Sets the minimum hue for colors in the ramp.
int valMax() const
Returns the maximum value for generated colors.
Definition: qgscolorramp.h:366
void updateColors()
Must be called after changing the properties of the color ramp to regenerate the list of random color...
QgsLimitedRandomColorRampWidget(const QgsLimitedRandomColorRamp &ramp, QWidget *parent=nullptr)
Constructor for QgsLimitedRandomColorRampWidget.
void setValMax(int val)
Sets the maximum value for generated colors.
Definition: qgscolorramp.h:407