Skip to content

Commit

Permalink
Add method to hide favorites and smart groups from style manager dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 16, 2019
1 parent ec8b299 commit 42a7804
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 17 deletions.
14 changes: 14 additions & 0 deletions python/gui/auto_generated/symbology/qgsstylemanagerdialog.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ The ``style`` object must last for the lifetime of the dialog.
QString RampType = QString() );
%Docstring
Opens the add color ramp dialog, returning the new color ramp's name if the ramp has been added.
%End

void setFavoritesGroupVisible( bool show );
%Docstring
Sets whether the favorites group should be shown. The default is to show the group.

.. versionadded:: 3.6
%End

void setSmartGroupsVisible( bool show );
%Docstring
Sets whether smart groups should be shown. The default is to show the groups.

.. versionadded:: 3.6
%End

public slots:
Expand Down
54 changes: 37 additions & 17 deletions src/gui/symbology/qgsstylemanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,18 @@ QString QgsStyleManagerDialog::addColorRampStatic( QWidget *parent, QgsStyle *st
return name;
}

void QgsStyleManagerDialog::setFavoritesGroupVisible( bool show )
{
mFavoritesGroupVisible = show;
populateGroups();
}

void QgsStyleManagerDialog::setSmartGroupsVisible( bool show )
{
mSmartGroupVisible = show;
populateGroups();
}

void QgsStyleManagerDialog::activate()
{
raise();
Expand Down Expand Up @@ -1015,11 +1027,14 @@ void QgsStyleManagerDialog::populateGroups()
QStandardItemModel *model = qobject_cast<QStandardItemModel *>( groupTree->model() );
model->clear();

QStandardItem *favoriteSymbols = new QStandardItem( tr( "Favorites" ) );
favoriteSymbols->setData( "favorite" );
favoriteSymbols->setEditable( false );
setBold( favoriteSymbols );
model->appendRow( favoriteSymbols );
if ( mFavoritesGroupVisible )
{
QStandardItem *favoriteSymbols = new QStandardItem( tr( "Favorites" ) );
favoriteSymbols->setData( "favorite" );
favoriteSymbols->setEditable( false );
setBold( favoriteSymbols );
model->appendRow( favoriteSymbols );
}

QStandardItem *allSymbols = new QStandardItem( tr( "All" ) );
allSymbols->setData( "all" );
Expand All @@ -1036,26 +1051,31 @@ void QgsStyleManagerDialog::populateGroups()
{
QStandardItem *item = new QStandardItem( tag );
item->setData( mStyle->tagId( tag ) );
item->setEditable( !mReadOnly );
taggroup->appendRow( item );
}
taggroup->setText( tr( "Tags" ) );//set title later
setBold( taggroup );
model->appendRow( taggroup );

QStandardItem *smart = new QStandardItem( tr( "Smart Groups" ) );
smart->setData( "smartgroups" );
smart->setEditable( false );
setBold( smart );
QgsSymbolGroupMap sgMap = mStyle->smartgroupsListMap();
QgsSymbolGroupMap::const_iterator i = sgMap.constBegin();
while ( i != sgMap.constEnd() )
if ( mSmartGroupVisible )
{
QStandardItem *item = new QStandardItem( i.value() );
item->setData( i.key() );
smart->appendRow( item );
++i;
QStandardItem *smart = new QStandardItem( tr( "Smart Groups" ) );
smart->setData( "smartgroups" );
smart->setEditable( false );
setBold( smart );
QgsSymbolGroupMap sgMap = mStyle->smartgroupsListMap();
QgsSymbolGroupMap::const_iterator i = sgMap.constBegin();
while ( i != sgMap.constEnd() )
{
QStandardItem *item = new QStandardItem( i.value() );
item->setData( i.key() );
item->setEditable( !mReadOnly );
smart->appendRow( item );
++i;
}
model->appendRow( smart );
}
model->appendRow( smart );

// expand things in the group tree
int rows = model->rowCount( model->indexFromItem( model->invisibleRootItem() ) );
Expand Down
14 changes: 14 additions & 0 deletions src/gui/symbology/qgsstylemanagerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan
static QString addColorRampStatic( QWidget *parent, QgsStyle *style,
QString RampType = QString() );

/**
* Sets whether the favorites group should be shown. The default is to show the group.
*
* \since QGIS 3.6
*/
void setFavoritesGroupVisible( bool show );

/**
* Sets whether smart groups should be shown. The default is to show the groups.
*
* \since QGIS 3.6
*/
void setSmartGroupsVisible( bool show );

public slots:

// TODO QGIS 4.0 -- most of this should be private
Expand Down

0 comments on commit 42a7804

Please sign in to comment.