Add method to hide favorites and smart groups from style manager dialog

This commit is contained in:
Nyall Dawson 2019-01-15 10:32:16 +10:00
parent ec8b299b9b
commit 42a7804323
3 changed files with 65 additions and 17 deletions

View File

@ -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:

View File

@ -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();
@ -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" );
@ -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() ) );

View File

@ -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