QGIS API Documentation 3.99.0-Master (d270888f95f)
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
18#include "qgscolorramp.h"
19#include "qgshelp.h"
20#include "qgssymbollayerutils.h"
21
22#include <QColorDialog>
23#include <QDialogButtonBox>
24#include <QString>
25
26#include "moc_qgslimitedrandomcolorrampdialog.cpp"
27
28using namespace Qt::StringLiterals;
29
31 : QgsPanelWidget( parent )
32 , mRamp( ramp )
33{
34 setupUi( this );
35 spinCount->setClearValue( 10 );
36 spinHue1->setClearValue( 0 );
37 spinHue2->setClearValue( 359 );
38 spinSat1->setClearValue( 100 );
39 spinSat2->setClearValue( 240 );
40 spinVal1->setClearValue( 200 );
41 spinVal2->setClearValue( 240 );
42
43 updateUi();
44
45 connect( spinCount, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setCount );
46 connect( spinHue1, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setHue1 );
47 connect( spinHue2, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setHue2 );
48 connect( spinSat1, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setSat1 );
49 connect( spinSat2, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setSat2 );
50 connect( spinVal1, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setVal1 );
51 connect( spinVal2, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), this, &QgsLimitedRandomColorRampWidget::setVal2 );
52}
53
55{
56 mRamp = ramp;
57 updateUi();
58 emit changed();
59}
60
61void QgsLimitedRandomColorRampWidget::updatePreview()
62{
63 mRamp.updateColors();
64
65 const QSize size( 300, 40 );
66 lblPreview->setPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( &mRamp, size ) );
67}
68
69void QgsLimitedRandomColorRampWidget::updateUi()
70{
71 spinCount->setValue( mRamp.count() );
72 spinHue1->setValue( mRamp.hueMin() );
73 spinHue2->setValue( mRamp.hueMax() );
74 spinSat1->setValue( mRamp.satMin() );
75 spinSat2->setValue( mRamp.satMax() );
76 spinVal1->setValue( mRamp.valMin() );
77 spinVal2->setValue( mRamp.valMax() );
78 updatePreview();
79}
80
82{
83 mRamp.setCount( val );
84 updatePreview();
85 emit changed();
86}
87
89{
90 mRamp.setHueMin( val );
91 updatePreview();
92 emit changed();
93}
94
96{
97 mRamp.setHueMax( val );
98 updatePreview();
99 emit changed();
100}
101
103{
104 mRamp.setSatMin( val );
105 updatePreview();
106 emit changed();
107}
108
110{
111 mRamp.setSatMax( val );
112 updatePreview();
113 emit changed();
114}
115
117{
118 mRamp.setValMin( val );
119 updatePreview();
120 emit changed();
121}
122
124{
125 mRamp.setValMax( val );
126 updatePreview();
127 emit changed();
128}
129
131 : QDialog( parent )
132{
133 QVBoxLayout *vLayout = new QVBoxLayout();
134 mWidget = new QgsLimitedRandomColorRampWidget( ramp );
135
136 connect( mWidget, &QgsPanelWidget::panelAccepted, this, &QDialog::reject );
137
138 vLayout->addWidget( mWidget );
139 mButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
140 connect( mButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
141 connect( mButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
142 connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsLimitedRandomColorRampDialog::showHelp );
143 vLayout->addWidget( mButtonBox );
144 setLayout( vLayout );
145 setWindowTitle( tr( "Random Color Ramp" ) );
147}
148
150{
151 return mButtonBox;
152}
153
154void QgsLimitedRandomColorRampDialog::showHelp()
155{
156 QgsHelp::openHelp( u"style_library/style_manager.html#setting-a-color-ramp"_s );
157}
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:41
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 panelAccepted(QgsPanelWidget *panel)
Emitted when the panel is accepted by the user.
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an inline panel.
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.