Skip to content

Commit b225a82

Browse files
committed
[FEATURE] Make color brewer and limited random ramp editors show
inline in style panel
1 parent 1d98b10 commit b225a82

10 files changed

+351
-254
lines changed

python/gui/qgscolorbrewercolorrampdialog.sip

+37
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
/** \ingroup gui
2+
* \class QgsColorBrewerColorRampDialog
3+
* A widget which allows users to modify the properties of a QgsColorBrewerColorRamp.
4+
* \note added in QGIS 3.0
5+
*/
6+
7+
class QgsColorBrewerColorRampWidget : QgsPanelWidget
8+
{
9+
%TypeHeaderCode
10+
#include <qgscolorbrewercolorrampdialog.h>
11+
%End
12+
13+
public:
14+
15+
/** Constructor for QgsColorBrewerColorRampDialog.
16+
* @param ramp initial ramp to show in dialog
17+
* @param parent parent widget
18+
*/
19+
QgsColorBrewerColorRampWidget( const QgsColorBrewerColorRamp& ramp, QWidget* parent /TransferThis/ = nullptr );
20+
21+
/** Returns a color ramp representing the current settings from the dialog.
22+
* @see setRamp()
23+
*/
24+
QgsColorBrewerColorRamp ramp() const;
25+
26+
/** Sets the color ramp to show in the dialog.
27+
* @param ramp color ramp
28+
* @see ramp()
29+
*/
30+
void setRamp( const QgsColorBrewerColorRamp& ramp );
31+
32+
signals:
33+
34+
//! Emitted when the dialog settings change
35+
void changed();
36+
};
37+
138
/** \ingroup gui
239
* \class QgsColorBrewerColorRampDialog
340
* A dialog which allows users to modify the properties of a QgsColorBrewerColorRamp.

python/gui/qgslimitedrandomcolorrampdialog.sip

+43-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
/** \ingroup gui
2-
* \class QgsLimitedRandomColorRampDialog
3-
* A dialog which allows users to modify the properties of a QgsLimitedRandomColorRamp.
2+
* \class QgsLimitedRandomColorRampWidget
3+
* A widget which allows users to modify the properties of a QgsLimitedRandomColorRamp.
44
* \note added in QGIS 3.0
55
*/
66

