Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove QgsColorDialog, rename QgsColorDialogV2 to QgsColorDialog
The last bits of missing functionality (handling native dialogs
and live updates) were ported across.
  • Loading branch information
nyalldawson committed Aug 6, 2016
1 parent 2893456 commit 26c1e09
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 156 deletions.
4 changes: 3 additions & 1 deletion doc/api_break.dox
Expand Up @@ -43,7 +43,9 @@ This page tries to maintain a list with incompatible changes that happened in pr
\subsection qgis_api_break_3_0_removed_classes Removed Classes

<ul>
<li>QgsColorbutton was removed. QgsColorButtonV2 has now been renamed to QgsColorButton. Hence, QgsColorButtonV2 does not exist anymore.
<li>QgsColorbutton was removed. QgsColorButtonV2 has now been renamed to QgsColorButton. Hence, QgsColorButtonV2 does not exist anymore.</li>
<li>QgsColorDialog was removed, and QgsColorDialogV2 was renamed to QgsColorDialog. Hence, QgsColorButtonV2 does not exist anymore.
All the functionality from the old QgsColorDialog has been moved to the new class.</li>
<li>QgsCRSCache was removed. QgsCoordinateReferenceSystem now internally uses a cache for CRS creation,
so there is no longer a need for the separate cache class. Code which previously called QgsCRSCache::updateCRSCache()
should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinateTransformCache::instance()->invalidateCrs( authid ).</li>
Expand Down
36 changes: 3 additions & 33 deletions python/gui/qgscolordialog.sip
@@ -1,42 +1,12 @@

/** \ingroup gui
* \class QgsColorDialog
* A dialog for selecting a color
*/

class QgsColorDialog : QObject
{
%TypeHeaderCode
#include <qgscolordialog.h>
%End
public:
QgsColorDialog();
~QgsColorDialog();

/** Return a color selection from a QColorDialog, with live updating of interim selections.
* @param initialColor The initial color of the selection dialog.
* @param updateObject The receiver object of the live updating.
* @param updateSlot The receiver object's slot for live updating (e.g. SLOT( setValidColor( const QColor& ) ) ).
* @param parent Parent widget. Usually 0 is best for native system color dialogs.
* @param title The title of the QColorDialog.
* @param options ColorDialogOptions passed to QColorDialog.
* @return Selected color on accepted() or initialColor on rejected().
*/
static QColor getLiveColor( const QColor& initialColor, QObject* updateObject, const char* updateSlot,
QWidget* parent = 0,
const QString& title = "",
const QColorDialog::ColorDialogOptions& options = 0 );
};


/** \ingroup gui
* \class QgsColorDialogV2
* A custom QGIS dialog for selecting a color. Has many improvements over the standard Qt color picker dialog, including
* hue wheel supports, color swatches, and a color sampler.
* \note Added in version 2.5
*/

