Skip to content

Commit 31e1661

Browse files
committed
Ensure that colors are always added to recent color list from style panel
1 parent 5b6bf82 commit 31e1661

7 files changed

+28
-13
lines changed

python/gui/qgscompoundcolorwidget.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ class QgsCompoundColorWidget : QgsPanelWidget
4141
*/
4242
void setAllowAlpha( const bool allowAlpha );
4343

44+
/** Sets whether the widget's color has been "discarded" and the selected color should not
45+
* be stored in the recent color list.
46+
* @param discarded set to true to avoid adding color to recent color list on widget destruction.
47+
* @note added in QGIS 3.0
48+
*/
49+
void setDiscarded( bool discarded );
50+
4451
signals:
4552

4653
/** Emitted when the dialog's color changes

src/gui/qgscolorbutton.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ void QgsColorButton::showColorDialog()
101101
colorWidget->setPanelTitle( mColorDialogTitle );
102102
colorWidget->setAllowAlpha( mAllowAlpha );
103103
connect( colorWidget, SIGNAL( currentColorChanged( QColor ) ), this, SLOT( setValidTemporaryColor( QColor ) ) );
104-
connect( colorWidget, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( panelAccepted( QgsPanelWidget* ) ) );
105104
panel->openPanel( colorWidget );
106105
return;
107106
}
@@ -141,7 +140,6 @@ void QgsColorButton::showColorDialog()
141140
if ( newColor.isValid() )
142141
{
143142
setValidColor( newColor );
144-
addRecentColor( newColor );
145143
}
146144

147145
// reactivate button's window
@@ -378,14 +376,6 @@ void QgsColorButton::setValidTemporaryColor( const QColor& newColor )
378376
}
379377
}
380378

381-
void QgsColorButton::panelAccepted( QgsPanelWidget* widget )
382-
{
383-
if ( QgsCompoundColorWidget* colorWidget = qobject_cast< QgsCompoundColorWidget* >( widget ) )
384-
{
385-
addRecentColor( colorWidget->color() );
386-
}
387-
}
388-
389379
QPixmap QgsColorButton::createMenuIcon( const QColor &color, const bool showChecks )
390380
{
391381
//create an icon pixmap

src/gui/qgscolorbutton.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,6 @@ class GUI_EXPORT QgsColorButton : public QToolButton
425425
*/
426426
void setValidTemporaryColor( const QColor& newColor );
427427

428-
//! Called when a color widget panel is accepted, and adds the final color to the recent colors list
429-
void panelAccepted( QgsPanelWidget* widget );
430-
431428
/** Adds a color to the recent colors list
432429
* @param color to add to recent colors list
433430
*/

src/gui/qgscolordialog.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ QgsColorDialog::QgsColorDialog( QWidget *parent, Qt::WindowFlags fl, const QColo
5555
mColorWidget->setAllowAlpha( true );
5656

5757
connect( mColorWidget, SIGNAL( currentColorChanged( QColor ) ), this, SIGNAL( currentColorChanged( QColor ) ) );
58+
connect( this, SIGNAL( rejected() ), this, SLOT( discardColor() ) );
5859
}
5960

6061
QgsColorDialog::~QgsColorDialog()
@@ -174,6 +175,11 @@ void QgsColorDialog::on_mButtonBox_clicked( QAbstractButton * button )
174175
}
175176
}
176177

178+
void QgsColorDialog::discardColor()
179+
{
180+
mColorWidget->setDiscarded( true );
181+
}
182+
177183
void QgsColorDialog::saveSettings()
178184
{
179185
QSettings settings;

src/gui/qgscolordialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class GUI_EXPORT QgsColorDialog : public QDialog, private Ui::QgsColorDialogBase
111111
void on_mButtonBox_accepted();
112112
void on_mButtonBox_rejected();
113113
void on_mButtonBox_clicked( QAbstractButton * button );
114+
void discardColor();
114115

115116
private:
116117

src/gui/qgscompoundcolorwidget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor& c
3535
, mAllowAlpha( true )
3636
, mLastCustomColorIndex( 0 )
3737
, mPickingColor( false )
38+
, mDiscarded( false )
3839
{
3940
setupUi( this );
4041

@@ -240,6 +241,10 @@ QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor& c
240241
QgsCompoundColorWidget::~QgsCompoundColorWidget()
241242
{
242243
saveSettings();
244+
if ( !mDiscarded )
245+
{
246+
QgsRecentColorScheme::addRecentColor( color() );
247+
}
243248
}
244249

245250
QColor QgsCompoundColorWidget::color() const

src/gui/qgscompoundcolorwidget.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ class GUI_EXPORT QgsCompoundColorWidget : public QgsPanelWidget, private Ui::Qgs
6161
*/
6262
void setAllowAlpha( const bool allowAlpha );
6363

64+
/** Sets whether the widget's color has been "discarded" and the selected color should not
65+
* be stored in the recent color list.
66+
* @param discarded set to true to avoid adding color to recent color list on widget destruction.
67+
* @note added in QGIS 3.0
68+
*/
69+
void setDiscarded( bool discarded ) { mDiscarded = discarded; }
70+
6471
signals:
6572

6673
/** Emitted when the dialog's color changes
@@ -125,6 +132,8 @@ class GUI_EXPORT QgsCompoundColorWidget : public QgsPanelWidget, private Ui::Qgs
125132

126133
bool mPickingColor;
127134

135+
bool mDiscarded;
136+
128137
/** Saves all widget settings
129138
*/
130139
void saveSettings();

0 commit comments

Comments
 (0)