7-
class QgsLimitedRandomColorRampDialog : QDialog
7+
class QgsLimitedRandomColorRampWidget : QgsPanelWidget
88
{
99
%TypeHeaderCode
1010
#include <qgslimitedrandomcolorrampdialog.h>
1111
%End
1212

1313
public:
1414

15-
/** Constructor for QgsLimitedRandomColorRampDialog.
15+
/** Constructor for QgsLimitedRandomColorRampWidget.
1616
* @param ramp initial ramp to show in dialog
1717
* @param parent parent widget
1818
*/
19-
QgsLimitedRandomColorRampDialog( const QgsLimitedRandomColorRamp& ramp, QWidget* parent /TransferThis/ = nullptr );
19+
QgsLimitedRandomColorRampWidget( const QgsLimitedRandomColorRamp& ramp, QWidget* parent /TransferThis/ = nullptr );
2020

2121
/** Returns a color ramp representing the current settings from the dialog.
2222
* @see setRamp()
@@ -51,3 +51,41 @@ class QgsLimitedRandomColorRampDialog : QDialog
5151
//! Sets the maximum value for colors in the ramp
5252
void setVal2( int val );
5353
};
54+
55+
/** \ingroup gui
56+
* \class QgsLimitedRandomColorRampDialog
57+
* A dialog which allows users to modify the properties of a QgsLimitedRandomColorRamp.
58+
* \note added in QGIS 3.0
59+
*/
60+
61+
class QgsLimitedRandomColorRampDialog : QDialog
62+
{
63+
%TypeHeaderCode
64+
#include <qgslimitedrandomcolorrampdialog.h>
65+
%End
66+
67+
public:
68+
69+
/** Constructor for QgsLimitedRandomColorRampDialog.
70+
* @param ramp initial ramp to show in dialog
71+
* @param parent parent widget
72+
*/
73+
QgsLimitedRandomColorRampDialog( const QgsLimitedRandomColorRamp& ramp, QWidget* parent /TransferThis/ = nullptr );
74+
75+
/** Returns a color ramp representing the current settings from the dialog.
76+
* @see setRamp()
77+
*/
78+
QgsLimitedRandomColorRamp ramp() const;
79+
80+
/** Sets the color ramp to show in the dialog.
81+
* @param ramp color ramp
82+
* @see ramp()
83+
*/
84+
void setRamp( const QgsLimitedRandomColorRamp& ramp );
85+
86+
signals:
87+
88+
//! Emitted when the dialog settings change
89+
void changed();
90+
91+
};

src/gui/qgscolorbrewercolorrampdialog.cpp

+23-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgscolorramp.h"
1919
#include "qgssymbollayerutils.h"
2020
#include <QAbstractButton>
21+
#include <QDialogButtonBox>
2122

2223
#if 0 // unused
2324
static void updateColorButton( QAbstractButton* button, QColor color )
@@ -31,8 +32,8 @@ static void updateColorButton( QAbstractButton* button, QColor color )
3132
/////////
3233

3334

34-
QgsColorBrewerColorRampDialog::QgsColorBrewerColorRampDialog( const QgsColorBrewerColorRamp& ramp, QWidget* parent )
35-
: QDialog( parent )
35+
QgsColorBrewerColorRampWidget::QgsColorBrewerColorRampWidget( const QgsColorBrewerColorRamp& ramp, QWidget* parent )
36+
: QgsPanelWidget( parent )
3637
, mRamp( ramp )
3738
{
3839

@@ -56,14 +57,14 @@ QgsColorBrewerColorRampDialog::QgsColorBrewerColorRampDialog( const QgsColorBrew
5657
connect( cboColors, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setColors() ) );
5758
}
5859

59-
void QgsColorBrewerColorRampDialog::setRamp( const QgsColorBrewerColorRamp& ramp )
60+
void QgsColorBrewerColorRampWidget::setRamp( const QgsColorBrewerColorRamp& ramp )
6061
{
6162
mRamp = ramp;
6263
updateUi();
6364
emit changed();
6465
}
6566

66-
void QgsColorBrewerColorRampDialog::populateVariants()
67+
void QgsColorBrewerColorRampWidget::populateVariants()
6768
{
6869
QString oldVariant = cboColors->currentText();
6970

@@ -85,21 +86,21 @@ void QgsColorBrewerColorRampDialog::populateVariants()
8586
cboColors->setCurrentIndex( idx );
8687
}
8788

88-
void QgsColorBrewerColorRampDialog::updatePreview()
89+
void QgsColorBrewerColorRampWidget::updatePreview()
8990
{
9091
QSize size( 300, 40 );
9192
lblPreview->setPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( &mRamp, size ) );
9293
}
9394

94-
void QgsColorBrewerColorRampDialog::updateUi()
95+
void QgsColorBrewerColorRampWidget::updateUi()
9596
{
9697
whileBlocking( cboSchemeName )->setCurrentIndex( cboSchemeName->findText( mRamp.schemeName() ) );
9798
populateVariants();
9899
whileBlocking( cboColors )->setCurrentIndex( cboColors->findText( QString::number( mRamp.colors() ) ) );
99100
updatePreview();
100101
}
101102

102-
void QgsColorBrewerColorRampDialog::setSchemeName()
103+
void QgsColorBrewerColorRampWidget::setSchemeName()
103104
{
104105
// populate list of variants
105106
populateVariants();
@@ -109,10 +110,24 @@ void QgsColorBrewerColorRampDialog::setSchemeName()
109110
emit changed();
110111
}
111112

112-
void QgsColorBrewerColorRampDialog::setColors()
113+
void QgsColorBrewerColorRampWidget::setColors()
113114
{
114115
int num = cboColors->currentText().toInt();
115116
mRamp.setColors( num );
116117
updatePreview();
117118
emit changed();
118119
}
120+
121+
QgsColorBrewerColorRampDialog::QgsColorBrewerColorRampDialog( const QgsColorBrewerColorRamp& ramp, QWidget* parent )
122+
: QDialog( parent )
123+
{
124+
QVBoxLayout* vLayout = new QVBoxLayout();
125+
mWidget = new QgsColorBrewerColorRampWidget( ramp );
126+
vLayout->addWidget( mWidget );
127+
QDialogButtonBox* bbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
128+
connect( bbox, SIGNAL( accepted() ), this, SLOT( accept() ) );
129+
connect( bbox, SIGNAL( rejected() ), this, SLOT( reject() ) );
130+
vLayout->addWidget( bbox );
131+
setLayout( vLayout );
132+
connect( mWidget, SIGNAL( changed() ), this, SIGNAL( changed() ) );
133+
}

