Skip to content

Commit 26c1e09

Browse files
committed
Remove QgsColorDialog, rename QgsColorDialogV2 to QgsColorDialog
The last bits of missing functionality (handling native dialogs and live updates) were ported across.
1 parent 2893456 commit 26c1e09

12 files changed

+75
-156
lines changed

doc/api_break.dox

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ This page tries to maintain a list with incompatible changes that happened in pr
4343
\subsection qgis_api_break_3_0_removed_classes Removed Classes
4444

4545
<ul>
46-
<li>QgsColorbutton was removed. QgsColorButtonV2 has now been renamed to QgsColorButton. Hence, QgsColorButtonV2 does not exist anymore.
46+
<li>QgsColorbutton was removed. QgsColorButtonV2 has now been renamed to QgsColorButton. Hence, QgsColorButtonV2 does not exist anymore.</li>
47+
<li>QgsColorDialog was removed, and QgsColorDialogV2 was renamed to QgsColorDialog. Hence, QgsColorButtonV2 does not exist anymore.
48+
All the functionality from the old QgsColorDialog has been moved to the new class.</li>
4749
<li>QgsCRSCache was removed. QgsCoordinateReferenceSystem now internally uses a cache for CRS creation,
4850
so there is no longer a need for the separate cache class. Code which previously called QgsCRSCache::updateCRSCache()
4951
should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinateTransformCache::instance()->invalidateCrs( authid ).</li>

python/gui/qgscolordialog.sip

+3-33
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,12 @@
11

22
/** \ingroup gui
33
* \class QgsColorDialog
4-
* A dialog for selecting a color
5-
*/
6-
7-
class QgsColorDialog : QObject
8-
{
9-
%TypeHeaderCode
10-
#include <qgscolordialog.h>
11-
%End
12-
public:
13-
QgsColorDialog();
14-
~QgsColorDialog();
15-
16-
/** Return a color selection from a QColorDialog, with live updating of interim selections.
17-
* @param initialColor The initial color of the selection dialog.
18-
* @param updateObject The receiver object of the live updating.
19-
* @param updateSlot The receiver object's slot for live updating (e.g. SLOT( setValidColor( const QColor& ) ) ).
20-
* @param parent Parent widget. Usually 0 is best for native system color dialogs.
21-
* @param title The title of the QColorDialog.
22-
* @param options ColorDialogOptions passed to QColorDialog.
23-
* @return Selected color on accepted() or initialColor on rejected().
24-
*/
25-
static QColor getLiveColor( const QColor& initialColor, QObject* updateObject, const char* updateSlot,
26-
QWidget* parent = 0,
27-
const QString& title = "",
28-
const QColorDialog::ColorDialogOptions& options = 0 );
29-
};
30-
31-
32-
/** \ingroup gui
33-
* \class QgsColorDialogV2
344
* A custom QGIS dialog for selecting a color. Has many improvements over the standard Qt color picker dialog, including
355
* hue wheel supports, color swatches, and a color sampler.
366
* \note Added in version 2.5
377
*/
388

