Skip to content

Commit

Permalink
Hide color schemes from color button menu if they contain no colors
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 14, 2014
1 parent 11686c7 commit b3dbe74
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/gui/qgscolorswatchgrid.sip
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class QgsColorSwatchGrid: QWidget
* @see baseColor
*/
void setBaseColor( const QColor baseColor );

/**Gets the list of colors shown in the grid
* @returns list of colors currently shown in the grid
*/
QgsNamedColorList* colors();

public slots:

Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgscolorswatchgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,15 @@ QgsColorSwatchGridAction::QgsColorSwatchGridAction( QgsColorScheme* scheme, QMen
, mSuppressRecurse( false )
{
mColorSwatchGrid = new QgsColorSwatchGrid( scheme, context, parent );

setDefaultWidget( mColorSwatchGrid );
connect( mColorSwatchGrid, SIGNAL( colorChanged( QColor ) ), this, SLOT( setColor( QColor ) ) );

connect( this, SIGNAL( hovered() ), this, SLOT( onHover() ) );
connect( mColorSwatchGrid, SIGNAL( hovered() ), this, SLOT( onHover() ) );

//hide the action if no colors to be shown
setVisible( mColorSwatchGrid->colors()->count() > 0 );
}

QgsColorSwatchGridAction::~QgsColorSwatchGridAction()
Expand Down Expand Up @@ -370,6 +374,8 @@ void QgsColorSwatchGridAction::setContext( const QString context )
void QgsColorSwatchGridAction::refreshColors()
{
mColorSwatchGrid->refreshColors();
//hide the action if no colors shown
setVisible( mColorSwatchGrid->colors()->count() > 0 );
}

void QgsColorSwatchGridAction::setColor( const QColor &color )
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgscolorswatchgrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class GUI_EXPORT QgsColorSwatchGrid: public QWidget
*/
void setBaseColor( const QColor baseColor );

/**Gets the list of colors shown in the grid
* @returns list of colors currently shown in the grid
*/
QgsNamedColorList* colors() { return &mColors; }

public slots:

/**Reload colors from scheme and redraws the widget
Expand Down

0 comments on commit b3dbe74

Please sign in to comment.