src/gui/qgscolorbrewercolorrampdialog.h

+47-7
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@
1717
#define QGSCOLORBREWERCOLORRAMPDIALOG_H
1818

1919
#include <QDialog>
20-
20+
#include "qgspanelwidget.h"
2121
#include "qgscolorramp.h"
22-
#include "ui_qgscolorbrewercolorrampdialogbase.h"
22+
#include "ui_qgscolorbrewercolorrampwidgetbase.h"
2323

2424
class QgsColorBrewerColorRamp;
2525

2626
/** \ingroup gui
27-
* \class QgsColorBrewerColorRampDialog
28-
* A dialog which allows users to modify the properties of a QgsColorBrewerColorRamp.
27+
* \class QgsColorBrewerColorRampWidget
28+
* A widget which allows users to modify the properties of a QgsColorBrewerColorRamp.
2929
* \note added in QGIS 3.0
3030
*/
31-
class GUI_EXPORT QgsColorBrewerColorRampDialog : public QDialog, private Ui::QgsColorBrewerColorRampDialogBase
31+
class GUI_EXPORT QgsColorBrewerColorRampWidget : public QgsPanelWidget, private Ui::QgsColorBrewerColorRampWidgetBase
3232
{
3333
Q_OBJECT
3434
Q_PROPERTY( QgsColorBrewerColorRamp ramp READ ramp WRITE setRamp )
3535

3636
public:
3737

38-
/** Constructor for QgsColorBrewerColorRampDialog.
38+
/** Constructor for QgsColorBrewerColorRampWidget.
3939
* @param ramp initial ramp to show in dialog
4040
* @param parent parent widget
4141
*/
42-
QgsColorBrewerColorRampDialog( const QgsColorBrewerColorRamp& ramp, QWidget* parent = nullptr );
42+
QgsColorBrewerColorRampWidget( const QgsColorBrewerColorRamp& ramp, QWidget* parent = nullptr );
4343

4444
/** Returns a color ramp representing the current settings from the dialog.
4545
* @see setRamp()
@@ -70,4 +70,44 @@ class GUI_EXPORT QgsColorBrewerColorRampDialog : public QDialog, private Ui::Qgs
7070
QgsColorBrewerColorRamp mRamp;
7171
};
7272

73+
/** \ingroup gui
74+
* \class QgsColorBrewerColorRampDialog
75+
* A dialog which allows users to modify the properties of a QgsColorBrewerColorRamp.
76+
* \note added in QGIS 3.0
77+
*/
78+
class GUI_EXPORT QgsColorBrewerColorRampDialog : public QDialog
79+
{
80+
Q_OBJECT
81+
Q_PROPERTY( QgsColorBrewerColorRamp ramp READ ramp WRITE setRamp )
82+
83+
public:
84+
85+
/** Constructor for QgsColorBrewerColorRampDialog.
86+
* @param ramp initial ramp to show in dialog
87+
* @param parent parent widget
88+
*/
89+
QgsColorBrewerColorRampDialog( const QgsColorBrewerColorRamp& ramp, QWidget* parent = nullptr );
90+
91+
/** Returns a color ramp representing the current settings from the dialog.
92+
* @see setRamp()
93+
*/
94+
QgsColorBrewerColorRamp ramp() const { return mWidget->ramp(); }
95+
96+
/** Sets the color ramp to show in the dialog.
97+
* @param ramp color ramp
98+
* @see ramp()
99+
*/
100+
void setRamp( const QgsColorBrewerColorRamp& ramp ) { mWidget->setRamp( ramp ); }
101+
102+
signals:
103+
104+
//! Emitted when the dialog settings change
105+
void changed();
106+
107+
private:
108+
109+
QgsColorBrewerColorRampWidget* mWidget;
110+
111+
};
112+
73113
#endif

src/gui/qgslimitedrandomcolorrampdialog.cpp

+27-12
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
#include "qgscolorramp.h"
2020

2121
#include <QColorDialog>
22+
#include <QDialogButtonBox>
2223

2324

24-
QgsLimitedRandomColorRampDialog::QgsLimitedRandomColorRampDialog( const QgsLimitedRandomColorRamp& ramp, QWidget* parent )
25-
: QDialog( parent )
25+
QgsLimitedRandomColorRampWidget::QgsLimitedRandomColorRampWidget( const QgsLimitedRandomColorRamp& ramp, QWidget* parent )
26+
: QgsPanelWidget( parent )
2627
, mRamp( ramp )
2728
{
2829
setupUi( this );
@@ -38,22 +39,22 @@ QgsLimitedRandomColorRampDialog::QgsLimitedRandomColorRampDialog( const QgsLimit
3839
connect( spinVal2, SIGNAL( valueChanged( int ) ), this, SLOT( setVal2( int ) ) );
3940
}
4041

41-
void QgsLimitedRandomColorRampDialog::setRamp( const QgsLimitedRandomColorRamp& ramp )
42+
void QgsLimitedRandomColorRampWidget::setRamp( const QgsLimitedRandomColorRamp& ramp )
4243
{
4344
mRamp = ramp;
4445
updateUi();
4546
emit changed();
4647
}
4748

48-
void QgsLimitedRandomColorRampDialog::updatePreview()
49+
void QgsLimitedRandomColorRampWidget::updatePreview()
4950
{
5051
mRamp.updateColors();
5152

5253
QSize size( 300, 40 );
5354
lblPreview->setPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( &mRamp, size ) );
5455
}
5556

56-
void QgsLimitedRandomColorRampDialog::updateUi()
57+
void QgsLimitedRandomColorRampWidget::updateUi()
5758
{
5859
spinCount->setValue( mRamp.count() );
5960
spinHue1->setValue( mRamp.hueMin() );
@@ -65,51 +66,65 @@ void QgsLimitedRandomColorRampDialog::updateUi()
6566
updatePreview();
6667
}
6768

68-
void QgsLimitedRandomColorRampDialog::setCount( int val )
69+
void QgsLimitedRandomColorRampWidget::setCount( int val )
6970
{
7071
mRamp.setCount( val );
7172
updatePreview();
7273
emit changed();
7374
}
7475

75-
void QgsLimitedRandomColorRampDialog::setHue1( int val )
76+
void QgsLimitedRandomColorRampWidget::setHue1( int val )
7677
{
7778
mRamp.setHueMin( val );
7879
updatePreview();
7980
emit changed();
8081
}
8182

82-
void QgsLimitedRandomColorRampDialog::setHue2( int val )
83+
void QgsLimitedRandomColorRampWidget::setHue2( int val )
8384
{
8485
mRamp.setHueMax( val );
8586
updatePreview();
8687
emit changed();
8788
}
8889

89-
void QgsLimitedRandomColorRampDialog::setSat1( int val )
90+
void QgsLimitedRandomColorRampWidget::setSat1( int val )
9091
{
9192
mRamp.setSatMin( val );
9293
updatePreview();
9394
emit changed();
9495
}
9596

96-
void QgsLimitedRandomColorRampDialog::setSat2( int val )
97+
void QgsLimitedRandomColorRampWidget::setSat2( int val )
9798
{
9899
mRamp.setSatMax( val );
99100
updatePreview();
100101
emit changed();
101102
}
102103

103-
void QgsLimitedRandomColorRampDialog::setVal1( int val )
104+
void QgsLimitedRandomColorRampWidget::setVal1( int val )
104105
{
105106
mRamp.setValMin( val );
106107
updatePreview();
107108
emit changed();
108109
}
109110

110-
void QgsLimitedRandomColorRampDialog::setVal2( int val )
111+
void QgsLimitedRandomColorRampWidget::setVal2( int val )
111112
{
112113
mRamp.setValMax( val );
113114
updatePreview();
114115
emit changed();
115116
}
117+
118+
QgsLimitedRandomColorRampDialog::QgsLimitedRandomColorRampDialog( const QgsLimitedRandomColorRamp& ramp, QWidget* parent )
119+
: QDialog( parent )
120+
{
121+
QVBoxLayout* vLayout = new QVBoxLayout();
122+
mWidget = new QgsLimitedRandomColorRampWidget( ramp );
123+
vLayout->addWidget( mWidget );
124+
QDialogButtonBox* bbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
125+
connect( bbox, SIGNAL( accepted() ), this, SLOT( accept() ) );
126+
connect( bbox, SIGNAL( rejected() ), this, SLOT( reject() ) );
127+
vLayout->addWidget( bbox );
128+
setLayout( vLayout );
129+
connect( mWidget, SIGNAL( changed() ), this, SIGNAL( changed() ) );
130+
}

0 commit comments

Comments
 (0)