39-
class QgsColorDialogV2 : QDialog
9+
class QgsColorDialog : QDialog
4010
{
4111
%TypeHeaderCode
4212
#include <qgscolordialog.h>
@@ -49,10 +19,10 @@ class QgsColorDialogV2 : QDialog
4919
* @param fl window flags
5020
* @param color initial color for dialog
5121
*/
52-
QgsColorDialogV2( QWidget *parent /TransferThis/ = 0, const Qt::WindowFlags& fl = QgisGui::ModalDialogFlags,
22+
QgsColorDialog( QWidget *parent /TransferThis/ = 0, const Qt::WindowFlags& fl = QgisGui::ModalDialogFlags,
5323
const QColor& color = QColor() );
5424

55-
~QgsColorDialogV2();
25+
~QgsColorDialog();
5626

5727
/** Returns the current color for the dialog
5828
* @returns dialog color

src/app/qgsdiagramproperties.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ void QgsDiagramProperties::on_mDiagramAttributesTreeWidget_itemDoubleClicked( QT
609609
{
610610
if ( column == 1 ) //change color
611611
{
612-
QColor newColor = QgsColorDialogV2::getColor( item->background( 1 ).color(), nullptr );
612+
QColor newColor = QgsColorDialog::getColor( item->background( 1 ).color(), nullptr );
613613
if ( newColor.isValid() )
614614
{
615615
item->setBackground( 1, QBrush( newColor ) );

src/app/qgsoptions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2152,7 +2152,7 @@ void QgsOptions::saveDefaultDatumTransformations()
21522152

21532153
void QgsOptions::on_mButtonAddColor_clicked()
21542154
{
2155-
QColor newColor = QgsColorDialogV2::getColor( QColor(), this->parentWidget(), tr( "Select color" ), true );
2155+
QColor newColor = QgsColorDialog::getColor( QColor(), this->parentWidget(), tr( "Select color" ), true );
21562156
if ( !newColor.isValid() )
21572157
{
21582158
return;

src/app/qgsprojectproperties.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@ void QgsProjectProperties::projectionSelectorInitialized()
20202020

20212021
void QgsProjectProperties::on_mButtonAddColor_clicked()
20222022
{
2023-
QColor newColor = QgsColorDialogV2::getColor( QColor(), this->parentWidget(), tr( "Select Color" ), true );
2023+
QColor newColor = QgsColorDialog::getColor( QColor(), this->parentWidget(), tr( "Select Color" ), true );
20242024
if ( !newColor.isValid() )
20252025
{
20262026
return;

src/gui/qgscolorbutton.cpp

+11-21
Original file line numberDiff line numberDiff line change
@@ -97,35 +97,25 @@ void QgsColorButton::showColorDialog()
9797
QColor newColor;
9898
QSettings settings;
9999

100-
//using native color dialogs?
101-
bool useNative = settings.value( "/qgis/native_color_dialogs", false ).toBool();
102-
103-
if ( useNative )
100+
if ( mAcceptLiveUpdates && settings.value( "/qgis/live_color_dialogs", false ).toBool() )
104101
{
105-
// use native o/s dialogs
106-
if ( mAcceptLiveUpdates && settings.value( "/qgis/live_color_dialogs", false ).toBool() )
107-
{
108-
newColor = QgsColorDialog::getLiveColor(
109-
color(), this, SLOT( setValidColor( const QColor& ) ),
110-
this->parentWidget(), mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
111-
}
112-
else
113-
{
114-
newColor = QColorDialog::getColor( color(), this->parentWidget(), mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
115-
}
102+
// live updating dialog - QgsColorDialog will automatically use native dialog if option is set
103+
newColor = QgsColorDialog::getLiveColor(
104+
color(), this, SLOT( setValidColor( const QColor& ) ),
105+
this, mColorDialogTitle, mAllowAlpha );
116106
}
117107
else
118108
{
119-
//use QGIS style color dialogs
120-
if ( mAcceptLiveUpdates && settings.value( "/qgis/live_color_dialogs", false ).toBool() )
109+
// not using live updating dialog - first check if we need to use the limited native dialogs
110+
bool useNative = settings.value( "/qgis/native_color_dialogs", false ).toBool();
111+
if ( useNative )
121112
{
122-
newColor = QgsColorDialogV2::getLiveColor(
123-
color(), this, SLOT( setValidColor( const QColor& ) ),
124-
this->parentWidget(), mColorDialogTitle, mAllowAlpha );
113+
// why would anyone want this? who knows.... maybe the limited nature of native dialogs helps ease the transition for MapInfo users?
114+
newColor = QColorDialog::getColor( color(), this, mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
125115
}
126116
else
127117
{
128-
QgsColorDialogV2 dialog( this, 0, color() );
118+
QgsColorDialog dialog( this, 0, color() );
129119
dialog.setTitle( mColorDialogTitle );
130120
dialog.setAllowAlpha( mAllowAlpha );
131121

src/gui/qgscolordialog.cpp

+47-61
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,7 @@
3030
#include <QMouseEvent>
3131
#include <QInputDialog>
3232

33-
QgsColorDialog::QgsColorDialog()
34-
{
35-
}
36-
37-
QgsColorDialog::~QgsColorDialog()
38-
{
39-
}
40-
41-
QColor QgsColorDialog::getLiveColor( const QColor& initialColor, QObject* updateObject, const char* updateSlot,
42-
QWidget* parent,
43-
const QString& title,
44-
const QColorDialog::ColorDialogOptions& options )
45-
{
46-
QColor returnColor( initialColor );
47-
QColorDialog* liveDialog = new QColorDialog( initialColor, parent );
48-
liveDialog->setWindowTitle( title.isEmpty() ? tr( "Select Color" ) : title );
49-
liveDialog->setOptions( options );
50-
51-
connect( liveDialog, SIGNAL( currentColorChanged( const QColor& ) ),
52-
updateObject, updateSlot );
53-
54-
if ( liveDialog->exec() )
55-
{
56-
returnColor = liveDialog->currentColor();
57-
}
58-
delete liveDialog;
59-
liveDialog = nullptr;
60-
61-
return returnColor;
62-
}
63-
64-
65-
//
66-
// QgsColorDialogV2
67-
//
68-
69-
QgsColorDialogV2::QgsColorDialogV2( QWidget *parent, Qt::WindowFlags fl, const QColor& color )
33+
QgsColorDialog::QgsColorDialog( QWidget *parent, Qt::WindowFlags fl, const QColor& color )
7034
: QDialog( parent, fl )
7135
, mPreviousColor( color )
7236
, mAllowAlpha( true )
@@ -93,51 +57,73 @@ QgsColorDialogV2::QgsColorDialogV2( QWidget *parent, Qt::WindowFlags fl, const Q
9357
connect( mColorWidget, SIGNAL( currentColorChanged( QColor ) ), this, SIGNAL( currentColorChanged( QColor ) ) );
9458
}
9559

96-
QgsColorDialogV2::~QgsColorDialogV2()
60+
QgsColorDialog::~QgsColorDialog()
9761
{
9862

9963
}
10064

101-
QColor QgsColorDialogV2::color() const
65+
QColor QgsColorDialog::color() const
10266
{
10367
return mColorWidget->color();
10468
}
10569

106-
void QgsColorDialogV2::setTitle( const QString& title )
70+
void QgsColorDialog::setTitle( const QString& title )
10771
{
10872
setWindowTitle( title.isEmpty() ? tr( "Select Color" ) : title );
10973
}
11074

111-
void QgsColorDialogV2::setAllowAlpha( const bool allowAlpha )
75+
void QgsColorDialog::setAllowAlpha( const bool allowAlpha )
11276
{
11377
mAllowAlpha = allowAlpha;
11478
mColorWidget->setAllowAlpha( allowAlpha );
11579
}
11680

117-
QColor QgsColorDialogV2::getLiveColor( const QColor &initialColor, QObject *updateObject, const char *updateSlot, QWidget *parent, const QString &title, const bool allowAlpha )
81+
QColor QgsColorDialog::getLiveColor( const QColor &initialColor, QObject *updateObject, const char *updateSlot, QWidget *parent, const QString &title, const bool allowAlpha )
11882
{
11983
QColor returnColor( initialColor );
120-
QgsColorDialogV2* liveDialog = new QgsColorDialogV2( parent, 0, initialColor );
121-
liveDialog->setWindowTitle( title.isEmpty() ? tr( "Select Color" ) : title );
122-
if ( !allowAlpha )
84+
85+
QSettings settings;
86+
87+
//using native color dialogs?
88+
bool useNative = settings.value( "/qgis/native_color_dialogs", false ).toBool();
89+
if ( useNative )
12390
{
124-
liveDialog->setAllowAlpha( false );
125-
}
91+
QColorDialog* liveDialog = new QColorDialog( initialColor, parent );
92+
liveDialog->setWindowTitle( title.isEmpty() ? tr( "Select Color" ) : title );
93+
liveDialog->setOptions( allowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
12694

127-
connect( liveDialog, SIGNAL( currentColorChanged( const QColor& ) ),
128-
updateObject, updateSlot );
95+
connect( liveDialog, SIGNAL( currentColorChanged( const QColor& ) ),
96+
updateObject, updateSlot );
12997

130-
if ( liveDialog->exec() )
98+
if ( liveDialog->exec() )
99+
{
100+
returnColor = liveDialog->currentColor();
101+
}
102+
delete liveDialog;
103+
}
104+
else
131105
{
132-
returnColor = liveDialog->color();
106+
QgsColorDialog* liveDialog = new QgsColorDialog( parent, 0, initialColor );
107+
liveDialog->setWindowTitle( title.isEmpty() ? tr( "Select Color" ) : title );
108+
if ( !allowAlpha )
109+
{
110+
liveDialog->setAllowAlpha( false );
111+
}
112+
113+
connect( liveDialog, SIGNAL( currentColorChanged( const QColor& ) ),
114+
updateObject, updateSlot );
115+
116+
if ( liveDialog->exec() )
117+
{
118+
returnColor = liveDialog->color();
119+
}
120+
delete liveDialog;
133121
}
134-
delete liveDialog;
135-
liveDialog = nullptr;
136122

137123
return returnColor;
138124
}
139125

140-
QColor QgsColorDialogV2::getColor( const QColor &initialColor, QWidget *parent, const QString &title, const bool allowAlpha )
126+
QColor QgsColorDialog::getColor( const QColor &initialColor, QWidget *parent, const QString &title, const bool allowAlpha )
141127
{
142128
QString dialogTitle = title.isEmpty() ? tr( "Select Color" ) : title;
143129

@@ -150,7 +136,7 @@ QColor QgsColorDialogV2::getColor( const QColor &initialColor, QWidget *parent,
150136
}
151137
else
152138
{
153-
QgsColorDialogV2* dialog = new QgsColorDialogV2( parent, 0, initialColor );
139+
QgsColorDialog* dialog = new QgsColorDialog( parent, 0, initialColor );
154140
dialog->setWindowTitle( dialogTitle );
155141
dialog->setAllowAlpha( allowAlpha );
156142

@@ -168,33 +154,33 @@ QColor QgsColorDialogV2::getColor( const QColor &initialColor, QWidget *parent,
168154
}
169155
}
170156

171-
void QgsColorDialogV2::on_mButtonBox_accepted()
157+
void QgsColorDialog::on_mButtonBox_accepted()
172158
{
173159
saveSettings();
174160
accept();
175161
}
176162

177-
void QgsColorDialogV2::on_mButtonBox_rejected()
163+
void QgsColorDialog::on_mButtonBox_rejected()
178164
{
179165
saveSettings();
180166
reject();
181167
}
182168

183-
void QgsColorDialogV2::on_mButtonBox_clicked( QAbstractButton * button )
169+
void QgsColorDialog::on_mButtonBox_clicked( QAbstractButton * button )
184170
{
185171
if ( mButtonBox->buttonRole( button ) == QDialogButtonBox::ResetRole && mPreviousColor.isValid() )
186172
{
187173
setColor( mPreviousColor );
188174
}
189175
}
190176

191-
void QgsColorDialogV2::saveSettings()
177+
void QgsColorDialog::saveSettings()
192178
{
193179
QSettings settings;
194180
settings.setValue( "/Windows/ColorDialog/geometry", saveGeometry() );
195181
}
196182

197-
void QgsColorDialogV2::setColor( const QColor &color )
183+
void QgsColorDialog::setColor( const QColor &color )
198184
{
199185
if ( !color.isValid() )
200186
{
@@ -212,7 +198,7 @@ void QgsColorDialogV2::setColor( const QColor &color )
212198
emit currentColorChanged( fixedColor );
213199
}
214200

215-
void QgsColorDialogV2::closeEvent( QCloseEvent *e )
201+
void QgsColorDialog::closeEvent( QCloseEvent *e )
216202
{
217203
saveSettings();
218204
QDialog::closeEvent( e );

src/gui/qgscolordialog.h

+4-33
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,12 @@ class QColor;
2424

2525
/** \ingroup gui
2626
* \class QgsColorDialog
27-
* A native operating system dialog for selecting a color
28-
*/
29-
30-
class GUI_EXPORT QgsColorDialog : public QObject
31-
{
32-
Q_OBJECT
33-
34-
public:
35-
QgsColorDialog();
36-
~QgsColorDialog();
37-
38-
/** Return a color selection from a QColorDialog, with live updating of interim selections.
39-
* @param initialColor The initial color of the selection dialog.
40-
* @param updateObject The receiver object of the live updating.
41-
* @param updateSlot The receiver object's slot for live updating (e.g. SLOT( setValidColor( const QColor& ) ) ).
42-
* @param parent Parent widget. Usually 0 is best for native system color dialogs.
43-
* @param title The title of the QColorDialog.
44-
* @param options ColorDialogOptions passed to QColorDialog.
45-
* @return Selected color on accepted() or initialColor on rejected().
46-
*/
47-
static QColor getLiveColor( const QColor& initialColor, QObject* updateObject, const char* updateSlot,
48-
QWidget* parent = nullptr,
49-
const QString& title = "",
50-
const QColorDialog::ColorDialogOptions& options = 0 );
51-
};
52-
53-
54-
/** \ingroup gui
55-
* \class QgsColorDialogV2
5627
* A custom QGIS dialog for selecting a color. Has many improvements over the standard Qt color picker dialog, including
5728
* hue wheel supports, color swatches, and a color sampler.
5829
* \note Added in version 2.5
5930
*/
6031

61-
class GUI_EXPORT QgsColorDialogV2 : public QDialog, private Ui::QgsColorDialogBase
32+
class GUI_EXPORT QgsColorDialog : public QDialog, private Ui::QgsColorDialogBase
6233
{
6334

6435
Q_OBJECT
@@ -70,10 +41,10 @@ class GUI_EXPORT QgsColorDialogV2 : public QDialog, private Ui::QgsColorDialogBa
7041
* @param fl window flags
7142
* @param color initial color for dialog
7243
*/
73-
QgsColorDialogV2( QWidget *parent = nullptr, Qt::WindowFlags fl = QgisGui::ModalDialogFlags,
74-
const QColor& color = QColor() );
44+
QgsColorDialog( QWidget *parent = nullptr, Qt::WindowFlags fl = QgisGui::ModalDialogFlags,
45+
const QColor& color = QColor() );
7546

76-
~QgsColorDialogV2();
47+
~QgsColorDialog();
7748

7849
/** Returns the current color for the dialog
7950
* @returns dialog color

0 commit comments

Comments
 (0)