38 #include <QFileDialog> 39 #include <QInputDialog> 40 #include <QMessageBox> 41 #include <QPushButton> 42 #include <QStandardItemModel> 54 QgsCheckableStyleModel::QgsCheckableStyleModel(
QgsStyleModel *sourceModel, QObject *parent,
bool readOnly )
56 , mStyle( sourceModel->style() )
57 , mReadOnly( readOnly )
62 QgsCheckableStyleModel::QgsCheckableStyleModel(
QgsStyle *style, QObject *parent,
bool readOnly )
65 , mReadOnly( readOnly )
69 void QgsCheckableStyleModel::setCheckable(
bool checkable )
71 if ( checkable == mCheckable )
74 mCheckable = checkable;
75 emit dataChanged( index( 0, 0 ), index( rowCount() - 1, 0 ), QVector< int >() << Qt::CheckStateRole );
78 void QgsCheckableStyleModel::setCheckTag(
const QString &tag )
80 if ( tag == mCheckTag )
84 emit dataChanged( index( 0, 0 ), index( rowCount() - 1, 0 ), QVector< int >() << Qt::CheckStateRole );
87 Qt::ItemFlags QgsCheckableStyleModel::flags(
const QModelIndex &index )
const 89 Qt::ItemFlags f = QgsStyleProxyModel::flags( index );
90 if ( !mReadOnly && mCheckable && index.column() == 0 )
91 f |= Qt::ItemIsUserCheckable;
94 f &= ~Qt::ItemIsEditable;
99 QVariant QgsCheckableStyleModel::data(
const QModelIndex &index,
int role )
const 106 QFont f = QgsStyleProxyModel::data( index, role ).value< QFont >();
111 case Qt::CheckStateRole:
113 if ( !mCheckable || index.column() != 0 )
117 return tags.contains( mCheckTag ) ? Qt::Checked : Qt::Unchecked;
124 return QgsStyleProxyModel::data( index, role );
127 bool QgsCheckableStyleModel::setData(
const QModelIndex &i,
const QVariant &value,
int role )
129 if ( i.row() < 0 || i.row() >= rowCount( QModelIndex() ) ||
130 ( role != Qt::EditRole && role != Qt::CheckStateRole ) )
136 if ( role == Qt::CheckStateRole )
138 if ( !mCheckable || mCheckTag.isEmpty() )
141 const QString name = data( index( i.row(),
QgsStyleModel::Name ), Qt::DisplayRole ).toString();
144 if ( value.toInt() == Qt::Checked )
145 return mStyle->
tagSymbol( entity, name, QStringList() << mCheckTag );
147 return mStyle->
detagSymbol( entity, name, QStringList() << mCheckTag );
149 return QgsStyleProxyModel::setData( i, value, role );
160 : QDialog( parent, flags )
162 , mReadOnly( readOnly )
166 connect( tabItemType, &QTabWidget::currentChanged,
this, &QgsStyleManagerDialog::tabItemType_currentChanged );
171 mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
172 mVerticalLayout->insertWidget( 0, mMessageBar );
175 setWindowModality( Qt::WindowModal );
180 mSplitter->setSizes( QList<int>() << 170 << 540 );
181 mSplitter->restoreState( settings.
value( QStringLiteral(
"Windows/StyleV2Manager/splitter" ) ).toByteArray() );
183 tabItemType->setDocumentMode(
true );
184 searchBox->setShowSearchIcon(
true );
185 searchBox->setPlaceholderText( tr(
"Filter symbols…" ) );
189 connect( btnEditItem, &QPushButton::clicked,
this, [ = ](
bool ) {
editItem(); }
191 connect( actnEditItem, &QAction::triggered,
this, [ = ](
bool ) {
editItem(); }
196 connect( btnAddItem, &QPushButton::clicked,
this, [ = ](
bool ) {
addItem(); }
199 connect( btnRemoveItem, &QPushButton::clicked,
this, [ = ](
bool ) {
removeItem(); }
201 connect( actnRemoveItem, &QAction::triggered,
this, [ = ](
bool ) {
removeItem(); }
206 btnAddTag->setEnabled(
false );
207 btnAddSmartgroup->setEnabled(
false );
210 QMenu *shareMenu =
new QMenu( tr(
"Share Menu" ),
this );
211 QAction *exportAction =
new QAction( tr(
"Export Item(s)…" ),
this );
213 shareMenu->addAction( exportAction );
216 QAction *importAction =
new QAction( tr(
"Import Item(s)…" ),
this );
218 shareMenu->addAction( importAction );
223 mActionCopyToDefault =
new QAction( tr(
"Copy Selection to Default Style…" ),
this );
224 shareMenu->addAction( mActionCopyToDefault );
225 connect( mActionCopyToDefault, &QAction::triggered,
this, &QgsStyleManagerDialog::copyItemsToDefault );
226 connect( mCopyToDefaultButton, &QPushButton::clicked,
this, &QgsStyleManagerDialog::copyItemsToDefault );
230 mCopyToDefaultButton->hide();
233 mActionCopyItem =
new QAction( tr(
"Copy Item" ),
this );
234 connect( mActionCopyItem, &QAction::triggered,
this, &QgsStyleManagerDialog::copyItem );
235 mActionPasteItem =
new QAction( tr(
"Paste Item…" ),
this );
236 connect( mActionPasteItem, &QAction::triggered,
this, &QgsStyleManagerDialog::pasteItem );
238 shareMenu->addSeparator();
239 shareMenu->addAction( actnExportAsPNG );
240 shareMenu->addAction( actnExportAsSVG );
245 btnShare->setMenu( shareMenu );
248 listItems->setIconSize( QSize( static_cast< int >( iconSize ), static_cast< int >( iconSize * 0.9 ) ) );
250 mSymbolTreeView->setIconSize( QSize( static_cast< int >( treeIconSize ), static_cast< int >( treeIconSize ) ) );
253 :
new QgsCheckableStyleModel( mStyle,
this, mReadOnly );
254 mModel->addDesiredIconSize( listItems->iconSize() );
255 mModel->addDesiredIconSize( mSymbolTreeView->iconSize() );
256 listItems->setModel( mModel );
257 mSymbolTreeView->setModel( mModel );
259 listItems->setSelectionBehavior( QAbstractItemView::SelectRows );
260 listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
261 mSymbolTreeView->setSelectionModel( listItems->selectionModel() );
262 mSymbolTreeView->setSelectionMode( listItems->selectionMode() );
264 connect( listItems->selectionModel(), &QItemSelectionModel::currentChanged,
266 connect( listItems->selectionModel(), &QItemSelectionModel::selectionChanged,
269 QStandardItemModel *groupModel =
new QStandardItemModel( groupTree );
270 groupTree->setModel( groupModel );
271 groupTree->setHeaderHidden(
true );
273 groupTree->setCurrentIndex( groupTree->model()->index( 0, 0 ) );
275 connect( groupTree->selectionModel(), &QItemSelectionModel::currentChanged,
279 connect( groupModel, &QStandardItemModel::itemChanged,
285 QMenu *groupMenu =
new QMenu( tr(
"Group Actions" ),
this );
287 groupMenu->addAction( actnTagSymbols );
289 actnFinishTagging->setVisible(
false );
290 groupMenu->addAction( actnFinishTagging );
291 groupMenu->addAction( actnEditSmartGroup );
292 btnManageGroups->setMenu( groupMenu );
296 btnManageGroups->setEnabled(
false );
302 groupTree->setContextMenuPolicy( Qt::CustomContextMenu );
303 connect( groupTree, &QWidget::customContextMenuRequested,
307 listItems->setContextMenuPolicy( Qt::CustomContextMenu );
308 connect( listItems, &QWidget::customContextMenuRequested,
310 mSymbolTreeView->setContextMenuPolicy( Qt::CustomContextMenu );
311 connect( mSymbolTreeView, &QWidget::customContextMenuRequested,
317 QStringList rampTypes;
318 rampTypes << tr(
"Gradient…" ) << tr(
"Color presets…" ) << tr(
"Random…" ) << tr(
"Catalog: cpt-city…" );
319 rampTypes << tr(
"Catalog: ColorBrewer…" );
321 mMenuBtnAddItemAll =
new QMenu(
this );
322 mMenuBtnAddItemColorRamp =
new QMenu(
this );
323 mMenuBtnAddItemLabelSettings =
new QMenu(
this );
327 mMenuBtnAddItemAll->addAction( item );
330 mMenuBtnAddItemAll->addAction( item );
333 mMenuBtnAddItemAll->addAction( item );
334 mMenuBtnAddItemAll->addSeparator();
335 for (
const QString &rampType : qgis::as_const( rampTypes ) )
338 connect( item, &QAction::triggered,
this, [ = ](
bool ) {
addColorRamp( item ); } );
339 mMenuBtnAddItemAll->addAction( item );
340 mMenuBtnAddItemColorRamp->addAction(
new QAction( rampType,
this ) );
342 mMenuBtnAddItemAll->addSeparator();
344 connect( item, &QAction::triggered,
this, [ = ](
bool ) { addTextFormat(); } );
345 mMenuBtnAddItemAll->addAction( item );
346 mMenuBtnAddItemAll->addSeparator();
349 mMenuBtnAddItemAll->addAction( item );
350 mMenuBtnAddItemLabelSettings->addAction( item );
353 mMenuBtnAddItemAll->addAction( item );
354 mMenuBtnAddItemLabelSettings->addAction( item );
357 mMenuBtnAddItemAll->addAction( item );
358 mMenuBtnAddItemLabelSettings->addAction( item );
360 connect( mMenuBtnAddItemColorRamp, &QMenu::triggered,
365 mGroupMenu =
new QMenu(
this );
366 mGroupListMenu =
new QMenu( mGroupMenu );
367 mGroupListMenu->setTitle( tr(
"Add to Tag" ) );
368 mGroupListMenu->setEnabled(
false );
372 mGroupMenu->addAction( actnAddFavorite );
374 mGroupMenu->addAction( actnRemoveFavorite );
375 mGroupMenu->addSeparator()->setParent(
this );
376 mGroupMenu->addMenu( mGroupListMenu );
377 actnDetag->setData( 0 );
379 mGroupMenu->addAction( actnDetag );
380 mGroupMenu->addSeparator()->setParent(
this );
381 mGroupMenu->addAction( actnRemoveItem );
382 mGroupMenu->addAction( actnEditItem );
383 mGroupMenu->addAction( mActionCopyItem );
384 mGroupMenu->addAction( mActionPasteItem );
385 mGroupMenu->addSeparator()->setParent(
this );
389 btnAddItem->setVisible(
false );
390 btnRemoveItem->setVisible(
false );
391 btnEditItem->setVisible(
false );
392 btnAddSmartgroup->setVisible(
false );
393 btnAddTag->setVisible(
false );
394 btnManageGroups->setVisible(
false );
396 mGroupMenu->addAction( mActionCopyItem );
398 if ( mActionCopyToDefault )
400 mGroupMenu->addAction( mActionCopyToDefault );
402 mGroupMenu->addAction( actnExportAsPNG );
403 mGroupMenu->addAction( actnExportAsSVG );
406 mGroupTreeContextMenu =
new QMenu(
this );
410 mGroupTreeContextMenu->addAction( actnEditSmartGroup );
411 connect( actnAddTag, &QAction::triggered,
this, [ = ](
bool ) {
addTag(); }
413 mGroupTreeContextMenu->addAction( actnAddTag );
414 connect( actnAddSmartgroup, &QAction::triggered,
this, [ = ](
bool ) {
addSmartgroup(); }
416 mGroupTreeContextMenu->addAction( actnAddSmartgroup );
418 mGroupTreeContextMenu->addAction( actnRemoveGroup );
421 tabItemType_currentChanged( 0 );
426 connect( mButtonIconView, &QToolButton::toggled,
this, [ = ](
bool active )
430 mSymbolViewStackedWidget->setCurrentIndex( 0 );
435 connect( mButtonListView, &QToolButton::toggled,
this, [ = ](
bool active )
440 mSymbolViewStackedWidget->setCurrentIndex( 1 );
444 const int currentView = settings.
value( QStringLiteral(
"Windows/StyleV2Manager/lastIconView" ), 0,
QgsSettings::Gui ).toInt();
445 if ( currentView == 0 )
446 mButtonIconView->setChecked(
true );
448 mButtonListView->setChecked(
true );
450 mSymbolTreeView->header()->restoreState( settings.
value( QStringLiteral(
"Windows/StyleV2Manager/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
451 connect( mSymbolTreeView->header(), &QHeaderView::sectionResized,
this, [
this]
463 if ( mModified && !mReadOnly )
469 settings.
setValue( QStringLiteral(
"Windows/StyleV2Manager/splitter" ), mSplitter->saveState() );
476 void QgsStyleManagerDialog::tabItemType_currentChanged(
int )
482 searchBox->setPlaceholderText( isSymbol ? tr(
"Filter symbols…" ) :
483 isColorRamp ? tr(
"Filter color ramps…" ) :
484 isTextFormat ? tr(
"Filter text symbols…" ) : tr(
"Filter label settings…" ) );
486 if ( !mReadOnly && isColorRamp )
488 btnAddItem->setMenu( mMenuBtnAddItemColorRamp );
490 if ( !mReadOnly && !isSymbol && !isColorRamp && !isTextFormat )
492 btnAddItem->setMenu( mMenuBtnAddItemLabelSettings );
494 else if ( !mReadOnly && !isSymbol && !isColorRamp )
496 btnAddItem->setMenu(
nullptr );
498 else if ( !mReadOnly && tabItemType->currentIndex() == 0 )
500 btnAddItem->setMenu( mMenuBtnAddItemAll );
504 btnAddItem->setMenu(
nullptr );
507 actnExportAsPNG->setVisible( isSymbol );
508 actnExportAsSVG->setVisible( isSymbol );
511 mModel->setEntityFilterEnabled( !allTypesSelected() );
512 mModel->setSymbolTypeFilterEnabled( isSymbol && !allTypesSelected() );
513 if ( isSymbol && !allTypesSelected() )
514 mModel->setSymbolType( static_cast< QgsSymbol::SymbolType >(
currentItemType() ) );
519 void QgsStyleManagerDialog::copyItemsToDefault()
521 const QList< ItemDetails > items = selectedItems();
522 if ( !items.empty() )
526 if ( !mBaseName.isEmpty() )
527 options.append( mBaseName );
530 defaultTags.sort( Qt::CaseInsensitive );
531 options.append( defaultTags );
532 const QString tags = QInputDialog::getItem(
this, tr(
"Import Items" ),
533 tr(
"Additional tags to add (comma separated)" ), options, mBaseName.isEmpty() ? -1 : 0,
true, &ok );
537 const QStringList parts = tags.split(
',', QString::SkipEmptyParts );
538 QStringList additionalTags;
539 additionalTags.reserve( parts.count() );
540 for (
const QString &tag : parts )
541 additionalTags << tag.trimmed();
543 auto cursorOverride = qgis::make_unique< QgsTemporaryCursorOverride >( Qt::WaitCursor );
544 const int count = copyItems( items, mStyle,
QgsStyle::defaultStyle(),
this, cursorOverride,
true, additionalTags,
false,
false );
545 cursorOverride.reset();
548 mMessageBar->
pushSuccess( tr(
"Import Items" ), count > 1 ? tr(
"Successfully imported %1 items." ).arg( count ) : tr(
"Successfully imported item." ) );
553 void QgsStyleManagerDialog::copyItem()
555 const QList< ItemDetails > items = selectedItems();
559 ItemDetails details = items.at( 0 );
560 switch ( details.entityType )
564 std::unique_ptr< QgsSymbol > symbol( mStyle->
symbol( details.name ) );
574 QApplication::clipboard()->setMimeData( format.toMimeData() );
581 QApplication::clipboard()->setMimeData( format.toMimeData() );
593 void QgsStyleManagerDialog::pasteItem()
595 const QString defaultTag = groupTree->currentIndex().isValid() ? groupTree->currentIndex().data().toString() : QString();
599 QgsStyleSaveDialog saveDlg(
this );
600 saveDlg.setWindowTitle( tr(
"Paste Symbol" ) );
601 saveDlg.setDefaultTags( defaultTag );
602 if ( !saveDlg.exec() || saveDlg.name().isEmpty() )
605 if ( mStyle->
symbolNames().contains( saveDlg.name() ) )
607 int res = QMessageBox::warning(
this, tr(
"Paste Symbol" ),
608 tr(
"A symbol with the name '%1' already exists. Overwrite?" )
609 .arg( saveDlg.name() ),
610 QMessageBox::Yes | QMessageBox::No );
611 if ( res != QMessageBox::Yes )
618 QStringList symbolTags = saveDlg.tags().split(
',' );
619 mStyle->
addSymbol( saveDlg.name(), tempSymbol->clone() );
621 mStyle->
saveSymbol( saveDlg.name(), tempSymbol->clone(), saveDlg.isFavorite(), symbolTags );
629 QgsStyleSaveDialog saveDlg(
this );
630 saveDlg.setDefaultTags( defaultTag );
631 saveDlg.setWindowTitle( tr(
"Paste Text Format" ) );
632 if ( !saveDlg.exec() || saveDlg.name().isEmpty() )
637 int res = QMessageBox::warning(
this, tr(
"Paste Text Format" ),
638 tr(
"A format with the name '%1' already exists. Overwrite?" )
639 .arg( saveDlg.name() ),
640 QMessageBox::Yes | QMessageBox::No );
641 if ( res != QMessageBox::Yes )
648 QStringList symbolTags = saveDlg.tags().split(
',' );
651 mStyle->
saveTextFormat( saveDlg.name(), format, saveDlg.isFavorite(), symbolTags );
656 int QgsStyleManagerDialog::selectedItemType()
658 QModelIndex index = listItems->selectionModel()->currentIndex();
659 if ( !index.isValid() )
673 bool QgsStyleManagerDialog::allTypesSelected()
const 675 return tabItemType->currentIndex() == 0;
678 QList< QgsStyleManagerDialog::ItemDetails > QgsStyleManagerDialog::selectedItems()
680 QList<QgsStyleManagerDialog::ItemDetails > res;
681 QModelIndexList indices = listItems->selectionModel()->selectedRows();
682 for (
const QModelIndex &index : indices )
684 if ( !index.isValid() )
691 details.name = mModel->data( mModel->index( index.row(),
QgsStyleModel::Name, index.parent() ), Qt::DisplayRole ).toString();
698 int QgsStyleManagerDialog::copyItems(
const QList<QgsStyleManagerDialog::ItemDetails> &items,
QgsStyle *src,
QgsStyle *dst, QWidget *parentWidget,
699 std::unique_ptr< QgsTemporaryCursorOverride > &cursorOverride,
bool isImport,
const QStringList &importTags,
bool addToFavorites,
bool ignoreSourceTags )
702 bool overwriteAll =
true;
710 for (
auto &details : items )
712 QStringList symbolTags;
713 if ( !ignoreSourceTags )
715 symbolTags = src->
tagsOfSymbol( details.entityType, details.name );
718 bool addItemToFavorites =
false;
721 symbolTags << importTags;
722 addItemToFavorites = addToFavorites;
725 switch ( details.entityType )
729 std::unique_ptr< QgsSymbol > symbol( src->
symbol( details.name ) );
733 const bool hasDuplicateName = dst->
symbolNames().contains( details.name );
734 bool overwriteThis =
false;
736 addItemToFavorites = favoriteSymbols.contains( details.name );
738 if ( hasDuplicateName && prompt )
740 cursorOverride.reset();
741 int res = QMessageBox::warning( parentWidget, isImport ? tr(
"Import Symbol" ) : tr(
"Export Symbol" ),
742 tr(
"A symbol with the name “%1” already exists.\nOverwrite?" )
743 .arg( details.name ),
744 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
745 cursorOverride = qgis::make_unique< QgsTemporaryCursorOverride >( Qt::WaitCursor );
748 case QMessageBox::Cancel:
751 case QMessageBox::No:
754 case QMessageBox::Yes:
755 overwriteThis =
true;
758 case QMessageBox::YesToAll:
763 case QMessageBox::NoToAll:
765 overwriteAll =
false;
770 if ( !hasDuplicateName || overwriteAll || overwriteThis )
773 dst->
addSymbol( details.name, symbol.release() );
774 dst->
saveSymbol( details.name, newSymbol, addItemToFavorites, symbolTags );
782 std::unique_ptr< QgsColorRamp > ramp( src->
colorRamp( details.name ) );
786 const bool hasDuplicateName = dst->
colorRampNames().contains( details.name );
787 bool overwriteThis =
false;
789 addItemToFavorites = favoriteColorramps.contains( details.name );
791 if ( hasDuplicateName && prompt )
793 cursorOverride.reset();
794 int res = QMessageBox::warning( parentWidget, isImport ? tr(
"Import Color Ramp" ) : tr(
"Export Color Ramp" ),
795 tr(
"A color ramp with the name “%1” already exists.\nOverwrite?" )
796 .arg( details.name ),
797 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
798 cursorOverride = qgis::make_unique< QgsTemporaryCursorOverride >( Qt::WaitCursor );
801 case QMessageBox::Cancel:
804 case QMessageBox::No:
807 case QMessageBox::Yes:
808 overwriteThis =
true;
811 case QMessageBox::YesToAll:
816 case QMessageBox::NoToAll:
818 overwriteAll =
false;
823 if ( !hasDuplicateName || overwriteAll || overwriteThis )
827 dst->
saveColorRamp( details.name, newRamp, addItemToFavorites, symbolTags );
837 const bool hasDuplicateName = dst->
textFormatNames().contains( details.name );
838 bool overwriteThis =
false;
840 addItemToFavorites = favoriteTextFormats.contains( details.name );
842 if ( hasDuplicateName && prompt )
844 cursorOverride.reset();
845 int res = QMessageBox::warning( parentWidget, isImport ? tr(
"Import Text Format" ) : tr(
"Export Text Format" ),
846 tr(
"A text format with the name “%1” already exists.\nOverwrite?" )
847 .arg( details.name ),
848 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
849 cursorOverride = qgis::make_unique< QgsTemporaryCursorOverride >( Qt::WaitCursor );
852 case QMessageBox::Cancel:
855 case QMessageBox::No:
858 case QMessageBox::Yes:
859 overwriteThis =
true;
862 case QMessageBox::YesToAll:
867 case QMessageBox::NoToAll:
869 overwriteAll =
false;
874 if ( !hasDuplicateName || overwriteAll || overwriteThis )
877 dst->
saveTextFormat( details.name, format, addItemToFavorites, symbolTags );
888 bool overwriteThis =
false;
890 addItemToFavorites = favoriteLabelSettings.contains( details.name );
892 if ( hasDuplicateName && prompt )
894 cursorOverride.reset();
895 int res = QMessageBox::warning( parentWidget, isImport ? tr(
"Import Label Settings" ) : tr(
"Export Label Settings" ),
896 tr(
"Label settings with the name “%1” already exist.\nOverwrite?" )
897 .arg( details.name ),
898 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
899 cursorOverride = qgis::make_unique< QgsTemporaryCursorOverride >( Qt::WaitCursor );
902 case QMessageBox::Cancel:
905 case QMessageBox::No:
908 case QMessageBox::Yes:
909 overwriteThis =
true;
912 case QMessageBox::YesToAll:
917 case QMessageBox::NoToAll:
919 overwriteAll =
false;
924 if ( !hasDuplicateName || overwriteAll || overwriteThis )
927 dst->
saveLabelSettings( details.name, settings, addItemToFavorites, symbolTags );
942 bool QgsStyleManagerDialog::addTextFormat()
946 if ( !formatDlg.exec() )
948 format = formatDlg.
format();
950 QgsStyleSaveDialog saveDlg(
this );
951 if ( !saveDlg.exec() )
953 QString name = saveDlg.name();
956 bool nameInvalid =
true;
957 while ( nameInvalid )
960 if ( name.isEmpty() )
962 QMessageBox::warning(
this, tr(
"Save Text Format" ),
963 tr(
"Cannot save text format without name. Enter a name." ) );
967 int res = QMessageBox::warning(
this, tr(
"Save Text Format" ),
968 tr(
"Text format with name '%1' already exists. Overwrite?" )
970 QMessageBox::Yes | QMessageBox::No );
971 if ( res == QMessageBox::Yes )
985 name = QInputDialog::getText(
this, tr(
"Text Format Name" ),
986 tr(
"Please enter a name for new text format:" ),
987 QLineEdit::Normal, name, &ok );
995 QStringList symbolTags = saveDlg.tags().split(
',' );
999 mStyle->
saveTextFormat( name, format, saveDlg.isFavorite(), symbolTags );
1007 groupChanged( groupTree->selectionModel()->currentIndex() );
1020 switch ( tabItemType->currentIndex() )
1041 QModelIndex index = listItems->selectionModel()->currentIndex();
1042 if ( !index.isValid() )
1045 return mModel->data( mModel->index( index.row(),
QgsStyleModel::Name, index.parent() ), Qt::DisplayRole ).toString();
1050 bool changed =
false;
1061 changed = addTextFormat();
1069 Q_ASSERT(
false &&
"not implemented" );
1082 QString name = tr(
"new symbol" );
1087 name = tr(
"new marker" );
1091 name = tr(
"new line" );
1095 name = tr(
"new fill symbol" );
1098 Q_ASSERT(
false &&
"unknown symbol type" );
1108 if ( dlg.exec() == 0 )
1114 QgsStyleSaveDialog saveDlg(
this );
1115 if ( !saveDlg.exec() )
1121 name = saveDlg.name();
1124 bool nameInvalid =
true;
1125 while ( nameInvalid )
1128 if ( name.isEmpty() )
1130 QMessageBox::warning(
this, tr(
"Save Symbol" ),
1131 tr(
"Cannot save symbol without name. Enter a name." ) );
1133 else if ( mStyle->
symbolNames().contains( name ) )
1135 int res = QMessageBox::warning(
this, tr(
"Save Symbol" ),
1136 tr(
"Symbol with name '%1' already exists. Overwrite?" )
1138 QMessageBox::Yes | QMessageBox::No );
1139 if ( res == QMessageBox::Yes )
1142 nameInvalid =
false;
1148 nameInvalid =
false;
1153 name = QInputDialog::getText(
this, tr(
"Symbol Name" ),
1154 tr(
"Please enter a name for new symbol:" ),
1155 QLineEdit::Normal, name, &ok );
1164 QStringList symbolTags = saveDlg.tags().split(
',' );
1168 mStyle->
saveSymbol( name, symbol, saveDlg.isFavorite(), symbolTags );
1179 if ( rampType.isEmpty() )
1181 QStringList rampTypes;
1182 rampTypes << tr(
"Gradient" ) << tr(
"Color presets" ) << tr(
"Random" ) << tr(
"Catalog: cpt-city" );
1183 rampTypes << tr(
"Catalog: ColorBrewer" );
1184 rampType = QInputDialog::getItem( parent, tr(
"Color Ramp Type" ),
1185 tr(
"Please select color ramp type:" ), rampTypes, 0,
false, &ok );
1187 if ( !ok || rampType.isEmpty() )
1190 QString name = tr(
"new ramp" );
1192 std::unique_ptr< QgsColorRamp > ramp;
1193 if ( rampType == tr(
"Gradient" ) )
1201 name = tr(
"new gradient ramp" );
1203 else if ( rampType == tr(
"Random" ) )
1211 name = tr(
"new random ramp" );
1213 else if ( rampType == tr(
"Catalog: ColorBrewer" ) )
1223 else if ( rampType == tr(
"Color presets" ) )
1231 name = tr(
"new preset ramp" );
1233 else if ( rampType == tr(
"Catalog: cpt-city" ) )
1255 QgsDebugMsg( QStringLiteral(
"invalid ramp type %1" ).arg( rampType ) );
1260 if ( !saveDlg.exec() )
1265 name = saveDlg.name();
1268 bool nameInvalid =
true;
1269 while ( nameInvalid )
1272 if ( name.isEmpty() )
1274 QMessageBox::warning( parent, tr(
"Save Color Ramp" ),
1275 tr(
"Cannot save color ramp without name. Enter a name." ) );
1279 int res = QMessageBox::warning( parent, tr(
"Save Color Ramp" ),
1280 tr(
"Color ramp with name '%1' already exists. Overwrite?" )
1282 QMessageBox::Yes | QMessageBox::No );
1283 if ( res == QMessageBox::Yes )
1285 nameInvalid =
false;
1291 nameInvalid =
false;
1296 name = QInputDialog::getText( parent, tr(
"Color Ramp Name" ),
1297 tr(
"Please enter a name for new color ramp:" ),
1298 QLineEdit::Normal, name, &ok );
1306 QStringList colorRampTags = saveDlg.tags().split(
',' );
1311 style->
saveColorRamp( name, r, saveDlg.isFavorite(), colorRampTags );
1318 mFavoritesGroupVisible = show;
1324 mSmartGroupVisible = show;
1336 setWindowState( windowState() & ~Qt::WindowMinimized );
1349 action ? action->text() : QString() );
1350 if ( !rampName.isEmpty() )
1362 if ( selectedItemType() < 3 )
1366 else if ( selectedItemType() == 3 )
1370 else if ( selectedItemType() == 4 )
1374 else if ( selectedItemType() == 5 )
1376 editLabelSettings();
1380 Q_ASSERT(
false &&
"not implemented" );
1387 if ( symbolName.isEmpty() )
1390 std::unique_ptr< QgsSymbol > symbol( mStyle->
symbol( symbolName ) );
1395 dlg.
buttonBox()->button( QDialogButtonBox::Ok )->setEnabled(
false );
1401 mStyle->
addSymbol( symbolName, symbol.release(), true );
1409 if ( name.isEmpty() )
1412 std::unique_ptr< QgsColorRamp > ramp( mStyle->
colorRamp( name ) );
1414 if ( ramp->type() == QLatin1String(
"gradient" ) )
1419 dlg.
buttonBox()->button( QDialogButtonBox::Ok )->setEnabled(
false );
1427 else if ( ramp->type() == QLatin1String(
"random" ) )
1432 dlg.
buttonBox()->button( QDialogButtonBox::Ok )->setEnabled(
false );
1440 else if ( ramp->type() == QLatin1String(
"colorbrewer" ) )
1445 dlg.
buttonBox()->button( QDialogButtonBox::Ok )->setEnabled(
false );
1453 else if ( ramp->type() == QLatin1String(
"preset" ) )
1458 dlg.
buttonBox()->button( QDialogButtonBox::Ok )->setEnabled(
false );
1466 else if ( ramp->type() == QLatin1String(
"cpt-city" ) )
1471 dlg.
buttonBox()->button( QDialogButtonBox::Ok )->setEnabled(
false );
1488 Q_ASSERT(
false &&
"invalid ramp type" );
1496 bool QgsStyleManagerDialog::editTextFormat()
1499 if ( formatName.isEmpty() )
1507 dlg.
buttonBox()->button( QDialogButtonBox::Ok )->setEnabled(
false );
1521 QgsLabelSettingsDialog settingsDlg( settings,
nullptr,
nullptr,
this, type );
1523 settingsDlg.buttonBox()->button( QDialogButtonBox::Ok )->setEnabled(
false );
1525 if ( !settingsDlg.exec() )
1528 settings = settingsDlg.settings();
1531 QgsStyleSaveDialog saveDlg(
this );
1532 if ( !saveDlg.exec() )
1534 QString name = saveDlg.name();
1537 bool nameInvalid =
true;
1538 while ( nameInvalid )
1541 if ( name.isEmpty() )
1543 QMessageBox::warning(
this, tr(
"Save Label Settings" ),
1544 tr(
"Cannot save label settings without a name. Enter a name." ) );
1548 int res = QMessageBox::warning(
this, tr(
"Save Label Settings" ),
1549 tr(
"Label settings with the name '%1' already exist. Overwrite?" )
1551 QMessageBox::Yes | QMessageBox::No );
1552 if ( res == QMessageBox::Yes )
1555 nameInvalid =
false;
1561 nameInvalid =
false;
1566 name = QInputDialog::getText(
this, tr(
"Label Settings Name" ),
1567 tr(
"Please enter a name for the new label settings:" ),
1568 QLineEdit::Normal, name, &ok );
1576 QStringList symbolTags = saveDlg.tags().split(
',' );
1586 bool QgsStyleManagerDialog::editLabelSettings()
1589 if ( formatName.isEmpty() )
1596 QgsLabelSettingsDialog dlg( settings,
nullptr,
nullptr,
this, geomType );
1600 settings = dlg.settings();
1612 const QList< ItemDetails > items = selectedItems();
1614 if ( allTypesSelected() )
1616 if ( QMessageBox::Yes != QMessageBox::question(
this, tr(
"Remove Items" ),
1617 QString( tr(
"Do you really want to remove %n item(s)?",
nullptr, items.count() ) ),
1626 if ( QMessageBox::Yes != QMessageBox::question(
this, tr(
"Remove Symbol" ),
1627 QString( tr(
"Do you really want to remove %n symbol(s)?",
nullptr, items.count() ) ),
1634 if ( QMessageBox::Yes != QMessageBox::question(
this, tr(
"Remove Color Ramp" ),
1635 QString( tr(
"Do you really want to remove %n ramp(s)?",
nullptr, items.count() ) ),
1642 if ( QMessageBox::Yes != QMessageBox::question(
this, tr(
"Remove Text Formats" ),
1643 QString( tr(
"Do you really want to remove %n text format(s)?",
nullptr, items.count() ) ),
1650 if ( QMessageBox::Yes != QMessageBox::question(
this, tr(
"Remove Label Settings" ),
1651 QString( tr(
"Do you really want to remove %n label settings?",
nullptr, items.count() ) ),
1660 for (
const ItemDetails &details : items )
1662 if ( details.name.isEmpty() )
1665 switch ( details.entityType )
1708 QString dir = QFileDialog::getExistingDirectory(
this, tr(
"Export Selected Symbols as PNG" ),
1709 QDir::home().absolutePath(),
1710 QFileDialog::ShowDirsOnly
1711 | QFileDialog::DontResolveSymlinks );
1717 QString dir = QFileDialog::getExistingDirectory(
this, tr(
"Export Selected Symbols as SVG" ),
1718 QDir::home().absolutePath(),
1719 QFileDialog::ShowDirsOnly
1720 | QFileDialog::DontResolveSymlinks );
1727 if ( dir.isEmpty() )
1730 const QList< ItemDetails > items = selectedItems();
1731 for (
const ItemDetails &details : items )
1736 QString path = dir +
'/' + details.name +
'.' + format;
1737 std::unique_ptr< QgsSymbol > sym( mStyle->
symbol( details.name ) );
1739 sym->exportImage( path, format, size );
1759 QFont font = item->font();
1760 font.setBold(
true );
1761 item->setFont( font );
1766 if ( mBlockGroupUpdates )
1769 QStandardItemModel *model = qobject_cast<QStandardItemModel *>( groupTree->model() );
1772 if ( mFavoritesGroupVisible )
1774 QStandardItem *favoriteSymbols =
new QStandardItem( tr(
"Favorites" ) );
1775 favoriteSymbols->setData(
"favorite" );
1776 favoriteSymbols->setEditable(
false );
1778 model->appendRow( favoriteSymbols );
1781 QStandardItem *allSymbols =
new QStandardItem( tr(
"All" ) );
1782 allSymbols->setData(
"all" );
1783 allSymbols->setEditable(
false );
1785 model->appendRow( allSymbols );
1787 QStandardItem *taggroup =
new QStandardItem( QString() );
1788 taggroup->setData(
"tags" );
1789 taggroup->setEditable(
false );
1790 QStringList tags = mStyle->
tags();
1792 for (
const QString &tag : qgis::as_const( tags ) )
1794 QStandardItem *item =
new QStandardItem( tag );
1795 item->setData( mStyle->
tagId( tag ) );
1796 item->setEditable( !mReadOnly );
1797 taggroup->appendRow( item );
1799 taggroup->setText( tr(
"Tags" ) );
1801 model->appendRow( taggroup );
1803 if ( mSmartGroupVisible )
1805 QStandardItem *smart =
new QStandardItem( tr(
"Smart Groups" ) );
1806 smart->setData(
"smartgroups" );
1807 smart->setEditable(
false );
1810 QgsSymbolGroupMap::const_iterator i = sgMap.constBegin();
1811 while ( i != sgMap.constEnd() )
1813 QStandardItem *item =
new QStandardItem( i.value() );
1814 item->setData( i.key() );
1815 item->setEditable( !mReadOnly );
1816 smart->appendRow( item );
1819 model->appendRow( smart );
1823 int rows = model->rowCount( model->indexFromItem( model->invisibleRootItem() ) );
1824 for (
int i = 0; i < rows; i++ )
1826 groupTree->setExpanded( model->indexFromItem( model->item( i ) ),
true );
1832 QStringList groupSymbols;
1834 const QString category = index.data( Qt::UserRole + 1 ).toString();
1835 if ( mGroupingMode )
1837 mModel->setTagId( -1 );
1838 mModel->setSmartGroupId( -1 );
1839 mModel->setFavoritesOnly(
false );
1840 mModel->setCheckTag( index.data( Qt::DisplayRole ).toString() );
1842 else if ( category == QLatin1String(
"all" ) || category == QLatin1String(
"tags" ) || category == QLatin1String(
"smartgroups" ) )
1845 if ( category == QLatin1String(
"tags" ) )
1847 actnAddTag->setEnabled( !mReadOnly );
1848 actnAddSmartgroup->setEnabled(
false );
1850 else if ( category == QLatin1String(
"smartgroups" ) )
1852 actnAddTag->setEnabled(
false );
1853 actnAddSmartgroup->setEnabled( !mReadOnly );
1856 mModel->setTagId( -1 );
1857 mModel->setSmartGroupId( -1 );
1858 mModel->setFavoritesOnly(
false );
1860 else if ( category == QLatin1String(
"favorite" ) )
1863 mModel->setTagId( -1 );
1864 mModel->setSmartGroupId( -1 );
1865 mModel->setFavoritesOnly(
true );
1867 else if ( index.parent().data( Qt::UserRole + 1 ) ==
"smartgroups" )
1869 actnRemoveGroup->setEnabled( !mReadOnly );
1870 btnManageGroups->setEnabled( !mReadOnly );
1871 const int groupId = index.data( Qt::UserRole + 1 ).toInt();
1872 mModel->setTagId( -1 );
1873 mModel->setSmartGroupId( groupId );
1874 mModel->setFavoritesOnly(
false );
1879 int tagId = index.data( Qt::UserRole + 1 ).toInt();
1880 mModel->setTagId( tagId );
1881 mModel->setSmartGroupId( -1 );
1882 mModel->setFavoritesOnly(
false );
1885 actnEditSmartGroup->setVisible(
false );
1886 actnAddTag->setVisible(
false );
1887 actnAddSmartgroup->setVisible(
false );
1888 actnRemoveGroup->setVisible(
false );
1889 actnTagSymbols->setVisible(
false );
1890 actnFinishTagging->setVisible(
false );
1892 if ( index.parent().isValid() )
1894 if ( index.parent().data( Qt::UserRole + 1 ).toString() == QLatin1String(
"smartgroups" ) )
1896 actnEditSmartGroup->setVisible( !mGroupingMode && !mReadOnly );
1898 else if ( index.parent().data( Qt::UserRole + 1 ).toString() == QLatin1String(
"tags" ) )
1900 actnAddTag->setVisible( !mGroupingMode && !mReadOnly );
1901 actnTagSymbols->setVisible( !mGroupingMode && !mReadOnly );
1902 actnFinishTagging->setVisible( mGroupingMode && !mReadOnly );
1904 actnRemoveGroup->setVisible( !mReadOnly );
1906 else if ( index.data( Qt::UserRole + 1 ) ==
"smartgroups" )
1908 actnAddSmartgroup->setVisible( !mGroupingMode && !mReadOnly );
1910 else if ( index.data( Qt::UserRole + 1 ) ==
"tags" )
1912 actnAddTag->setVisible( !mGroupingMode && !mReadOnly );
1918 QStandardItemModel *model = qobject_cast<QStandardItemModel *>( groupTree->model() );
1920 for (
int i = 0; i < groupTree->model()->rowCount(); i++ )
1922 index = groupTree->model()->index( i, 0 );
1923 QString data = index.data( Qt::UserRole + 1 ).toString();
1924 if ( data == QLatin1String(
"tags" ) )
1933 itemName = QInputDialog::getText(
this, tr(
"Add Tag" ),
1934 tr(
"Please enter name for the new tag:" ), QLineEdit::Normal, tr(
"New tag" ), &ok ).trimmed();
1935 if ( !ok || itemName.isEmpty() )
1938 int check = mStyle->
tagId( itemName );
1941 mMessageBar->
pushCritical( tr(
"Add Tag" ), tr(
"The tag “%1” already exists." ).arg( itemName ) );
1947 mBlockGroupUpdates++;
1948 id = mStyle->
addTag( itemName );
1949 mBlockGroupUpdates--;
1953 mMessageBar->
pushCritical( tr(
"Add Tag" ), tr(
"New tag could not be created — There was a problem with the symbol database." ) );
1957 QStandardItem *parentItem = model->itemFromIndex( index );
1958 QStandardItem *childItem =
new QStandardItem( itemName );
1959 childItem->setData(
id );
1960 parentItem->appendRow( childItem );
1967 QStandardItemModel *model = qobject_cast<QStandardItemModel *>( groupTree->model() );
1969 for (
int i = 0; i < groupTree->model()->rowCount(); i++ )
1971 index = groupTree->model()->index( i, 0 );
1972 QString data = index.data( Qt::UserRole + 1 ).toString();
1973 if ( data == QLatin1String(
"smartgroups" ) )
1982 if ( dlg.exec() == QDialog::Rejected )
1987 mBlockGroupUpdates++;
1989 mBlockGroupUpdates--;
1995 QStandardItem *parentItem = model->itemFromIndex( index );
1996 QStandardItem *childItem =
new QStandardItem( itemName );
1997 childItem->setData(
id );
1998 parentItem->appendRow( childItem );
2005 QStandardItemModel *model = qobject_cast<QStandardItemModel *>( groupTree->model() );
2006 QModelIndex index = groupTree->currentIndex();
2009 QString data = index.data( Qt::UserRole + 1 ).toString();
2010 if ( data == QLatin1String(
"all" ) || data == QLatin1String(
"favorite" ) || data == QLatin1String(
"tags" ) || index.data() ==
"smartgroups" )
2013 int err = QMessageBox::critical(
this, tr(
"Remove Group" ),
2014 tr(
"Invalid selection. Cannot delete system defined categories.\n" 2015 "Kindly select a group or smart group you might want to delete." ) );
2020 QStandardItem *parentItem = model->itemFromIndex( index.parent() );
2024 mBlockGroupUpdates++;
2026 if ( parentItem->data( Qt::UserRole + 1 ).toString() == QLatin1String(
"smartgroups" ) )
2035 mBlockGroupUpdates--;
2036 parentItem->removeRow( index.row() );
2041 QgsDebugMsg( QStringLiteral(
"Symbol group edited: data=%1 text=%2" ).arg( item->data( Qt::UserRole + 1 ).toString(), item->text() ) );
2042 int id = item->data( Qt::UserRole + 1 ).toInt();
2043 QString name = item->text();
2044 mBlockGroupUpdates++;
2045 if ( item->parent()->data( Qt::UserRole + 1 ) ==
"smartgroups" )
2053 mBlockGroupUpdates--;
2058 QStandardItemModel *treeModel = qobject_cast<QStandardItemModel *>( groupTree->model() );
2060 if ( mGroupingMode )
2062 mGroupingMode =
false;
2063 mModel->setCheckable(
false );
2064 actnTagSymbols->setVisible(
true );
2065 actnFinishTagging->setVisible(
false );
2073 connect( treeModel, &QStandardItemModel::itemChanged,
2077 listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
2078 mSymbolTreeView->setSelectionMode( QAbstractItemView::ExtendedSelection );
2082 bool validGroup =
false;
2084 QModelIndex present = groupTree->currentIndex();
2085 while ( present.parent().isValid() )
2087 if ( present.parent().data() ==
"Tags" )
2092 present = present.parent();
2097 mGroupingMode =
true;
2099 actnTagSymbols->setVisible(
false );
2100 actnFinishTagging->setVisible(
true );
2102 disconnect( treeModel, &QStandardItemModel::itemChanged,
2108 btnManageGroups->setEnabled(
true );
2110 mModel->setCheckable(
true );
2113 listItems->setSelectionMode( QAbstractItemView::NoSelection );
2114 mSymbolTreeView->setSelectionMode( QAbstractItemView::NoSelection );
2128 mModel->setFilterString( qword );
2133 actnEditItem->setEnabled( index.isValid() && !mGroupingMode && !mReadOnly );
2138 Q_UNUSED( selected )
2139 Q_UNUSED( deselected )
2140 bool nothingSelected = listItems->selectionModel()->selectedIndexes().empty();
2141 actnRemoveItem->setDisabled( nothingSelected || mReadOnly );
2142 actnAddFavorite->setDisabled( nothingSelected || mReadOnly );
2143 actnRemoveFavorite->setDisabled( nothingSelected || mReadOnly );
2144 mGroupListMenu->setDisabled( nothingSelected || mReadOnly );
2145 actnDetag->setDisabled( nothingSelected || mReadOnly );
2146 actnExportAsPNG->setDisabled( nothingSelected );
2147 actnExportAsSVG->setDisabled( nothingSelected );
2148 if ( mActionCopyToDefault )
2149 mActionCopyToDefault->setDisabled( nothingSelected );
2150 mCopyToDefaultButton->setDisabled( nothingSelected );
2151 actnEditItem->setDisabled( nothingSelected || mReadOnly );
2156 groupTree->setEnabled( enable );
2157 btnAddTag->setEnabled( enable && !mReadOnly );
2158 btnAddSmartgroup->setEnabled( enable && !mReadOnly );
2159 actnAddTag->setEnabled( enable && !mReadOnly );
2160 actnAddSmartgroup->setEnabled( enable && !mReadOnly );
2161 actnRemoveGroup->setEnabled( enable && !mReadOnly );
2162 btnManageGroups->setEnabled( !mReadOnly && ( enable || mGroupingMode ) );
2163 searchBox->setEnabled( enable );
2168 actnRemoveGroup->setEnabled( enable && !mReadOnly );
2169 btnManageGroups->setEnabled( !mReadOnly && ( enable || mGroupingMode ) );
2174 QStandardItemModel *treeModel = qobject_cast<QStandardItemModel *>( groupTree->model() );
2175 for (
int i = 0; i < treeModel->rowCount(); i++ )
2177 treeModel->item( i )->setEnabled( enable );
2179 if ( treeModel->item( i )->data() ==
"smartgroups" )
2181 for (
int j = 0; j < treeModel->item( i )->rowCount(); j++ )
2183 treeModel->item( i )->child( j )->setEnabled( enable );
2190 for (
int i = 0; i < symbolBtnsLayout->count(); i++ )
2192 QWidget *w = symbolBtnsLayout->itemAt( i )->widget();
2194 w->setEnabled( enable );
2198 actnRemoveItem->setEnabled( enable );
2199 actnEditItem->setEnabled( enable );
2200 mActionCopyItem->setEnabled( enable );
2201 mActionPasteItem->setEnabled( enable );
2206 QPoint globalPos = groupTree->viewport()->mapToGlobal( point );
2208 QModelIndex index = groupTree->indexAt( point );
2209 if ( index.isValid() && !mGroupingMode )
2210 mGroupTreeContextMenu->popup( globalPos );
2215 QPoint globalPos = mSymbolViewStackedWidget->currentIndex() == 0
2216 ? listItems->viewport()->mapToGlobal( point )
2217 : mSymbolTreeView->viewport()->mapToGlobal( point );
2220 mGroupListMenu->clear();
2222 const QModelIndexList indices = listItems->selectionModel()->selectedRows();
2226 const QStringList currentTags = indices.count() == 1 ? indices.at( 0 ).data(
QgsStyleModel::TagRole ).toStringList() : QStringList();
2227 QAction *a =
nullptr;
2228 QStringList tags = mStyle->
tags();
2230 for (
const QString &tag : qgis::as_const( tags ) )
2232 a =
new QAction( tag, mGroupListMenu );
2234 if ( indices.count() == 1 )
2236 a->setCheckable(
true );
2237 a->setChecked( currentTags.contains( tag ) );
2241 mGroupListMenu->addAction( a );
2244 if ( tags.count() > 0 )
2246 mGroupListMenu->addSeparator();
2248 a =
new QAction( tr(
"Create New Tag…" ), mGroupListMenu );
2251 mGroupListMenu->addAction( a );
2254 const QList< ItemDetails > items = selectedItems();
2257 bool enablePaste =
false;
2265 mActionPasteItem->setEnabled( enablePaste );
2267 mGroupMenu->popup( globalPos );
2272 const QList< ItemDetails > items = selectedItems();
2273 for (
const ItemDetails &details : items )
2275 mStyle->
addFavorite( details.entityType, details.name );
2281 const QList< ItemDetails > items = selectedItems();
2282 for (
const ItemDetails &details : items )
2290 QAction *selectedItem = qobject_cast<QAction *>( sender() );
2293 const QList< ItemDetails > items = selectedItems();
2303 tag = mStyle->
tag(
id );
2307 tag = selectedItem->data().toString();
2310 for (
const ItemDetails &details : items )
2312 mStyle->
tagSymbol( details.entityType, details.name, QStringList( tag ) );
2319 QAction *selectedItem = qobject_cast<QAction *>( sender() );
2323 const QList< ItemDetails > items = selectedItems();
2324 for (
const ItemDetails &details : items )
2326 mStyle->
detagSymbol( details.entityType, details.name );
2333 QStandardItemModel *treeModel = qobject_cast<QStandardItemModel *>( groupTree->model() );
2336 QModelIndex present = groupTree->currentIndex();
2337 if ( present.parent().data( Qt::UserRole + 1 ) !=
"smartgroups" )
2340 QMessageBox::critical(
this, tr(
"Edit Smart Group" ),
2341 tr(
"You have not selected a Smart Group. Kindly select a Smart Group to edit." ) );
2344 QStandardItem *item = treeModel->itemFromIndex( present );
2352 if ( dlg.exec() == QDialog::Rejected )
2355 mBlockGroupUpdates++;
2358 mBlockGroupUpdates--;
2361 mMessageBar->
pushCritical( tr(
"Edit Smart Group" ), tr(
"There was an error while editing the smart group." ) );
2365 item->setData(
id );
2377 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/style_library.html#the-style-manager" ) );
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
void setBaseStyleName(const QString &name)
Sets the base name for the style, which is used by the dialog to reflect the original style/XML file ...
void groupChanged(const QModelIndex &)
Triggered when the current group (or tag) is changed.
void tagSymbolsAction()
Toggles the interactive item tagging mode.
void setSmartGroupsVisible(bool show)
Sets whether smart groups should be shown.
void editItem()
Triggers the dialog for editing the current item.
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
bool addTextFormat(const QString &name, const QgsTextFormat &format, bool update=false)
Adds a text format with the specified name to the style.
Temporarily sets a cursor override for the QApplication for the lifetime of the object.
bool addColorRamp(const QString &name, QgsColorRamp *colorRamp, bool update=false)
Adds a color ramp to the style.
void symbolSaved(const QString &name, QgsSymbol *symbol)
Emitted every time a new symbol has been added to the database.
Q_DECL_DEPRECATED void regrouped(QStandardItem *) SIP_DEPRECATED
void setBold(QStandardItem *)
sets the text of the item with bold font
bool save(QString filename=QString())
Saves style into a file (will use current filename if empty string is passed)
A dialog allowing users to customize and populate a QgsStyle.
QgsStyleManagerDialog(QgsStyle *style, QWidget *parent SIP_TRANSFERTHIS=nullptr, Qt::WindowFlags flags=Qt::WindowFlags(), bool readOnly=false)
Constructor for QgsStyleManagerDialog, with the specified parent widget and window flags...
Abstract base class for all rendered symbols.
static const double UI_SCALE_FACTOR
UI scaling factor.
This class is a composition of two QSettings instances:
QgsColorBrewerColorRamp * clone() const override
Creates a clone of the color ramp.
void populateList()
Refreshes the list of items.
void onFinished()
Called when the dialog is going to be closed.
QgsSmartConditionMap conditionMap()
returns the condition map
int addSmartgroup()
Triggers the dialog to add a new smart group.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void selectedSymbolsChanged(const QItemSelection &selected, const QItemSelection &deselected)
Perform tasks when the selected symbols change.
bool addLabelSettings(const QString &name, const QgsPalLayerSettings &settings, bool update=false)
Adds label settings with the specified name to the style.
QStringList tagsOfSymbol(StyleEntity type, const QString &symbol)
Returns the tags associated with the symbol.
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
Abstract base class for color ramps.
QMap< int, QString > QgsSymbolGroupMap
QString schemeName() const
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
bool saveColorRamp(const QString &name, QgsColorRamp *ramp, bool favorite, const QStringList &tags)
Adds the colorramp to the DB.
void populateGroups()
populate the groups
bool tagSymbol(StyleEntity type, const QString &symbol, const QStringList &tags)
Tags the symbol with the tags in the list.
A bar for displaying non-blocking messages to the user.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QgsTextFormat format() const
Returns the current formatting settings defined by the widget.
void importItems()
Triggers the dialog to import items.
bool addColorRamp()
add a new color ramp to style
Q_DECL_DEPRECATED void populateTypes() SIP_DEPRECATED
Populate combo box with known style items (symbols, color ramps).
static QgsGui * instance()
Returns a pointer to the singleton instance.
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
A dialog which allows users to modify the properties of a QgsColorBrewerColorRamp.
QgsColorRamp * colorRamp(const QString &name) const
Returns a new copy of the specified color ramp.
Q_DECL_DEPRECATED void itemChanged(QStandardItem *item) SIP_DEPRECATED
QString smartgroupName()
returns the value from mNameLineEdit
bool removeColorRamp(const QString &name)
Removes color ramp from style (and delete it)
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
bool rename(StyleEntity type, int id, const QString &newName)
Renames the given entity with the specified id.
void pushSuccess(const QString &title, const QString &message)
Pushes a success message with default timeout to the message bar.
A dialog which allows users to modify the properties of a QgsGradientColorRamp.
A dialog which allows users to modify the properties of a QgsPresetSchemeColorRamp.
A marker symbol type, for rendering Point and MultiPoint geometries.
A line symbol type, for rendering LineString and MultiLineString geometries.
static QgsStyle * defaultStyle()
Returns default application-wide style.
A dialog which allows users to modify the properties of a QgsLimitedRandomColorRamp.
StyleEntity
Enum for Entities involved in a style.
QString currentItemName()
static QgsTextFormat fromMimeData(const QMimeData *data, bool *ok=nullptr)
Attempts to parse the provided mime data as a QgsTextFormat.
SymbolType
Type of the symbol.
void tagSelectedSymbols(bool newTag=false)
Tag selected symbols using menu item selection.
QgsGradientColorRamp * clone() const override
Creates a clone of the color ramp.
QStringList textFormatNames() const
Returns a list of names of text formats in the style.
QgsPalLayerSettings labelSettings(const QString &name) const
Returns the label settings with the specified name.
bool addSymbol(int symbolType=-1)
add a new symbol to style
int colors() const
Returns the number of colors in the ramp.
Constrained random color ramp, which returns random colors based on preset parameters.
void filterSymbols(const QString &filter)
Sets the filter string to filter symbols by.
QString tag(int id) const
Returns the tag name for the given id.
Q_DECL_DEPRECATED bool removeColorRamp() SIP_DEPRECATED
void exportItemsSVG()
Triggers the dialog to export selected items as SVG files.
QStringList labelSettingsNames() const
Returns a list of names of label settings in the style.
bool removeFavorite(StyleEntity type, const QString &name)
Removes the specified symbol from favorites.
QgsGradientColorRamp ramp
QgsPresetSchemeColorRamp * clone() const override
Creates a clone of the color ramp.
static QMimeData * symbolToMimeData(const QgsSymbol *symbol)
Creates new mime data from a symbol.
bool remove(StyleEntity type, int id)
Removes the specified entity from the db.
void groupsModified()
Emitted every time a tag or smartgroup has been added, removed, or renamed.
void enableItemsForGroupingMode(bool)
Enables or disables the groupTree items for grouping mode.
void editSmartgroupAction()
Triggers the dialog for editing the selected smart group.
void exportSelectedItemsImages(const QString &dir, const QString &format, QSize size)
Triggers the dialog to export selected items as images of the specified format and size...
int addTag(const QString &tagName)
Adds a new tag and returns the tag's id.
Q_DECL_DEPRECATED void populateColorRamps(const QStringList &colorRamps, bool checkable=false) SIP_DEPRECATED
Populates the list view with color ramps of the current type with the given names.
void symbolSelected(const QModelIndex &)
Perform symbol specific tasks when selected.
QString smartgroupOperator(int id)
Returns the operator for the smartgroup clumsy implementation TODO create a class for smartgroups...
void grouptreeContextMenu(QPoint)
Context menu for the groupTree.
static QString addColorRampStatic(QWidget *parent, QgsStyle *style, QString RampType=QString())
Opens the add color ramp dialog, returning the new color ramp's name if the ramp has been added...
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
void removeFavoriteSelectedSymbols()
Remove selected symbols from favorites.
Export existing symbols mode.
A scheme based color ramp consisting of a list of predefined colors.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
QgsTextFormat textFormat(const QString &name) const
Returns the text format with the specified name.
A QSortFilterProxyModel subclass for showing filtered symbol and color ramps entries from a QgsStyle ...
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc...
QgsGradientColorRamp * cloneGradientRamp() const
QgsSmartConditionMap smartgroup(int id)
Returns the QgsSmartConditionMap for the given id.
QgsLimitedRandomColorRamp * clone() const override
Creates a clone of the color ramp.
void enableSymbolInputs(bool)
Enables or disbables the symbol specific inputs.
Q_DECL_DEPRECATED void populateSymbols(const QStringList &symbolNames, bool checkable=false) SIP_DEPRECATED
Populates the list view with symbols of the current type with the given names.
void setFavoritesGroupVisible(bool show)
Sets whether the favorites group should be shown.
int tagId(const QString &tag)
Returns the DB id for the given tag name.
static QgsStyleModel * defaultStyleModel()
Returns a shared QgsStyleModel containing the default style library (see QgsStyle::defaultStyle()).
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
bool saveTextFormat(const QString &name, const QgsTextFormat &format, bool favorite, const QStringList &tags)
Adds a text format to the database.
QString schemeName() const
Returns the name of the color brewer color scheme.
void groupRenamed(QStandardItem *item)
Triggered when a group item is renamed.
void addFavoriteSelectedSymbols()
Add selected symbols to favorites.
bool addSymbol(const QString &name, QgsSymbol *symbol, bool update=false)
Adds a symbol to style and takes symbol's ownership.
bool removeTextFormat(const QString &name)
Removes a text format from the style.
QStringList tags() const
Returns a list of all tags in the style database.
int addSmartgroup(const QString &name, const QString &op, const QgsSmartConditionMap &conditions)
Adds a new smartgroup to the database and returns the id.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
void setOperator(const QString &)
sets the operator AND/OR
QgsCptCityColorRamp * clone() const override
Creates a clone of the color ramp.
void activate()
Raises, unminimizes and activates this window.
QgsPresetSchemeColorRamp ramp
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
Q_DECL_DEPRECATED void setSymbolsChecked(const QStringList &) SIP_DEPRECATED
QStringList colorRampNames() const
Returns a list of names of color ramps.
void removeGroup()
Removes the selected tag or smartgroup.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
void listitemsContextMenu(QPoint)
Context menu for the listItems ( symbols list )
Color ramp utilising "Color Brewer" preset color schemes.
int addTag()
Triggers the dialog to add a new tag.
void setSmartgroupName(const QString &)
sets the smart group Name
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
void exportItemsPNG()
Triggers the dialog to export selected items as PNG files.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
void showHelp()
Opens the associated help.
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
void addItem()
Triggers the dialog for adding a new item, based on the currently selected item type tab...
void exportItems()
Triggers the dialog to export items.
bool saveSymbol(const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags)
Adds the symbol to the DB with the tags.
void onClose()
Closes the dialog.
bool removeSymbol(const QString &name)
Removes symbol from style (and delete it)
Container for all settings relating to text rendering.
bool saveLabelSettings(const QString &name, const QgsPalLayerSettings &settings, bool favorite, const QStringList &tags)
Adds label settings to the database.
A dialog which allows users to modify the properties of a QgsCptCityColorRamp.
A simple dialog for customizing text formatting settings.
Style entity type, see QgsStyle::StyleEntity.
QgsColorBrewerColorRamp ramp
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
bool addFavorite(StyleEntity type, const QString &name)
Adds the specified symbol to favorites.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
QgsLimitedRandomColorRamp ramp
bool removeLabelSettings(const QString &name)
Removes label settings from the style.
void setConditionMap(const QgsSmartConditionMap &)
sets up the GUI for the given conditionmap
QString variantName() const
bool detagSymbol(StyleEntity type, const QString &symbol, const QStringList &tags)
Detags the symbol with the given list.
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
QMultiMap< QString, QString > QgsSmartConditionMap
A multimap to hold the smart group conditions as constraint and parameter pairs.
bool saveAsGradientRamp() const
Returns true if the ramp should be converted to a QgsGradientColorRamp.
void removeItem()
Removes the current selected item.
QgsSymbolGroupMap smartgroupsListMap()
Returns the smart groups map with id as key and name as value.
Q_DECL_DEPRECATED bool removeSymbol() SIP_DEPRECATED
void detagSelectedSymbols()
Remove all tags from selected symbols.
Symbol type (for symbol entities)
QString conditionOperator()
returns the AND/OR condition
void enableGroupInputs(bool)
Enables or disables the groupTree specific inputs.
void pushCritical(const QString &title, const QString &message)
Pushes a critical warning with default timeout to the message bar.
QStringList symbolNames() const
Returns a list of names of symbols.
QgsWkbTypes::GeometryType layerType
Geometry type of layers associated with these settings.