Skip to content

Commit b3dbe74

Browse files
committedAug 14, 2014
Hide color schemes from color button menu if they contain no colors
1 parent 11686c7 commit b3dbe74

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed
 

‎python/gui/qgscolorswatchgrid.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class QgsColorSwatchGrid: QWidget
5353
* @see baseColor
5454
*/
5555
void setBaseColor( const QColor baseColor );
56+
57+
/**Gets the list of colors shown in the grid
58+
* @returns list of colors currently shown in the grid
59+
*/
60+
QgsNamedColorList* colors();
5661

5762
public slots:
5863

‎src/gui/qgscolorswatchgrid.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,15 @@ QgsColorSwatchGridAction::QgsColorSwatchGridAction( QgsColorScheme* scheme, QMen
335335
, mSuppressRecurse( false )
336336
{
337337
mColorSwatchGrid = new QgsColorSwatchGrid( scheme, context, parent );
338+
338339
setDefaultWidget( mColorSwatchGrid );
339340
connect( mColorSwatchGrid, SIGNAL( colorChanged( QColor ) ), this, SLOT( setColor( QColor ) ) );
340341

341342
connect( this, SIGNAL( hovered() ), this, SLOT( onHover() ) );
342343
connect( mColorSwatchGrid, SIGNAL( hovered() ), this, SLOT( onHover() ) );
344+
345+
//hide the action if no colors to be shown
346+
setVisible( mColorSwatchGrid->colors()->count() > 0 );
343347
}
344348

345349
QgsColorSwatchGridAction::~QgsColorSwatchGridAction()
@@ -370,6 +374,8 @@ void QgsColorSwatchGridAction::setContext( const QString context )
370374
void QgsColorSwatchGridAction::refreshColors()
371375
{
372376
mColorSwatchGrid->refreshColors();
377+
//hide the action if no colors shown
378+
setVisible( mColorSwatchGrid->colors()->count() > 0 );
373379
}
374380

375381
void QgsColorSwatchGridAction::setColor( const QColor &color )

‎src/gui/qgscolorswatchgrid.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ class GUI_EXPORT QgsColorSwatchGrid: public QWidget
7171
*/
7272
void setBaseColor( const QColor baseColor );
7373

74+
/**Gets the list of colors shown in the grid
75+
* @returns list of colors currently shown in the grid
76+
*/
77+
QgsNamedColorList* colors() { return &mColors; }
78+
7479
public slots:
7580

7681
/**Reload colors from scheme and redraws the widget

0 commit comments

Comments
 (0)
Please sign in to comment.