QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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#include "moc_qgslimitedrandomcolorrampdialog.cpp"
18
19#include "qgssymbollayerutils.h"
20#include "qgscolorramp.h"
21#include "qgshelp.h"
22
23#include <QColorDialog>
24#include <QDialogButtonBox>
25
26
28 : QgsPanelWidget( parent )
29 , mRamp( ramp )
30{
31 setupUi( this );
32 spinCount->setClearValue( 10 );
33 spinHue1->setClearValue( 0 );
34 spinHue2->setClearValue( 359 );
35 spinSat1->setClearValue( 100 );
36 spinSat2->setClearValue( 240 );
37 spinVal1->setClearValue( 200 );
38 spinVal2->setClearValue( 240 );
39
40 updateUi();
41
42 connect( spinCount, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setCount );
43 connect( spinHue1, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setHue1 );
44 connect( spinHue2, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setHue2 );
45 connect( spinSat1, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setSat1 );
46 connect( spinSat2, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setSat2 );
47 connect( spinVal1, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setVal1 );
48 connect( spinVal2, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setVal2 );
49}
50
52{
53 mRamp = ramp;
54 updateUi();
55 emit changed();
56}
57
58void QgsLimitedRandomColorRampWidget::updatePreview()
59{
60 mRamp.updateColors();
61
62 const QSize size( 300, 40 );
63 lblPreview->setPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( &mRamp, size ) );
64}
65
66void QgsLimitedRandomColorRampWidget::updateUi()
67{
68 spinCount->setValue( mRamp.count() );
69 spinHue1->setValue( mRamp.hueMin() );
70 spinHue2->setValue( mRamp.hueMax() );
71 spinSat1->setValue( mRamp.satMin() );
72 spinSat2->setValue( mRamp.satMax() );
73 spinVal1->setValue( mRamp.valMin() );
74 spinVal2->setValue( mRamp.valMax() );
75 updatePreview();
76}
77
79{
80 mRamp.setCount( val );
81 updatePreview();
82 emit changed();
83}
84
86{
87 mRamp.setHueMin( val );
88 updatePreview();
89 emit changed();
90}
91
93{
94 mRamp.setHueMax( val );
95 updatePreview();
96 emit changed();
97}
98
100{
101 mRamp.setSatMin( val );
102 updatePreview();
103 emit changed();
104}
105
107{
108 mRamp.setSatMax( val );
109 updatePreview();
110 emit changed();
111}
112
114{
115 mRamp.setValMin( val );
116 updatePreview();
117 emit changed();
118}
119
121{
122 mRamp.setValMax( val );
123 updatePreview();
124 emit changed();
125}
126
128 : QDialog( parent )
129{
130 QVBoxLayout *vLayout = new QVBoxLayout();
131 mWidget = new QgsLimitedRandomColorRampWidget( ramp );
132
133 connect( mWidget, &QgsPanelWidget::panelAccepted, this, &QDialog::reject );
134
135 vLayout->addWidget( mWidget );
136 mButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
137 connect( mButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
138 connect( mButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
139 connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsLimitedRandomColorRampDialog::showHelp );
140 vLayout->addWidget( mButtonBox );
141 setLayout( vLayout );
142 setWindowTitle( tr( "Random Color Ramp" ) );
144}
145
147{
148 return mButtonBox;
149}
150
151void QgsLimitedRandomColorRampDialog::showHelp()
152{
153 QgsHelp::openHelp( QStringLiteral( "style_library/style_manager.html#setting-a-color-ramp" ) );
154}
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:39
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
void changed()
Emitted when the dialog settings change.
QgsLimitedRandomColorRampDialog(const QgsLimitedRandomColorRamp &ramp, QWidget *parent=nullptr)
Constructor for QgsLimitedRandomColorRampDialog.
A widget which allows users to modify the properties of a QgsLimitedRandomColorRamp.
QgsLimitedRandomColorRampWidget(const QgsLimitedRandomColorRamp &ramp, QWidget *parent=nullptr)
Constructor for QgsLimitedRandomColorRampWidget.
void setCount(int val)
Sets the number of colors to create in the ramp.
void setVal1(int val)
Sets the minimum value for colors in the ramp.
void setHue2(int val)
Sets the maximum hue for colors in the ramp.
void changed()
Emitted when the dialog settings change.
void setVal2(int val)
Sets the maximum value for colors in the ramp.
void setSat2(int val)
Sets the maximum saturation for colors in the ramp.
void setRamp(const QgsLimitedRandomColorRamp &ramp)
Sets the color ramp to show in the dialog.
void setHue1(int val)
Sets the minimum hue for colors in the ramp.
void setSat1(int val)
Sets the minimum saturation for colors in the ramp.
Constrained random color ramp, which returns random colors based on preset parameters.
void updateColors()
Must be called after changing the properties of the color ramp to regenerate the list of random color...
void setSatMin(int val)
Sets the minimum saturation for generated colors.
int count() const override
Returns number of defined colors, or -1 if undefined.
void setHueMin(int val)
Sets the minimum hue for generated colors.
void setSatMax(int val)
Sets the maximum saturation for generated colors.
int valMax() const
Returns the maximum value for generated colors.
int satMax() const
Returns the maximum saturation for generated colors.
void setHueMax(int val)
Sets the maximum hue for generated colors.
void setCount(int val)
Sets the number of colors contained in the ramp.
int hueMax() const
Returns the maximum hue for generated colors.
int hueMin() const
Returns the minimum hue for generated colors.
void setValMax(int val)
Sets the maximum value for generated colors.
int valMin() const
Returns the minimum value for generated colors.
void setValMin(int val)
Sets the minimum value for generated colors.
int satMin() const
Returns the minimum saturation for generated colors.
Base class for any widget that can be shown as a inline panel.
void panelAccepted(QgsPanelWidget *panel)
Emitted when the panel is accepted by the user.
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.