Skip to content

Commit

Permalink
allow to export favorite symbols from style manager (fix #27315)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy authored and nyalldawson committed May 28, 2020
1 parent fcf6203 commit 2fbc2b8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/gui/symbology/qgsstyleexportimportdialog.cpp
Expand Up @@ -258,6 +258,18 @@ void QgsStyleExportImportDialog::clearSelection()
listItems->clearSelection();
}

void QgsStyleExportImportDialog::selectFavorites()
{
QStringList symbolNames = mStyle->symbolsOfFavorite( QgsStyle::SymbolEntity );
selectSymbols( symbolNames );
}

void QgsStyleExportImportDialog::deselectFavorites()
{
QStringList symbolNames = mStyle->symbolsOfFavorite( QgsStyle::SymbolEntity );
deselectSymbols( symbolNames );
}

void QgsStyleExportImportDialog::selectSymbols( const QStringList &symbolNames )
{
const auto constSymbolNames = symbolNames;
Expand Down Expand Up @@ -329,6 +341,8 @@ void QgsStyleExportImportDialog::selectByGroup()
connect( mGroupSelectionDlg, &QgsStyleGroupSelectionDialog::tagDeselected, this, &QgsStyleExportImportDialog::deselectTag );
connect( mGroupSelectionDlg, &QgsStyleGroupSelectionDialog::allSelected, this, &QgsStyleExportImportDialog::selectAll );
connect( mGroupSelectionDlg, &QgsStyleGroupSelectionDialog::allDeselected, this, &QgsStyleExportImportDialog::clearSelection );
connect( mGroupSelectionDlg, &QgsStyleGroupSelectionDialog::favoritesSelected, this, &QgsStyleExportImportDialog::selectFavorites );
connect( mGroupSelectionDlg, &QgsStyleGroupSelectionDialog::favoritesDeselected, this, &QgsStyleExportImportDialog::deselectFavorites );
connect( mGroupSelectionDlg, &QgsStyleGroupSelectionDialog::smartgroupSelected, this, &QgsStyleExportImportDialog::selectSmartgroup );
connect( mGroupSelectionDlg, &QgsStyleGroupSelectionDialog::smartgroupDeselected, this, &QgsStyleExportImportDialog::deselectSmartgroup );
}
Expand Down
12 changes: 12 additions & 0 deletions src/gui/symbology/qgsstyleexportimportdialog.h
Expand Up @@ -96,6 +96,18 @@ class GUI_EXPORT QgsStyleExportImportDialog : public QDialog, private Ui::QgsSty
*/
void clearSelection();

/**
* \brief selectFavorites selects favorite symbols
* \since QGIS 3.14
*/
void selectFavorites();

/**
* \brief deselectFavorites deselects favorite symbols
* \since QGIS 3.14
*/
void deselectFavorites();

/**
* Select the symbols belonging to the given tag
* \param tagName the name of the group to be selected
Expand Down
17 changes: 14 additions & 3 deletions src/gui/symbology/qgsstylegroupselectiondialog.cpp
Expand Up @@ -34,6 +34,12 @@ QgsStyleGroupSelectionDialog::QgsStyleGroupSelectionDialog( QgsStyle *style, QWi
QStandardItemModel *model = new QStandardItemModel( groupTree );
groupTree->setModel( model );

QStandardItem *favSymbols = new QStandardItem( tr( "Favorites" ) );
favSymbols->setData( "favorites", Qt::UserRole + 2 );
favSymbols->setEditable( false );
setBold( favSymbols );
model->appendRow( favSymbols );

QStandardItem *allSymbols = new QStandardItem( tr( "All" ) );
allSymbols->setData( "all", Qt::UserRole + 2 );
allSymbols->setEditable( false );
Expand Down Expand Up @@ -83,7 +89,6 @@ void QgsStyleGroupSelectionDialog::setBold( QStandardItem *item )
item->setFont( font );
}


void QgsStyleGroupSelectionDialog::groupTreeSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
{
const QModelIndexList selectedItems = selected.indexes();
Expand All @@ -95,6 +100,10 @@ void QgsStyleGroupSelectionDialog::groupTreeSelectionChanged( const QItemSelecti
{
// Ignore: it's the group header
}
else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String( "favorites" ) )
{
emit favoritesDeselected();
}
else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String( "all" ) )
{
emit allDeselected();
Expand All @@ -120,6 +129,10 @@ void QgsStyleGroupSelectionDialog::groupTreeSelectionChanged( const QItemSelecti
{
// Ignore: it's the group header
}
else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String( "favorites" ) )
{
emit favoritesSelected();
}
else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String( "all" ) )
{
emit allSelected();
Expand All @@ -140,7 +153,6 @@ void QgsStyleGroupSelectionDialog::groupTreeSelectionChanged( const QItemSelecti
}
}


void QgsStyleGroupSelectionDialog::buildTagTree( QStandardItem *&parent )
{
QStringList tags = mStyle->tags();
Expand All @@ -155,4 +167,3 @@ void QgsStyleGroupSelectionDialog::buildTagTree( QStandardItem *&parent )
parent->appendRow( item );
}
}

8 changes: 8 additions & 0 deletions src/gui/symbology/qgsstylegroupselectiondialog.h
Expand Up @@ -51,6 +51,14 @@ class GUI_EXPORT QgsStyleGroupSelectionDialog : public QDialog, private Ui::Symb
void allDeselected();
//! all selected
void allSelected();
/** favorites has been deselected
* \since QGIS 3.14
*/
void favoritesDeselected();
/** favorites has need selected
* \since QGIS 3.14
*/
void favoritesSelected();

private slots:
void groupTreeSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
Expand Down

0 comments on commit 2fbc2b8

Please sign in to comment.