class QgsColorDialogV2 : QDialog
class QgsColorDialog : QDialog
{
%TypeHeaderCode
#include <qgscolordialog.h>
Expand All @@ -49,10 +19,10 @@ class QgsColorDialogV2 : QDialog
* @param fl window flags
* @param color initial color for dialog
*/
QgsColorDialogV2( QWidget *parent /TransferThis/ = 0, const Qt::WindowFlags& fl = QgisGui::ModalDialogFlags,
QgsColorDialog( QWidget *parent /TransferThis/ = 0, const Qt::WindowFlags& fl = QgisGui::ModalDialogFlags,
const QColor& color = QColor() );

~QgsColorDialogV2();
~QgsColorDialog();

/** Returns the current color for the dialog
* @returns dialog color
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdiagramproperties.cpp
Expand Up @@ -609,7 +609,7 @@ void QgsDiagramProperties::on_mDiagramAttributesTreeWidget_itemDoubleClicked( QT
{
if ( column == 1 ) //change color
{
QColor newColor = QgsColorDialogV2::getColor( item->background( 1 ).color(), nullptr );
QColor newColor = QgsColorDialog::getColor( item->background( 1 ).color(), nullptr );
if ( newColor.isValid() )
{
item->setBackground( 1, QBrush( newColor ) );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsoptions.cpp
Expand Up @@ -2152,7 +2152,7 @@ void QgsOptions::saveDefaultDatumTransformations()

void QgsOptions::on_mButtonAddColor_clicked()
{
QColor newColor = QgsColorDialogV2::getColor( QColor(), this->parentWidget(), tr( "Select color" ), true );
QColor newColor = QgsColorDialog::getColor( QColor(), this->parentWidget(), tr( "Select color" ), true );
if ( !newColor.isValid() )
{
return;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsprojectproperties.cpp
Expand Up @@ -2020,7 +2020,7 @@ void QgsProjectProperties::projectionSelectorInitialized()

void QgsProjectProperties::on_mButtonAddColor_clicked()
{
QColor newColor = QgsColorDialogV2::getColor( QColor(), this->parentWidget(), tr( "Select Color" ), true );
QColor newColor = QgsColorDialog::getColor( QColor(), this->parentWidget(), tr( "Select Color" ), true );
if ( !newColor.isValid() )
{
return;
Expand Down
32 changes: 11 additions & 21 deletions src/gui/qgscolorbutton.cpp
Expand Up @@ -97,35 +97,25 @@ void QgsColorButton::showColorDialog()
QColor newColor;
QSettings settings;

//using native color dialogs?
bool useNative = settings.value( "/qgis/native_color_dialogs", false ).toBool();

if ( useNative )
if ( mAcceptLiveUpdates && settings.value( "/qgis/live_color_dialogs", false ).toBool() )
{
// use native o/s dialogs
if ( mAcceptLiveUpdates && settings.value( "/qgis/live_color_dialogs", false ).toBool() )
{
newColor = QgsColorDialog::getLiveColor(
color(), this, SLOT( setValidColor( const QColor& ) ),
this->parentWidget(), mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
}
else
{
newColor = QColorDialog::getColor( color(), this->parentWidget(), mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
}
// live updating dialog - QgsColorDialog will automatically use native dialog if option is set
newColor = QgsColorDialog::getLiveColor(
color(), this, SLOT( setValidColor( const QColor& ) ),
this, mColorDialogTitle, mAllowAlpha );
}
else
{
//use QGIS style color dialogs
if ( mAcceptLiveUpdates && settings.value( "/qgis/live_color_dialogs", false ).toBool() )
// not using live updating dialog - first check if we need to use the limited native dialogs
bool useNative = settings.value( "/qgis/native_color_dialogs", false ).toBool();
if ( useNative )
{
newColor = QgsColorDialogV2::getLiveColor(
color(), this, SLOT( setValidColor( const QColor& ) ),
this->parentWidget(), mColorDialogTitle, mAllowAlpha );
// why would anyone want this? who knows.... maybe the limited nature of native dialogs helps ease the transition for MapInfo users?
newColor = QColorDialog::getColor( color(), this, mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
}
else
{
QgsColorDialogV2 dialog( this, 0, color() );
QgsColorDialog dialog( this, 0, color() );
dialog.setTitle( mColorDialogTitle );
dialog.setAllowAlpha( mAllowAlpha );

Expand Down
108 changes: 47 additions & 61 deletions src/gui/qgscolordialog.cpp
Expand Up @@ -30,43 +30,7 @@
#include <QMouseEvent>
#include <QInputDialog>

QgsColorDialog::QgsColorDialog()
{
}

QgsColorDialog::~QgsColorDialog()
{
}

QColor QgsColorDialog::getLiveColor( const QColor& initialColor, QObject* updateObject, const char* updateSlot,
QWidget* parent,
const QString& title,
const QColorDialog::ColorDialogOptions& options )
{
QColor returnColor( initialColor );
QColorDialog* liveDialog = new QColorDialog( initialColor, parent );
liveDialog->setWindowTitle( title.isEmpty() ? tr( "Select Color" ) : title );
liveDialog->setOptions( options );

connect( liveDialog, SIGNAL( currentColorChanged( const QColor& ) ),
updateObject, updateSlot );

if ( liveDialog->exec() )
{
returnColor = liveDialog->currentColor();
}
delete liveDialog;
liveDialog = nullptr;

return returnColor;
}


//
// QgsColorDialogV2
//

QgsColorDialogV2::QgsColorDialogV2( QWidget *parent, Qt::WindowFlags fl, const QColor& color )
QgsColorDialog::QgsColorDialog( QWidget *parent, Qt::WindowFlags fl, const QColor& color )
: QDialog( parent, fl )
, mPreviousColor( color )
, mAllowAlpha( true )
Expand All @@ -93,51 +57,73 @@ QgsColorDialogV2::QgsColorDialogV2( QWidget *parent, Qt::WindowFlags fl, const Q
connect( mColorWidget, SIGNAL( currentColorChanged( QColor ) ), this, SIGNAL( currentColorChanged( QColor ) ) );
}

QgsColorDialogV2::~QgsColorDialogV2()
QgsColorDialog::~QgsColorDialog()
{

}

QColor QgsColorDialogV2::color() const
QColor QgsColorDialog::color() const
{
return mColorWidget->color();
}

void QgsColorDialogV2::setTitle( const QString& title )
void QgsColorDialog::setTitle( const QString& title )
{
setWindowTitle( title.isEmpty() ? tr( "Select Color" ) : title );
}

void QgsColorDialogV2::setAllowAlpha( const bool allowAlpha )
void QgsColorDialog::setAllowAlpha( const bool allowAlpha )
{
mAllowAlpha = allowAlpha;
mColorWidget->setAllowAlpha( allowAlpha );
}

QColor QgsColorDialogV2::getLiveColor( const QColor &initialColor, QObject *updateObject, const char *updateSlot, QWidget *parent, const QString &title, const bool allowAlpha )
QColor QgsColorDialog::getLiveColor( const QColor &initialColor, QObject *updateObject, const char *updateSlot, QWidget *parent, const QString &title, const bool allowAlpha )
{
QColor returnColor( initialColor );
QgsColorDialogV2* liveDialog = new QgsColorDialogV2( parent, 0, initialColor );
liveDialog->setWindowTitle( title.isEmpty() ? tr( "Select Color" ) : title );
if ( !allowAlpha )

QSettings settings;

//using native color dialogs?
bool useNative = settings.value( "/qgis/native_color_dialogs", false ).toBool();
if ( useNative )
{
liveDialog->setAllowAlpha( false );
}
QColorDialog* liveDialog = new QColorDialog( initialColor, parent );
liveDialog->setWindowTitle( title.isEmpty() ? tr( "Select Color" ) : title );
liveDialog->setOptions( allowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );

connect( liveDialog, SIGNAL( currentColorChanged( const QColor& ) ),
updateObject, updateSlot );
connect( liveDialog, SIGNAL( currentColorChanged( const QColor& ) ),
updateObject, updateSlot );

if ( liveDialog->exec() )
if ( liveDialog->exec() )
{
returnColor = liveDialog->currentColor();
}
delete liveDialog;
}
else
{
returnColor = liveDialog->color();
QgsColorDialog* liveDialog = new QgsColorDialog( parent, 0, initialColor );
liveDialog->setWindowTitle( title.isEmpty() ? tr( "Select Color" ) : title );
if ( !allowAlpha )
{
liveDialog->setAllowAlpha( false );
}

connect( liveDialog, SIGNAL( currentColorChanged( const QColor& ) ),
updateObject, updateSlot );

if ( liveDialog->exec() )
{
returnColor = liveDialog->color();
}
delete liveDialog;
}
delete liveDialog;
liveDialog = nullptr;

return returnColor;
}

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

Expand All @@ -150,7 +136,7 @@ QColor QgsColorDialogV2::getColor( const QColor &initialColor, QWidget *parent,
}
else
{
QgsColorDialogV2* dialog = new QgsColorDialogV2( parent, 0, initialColor );
QgsColorDialog* dialog = new QgsColorDialog( parent, 0, initialColor );
dialog->setWindowTitle( dialogTitle );
dialog->setAllowAlpha( allowAlpha );

Expand All @@ -168,33 +154,33 @@ QColor QgsColorDialogV2::getColor( const QColor &initialColor, QWidget *parent,
}
}

void QgsColorDialogV2::on_mButtonBox_accepted()
void QgsColorDialog::on_mButtonBox_accepted()
{
saveSettings();
accept();
}

void QgsColorDialogV2::on_mButtonBox_rejected()
void QgsColorDialog::on_mButtonBox_rejected()
{
saveSettings();
reject();
}

void QgsColorDialogV2::on_mButtonBox_clicked( QAbstractButton * button )
void QgsColorDialog::on_mButtonBox_clicked( QAbstractButton * button )
{
if ( mButtonBox->buttonRole( button ) == QDialogButtonBox::ResetRole && mPreviousColor.isValid() )
{
setColor( mPreviousColor );
}
}

void QgsColorDialogV2::saveSettings()
void QgsColorDialog::saveSettings()
{
QSettings settings;
settings.setValue( "/Windows/ColorDialog/geometry", saveGeometry() );
}

void QgsColorDialogV2::setColor( const QColor &color )
void QgsColorDialog::setColor( const QColor &color )
{
if ( !color.isValid() )
{
Expand All @@ -212,7 +198,7 @@ void QgsColorDialogV2::setColor( const QColor &color )
emit currentColorChanged( fixedColor );
}

void QgsColorDialogV2::closeEvent( QCloseEvent *e )
void QgsColorDialog::closeEvent( QCloseEvent *e )
{
saveSettings();
QDialog::closeEvent( e );
Expand Down
37 changes: 4 additions & 33 deletions src/gui/qgscolordialog.h
Expand Up @@ -24,41 +24,12 @@ class QColor;

/** \ingroup gui
* \class QgsColorDialog
* A native operating system dialog for selecting a color
*/

class GUI_EXPORT QgsColorDialog : public QObject
{
Q_OBJECT

public:
QgsColorDialog();
~QgsColorDialog();

/** Return a color selection from a QColorDialog, with live updating of interim selections.
* @param initialColor The initial color of the selection dialog.
* @param updateObject The receiver object of the live updating.
* @param updateSlot The receiver object's slot for live updating (e.g. SLOT( setValidColor( const QColor& ) ) ).
* @param parent Parent widget. Usually 0 is best for native system color dialogs.
* @param title The title of the QColorDialog.
* @param options ColorDialogOptions passed to QColorDialog.
* @return Selected color on accepted() or initialColor on rejected().
*/
static QColor getLiveColor( const QColor& initialColor, QObject* updateObject, const char* updateSlot,
QWidget* parent = nullptr,
const QString& title = "",
const QColorDialog::ColorDialogOptions& options = 0 );
};


/** \ingroup gui
* \class QgsColorDialogV2
* A custom QGIS dialog for selecting a color. Has many improvements over the standard Qt color picker dialog, including
* hue wheel supports, color swatches, and a color sampler.
* \note Added in version 2.5
*/

class GUI_EXPORT QgsColorDialogV2 : public QDialog, private Ui::QgsColorDialogBase
class GUI_EXPORT QgsColorDialog : public QDialog, private Ui::QgsColorDialogBase
{

Q_OBJECT
Expand All @@ -70,10 +41,10 @@ class GUI_EXPORT QgsColorDialogV2 : public QDialog, private Ui::QgsColorDialogBa
* @param fl window flags
* @param color initial color for dialog
*/
QgsColorDialogV2( QWidget *parent = nullptr, Qt::WindowFlags fl = QgisGui::ModalDialogFlags,
const QColor& color = QColor() );
QgsColorDialog( QWidget *parent = nullptr, Qt::WindowFlags fl = QgisGui::ModalDialogFlags,
const QColor& color = QColor() );

~QgsColorDialogV2();
~QgsColorDialog();

/** Returns the current color for the dialog
* @returns dialog color
Expand Down

0 comments on commit 26c1e09

Please sign in to comment.