36 #include <QFileDialog> 37 #include <QInputDialog> 38 #include <QMessageBox> 39 #include <QPushButton> 40 #include <QStandardItemModel> 47 : QDialog( parent, flags )
51 connect( tabItemType, &QTabWidget::currentChanged,
this, &QgsStyleManagerDialog::tabItemType_currentChanged );
56 setWindowModality( Qt::WindowModal );
61 restoreGeometry( settings.
value( QStringLiteral(
"Windows/StyleV2Manager/geometry" ) ).toByteArray() );
62 mSplitter->setSizes( QList<int>() << 170 << 540 );
63 mSplitter->restoreState( settings.
value( QStringLiteral(
"Windows/StyleV2Manager/splitter" ) ).toByteArray() );
65 tabItemType->setDocumentMode(
true );
66 searchBox->setShowSearchIcon(
true );
67 searchBox->setPlaceholderText( tr(
"Filter symbols…" ) );
73 connect( btnAddItem, &QPushButton::clicked,
this, [ = ](
bool ) {
addItem(); }
75 connect( btnEditItem, &QPushButton::clicked,
this, [ = ](
bool ) {
editItem(); }
77 connect( actnEditItem, &QAction::triggered,
this, [ = ](
bool ) {
editItem(); }
79 connect( btnRemoveItem, &QPushButton::clicked,
this, [ = ](
bool ) {
removeItem(); }
81 connect( actnRemoveItem, &QAction::triggered,
this, [ = ](
bool ) {
removeItem(); }
84 QMenu *shareMenu =
new QMenu( tr(
"Share Menu" ),
this );
85 QAction *exportAction =
new QAction( tr(
"Export Item(s)…" ),
this );
87 shareMenu->addAction( exportAction );
88 QAction *importAction =
new QAction( tr(
"Import Item(s)…" ),
this );
90 shareMenu->addAction( importAction );
91 shareMenu->addSeparator();
92 shareMenu->addAction( actnExportAsPNG );
93 shareMenu->addAction( actnExportAsSVG );
98 btnShare->setMenu( shareMenu );
100 QStandardItemModel *model =
new QStandardItemModel( listItems );
101 listItems->setModel( model );
102 listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
105 connect( listItems->selectionModel(), &QItemSelectionModel::currentChanged,
107 connect( listItems->selectionModel(), &QItemSelectionModel::selectionChanged,
112 QStandardItemModel *groupModel =
new QStandardItemModel( groupTree );
113 groupTree->setModel( groupModel );
114 groupTree->setHeaderHidden(
true );
116 groupTree->setCurrentIndex( groupTree->model()->index( 0, 0 ) );
118 connect( groupTree->selectionModel(), &QItemSelectionModel::currentChanged,
120 connect( groupModel, &QStandardItemModel::itemChanged,
123 QMenu *groupMenu =
new QMenu( tr(
"Group Actions" ),
this );
125 groupMenu->addAction( actnTagSymbols );
127 actnFinishTagging->setVisible(
false );
128 groupMenu->addAction( actnFinishTagging );
129 groupMenu->addAction( actnEditSmartGroup );
130 btnManageGroups->setMenu( groupMenu );
135 groupTree->setContextMenuPolicy( Qt::CustomContextMenu );
136 connect( groupTree, &QWidget::customContextMenuRequested,
140 listItems->setContextMenuPolicy( Qt::CustomContextMenu );
141 connect( listItems, &QWidget::customContextMenuRequested,
145 QStringList rampTypes;
146 rampTypes << tr(
"Gradient" ) << tr(
"Color presets" ) << tr(
"Random" ) << tr(
"Catalog: cpt-city" );
147 rampTypes << tr(
"Catalog: ColorBrewer" );
148 mMenuBtnAddItemColorRamp =
new QMenu(
this );
149 for (
const QString &rampType : qgis::as_const( rampTypes ) )
150 mMenuBtnAddItemColorRamp->addAction(
new QAction( rampType,
this ) );
151 connect( mMenuBtnAddItemColorRamp, &QMenu::triggered,
155 mGroupMenu =
new QMenu(
this );
157 mGroupMenu->addAction( actnAddFavorite );
159 mGroupMenu->addAction( actnRemoveFavorite );
160 mGroupMenu->addSeparator()->setParent(
this );
161 mGroupListMenu =
new QMenu( mGroupMenu );
162 mGroupListMenu->setTitle( tr(
"Add to Tag" ) );
163 mGroupListMenu->setEnabled(
false );
164 mGroupMenu->addMenu( mGroupListMenu );
165 actnDetag->setData( 0 );
167 mGroupMenu->addAction( actnDetag );
168 mGroupMenu->addSeparator()->setParent(
this );
169 mGroupMenu->addAction( actnRemoveItem );
170 mGroupMenu->addAction( actnEditItem );
171 mGroupMenu->addSeparator()->setParent(
this );
172 mGroupMenu->addAction( actnExportAsPNG );
173 mGroupMenu->addAction( actnExportAsSVG );
176 mGroupTreeContextMenu =
new QMenu(
this );
178 mGroupTreeContextMenu->addAction( actnEditSmartGroup );
179 connect( actnAddTag, &QAction::triggered,
this, [ = ](
bool ) {
addTag(); }
181 mGroupTreeContextMenu->addAction( actnAddTag );
182 connect( actnAddSmartgroup, &QAction::triggered,
this, [ = ](
bool ) {
addSmartgroup(); }
184 mGroupTreeContextMenu->addAction( actnAddSmartgroup );
186 mGroupTreeContextMenu->addAction( actnRemoveGroup );
188 tabItemType_currentChanged( 0 );
203 settings.
setValue( QStringLiteral(
"Windows/StyleV2Manager/splitter" ), mSplitter->saveState() );
210 int current = ( tabItemType->count() > 0 ? tabItemType->currentIndex() : 0 );
213 int markerCount = 0, lineCount = 0, fillCount = 0;
216 for (
int i = 0; i < symbolNames.count(); ++i )
230 Q_ASSERT( 0 &&
"unknown symbol type" );
235 cboItemType->clear();
236 cboItemType->addItem( tr(
"Marker symbol (%1)" ).arg( markerCount ), QVariant(
QgsSymbol::Marker ) );
237 cboItemType->addItem( tr(
"Line symbol (%1)" ).arg( lineCount ), QVariant(
QgsSymbol::Line ) );
238 cboItemType->addItem( tr(
"Fill symbol (%1)" ).arg( fillCount ), QVariant(
QgsSymbol::Fill ) );
240 cboItemType->addItem( tr(
"Color ramp (%1)" ).arg( mStyle->
colorRampCount() ), QVariant( 3 ) );
243 cboItemType->setCurrentIndex( current );
247 void QgsStyleManagerDialog::tabItemType_currentChanged(
int )
251 searchBox->setPlaceholderText( flag ? tr(
"Filter symbols…" ) : tr(
"Filter color ramps…" ) );
252 btnAddItem->setMenu( flag ?
nullptr : mMenuBtnAddItemColorRamp );
253 actnExportAsPNG->setVisible( flag );
254 actnExportAsSVG->setVisible( flag );
257 listItems->setIconSize( QSize( static_cast< int >( iconSize ), static_cast< int >( iconSize * 0.9 ) ) );
266 Q_ASSERT(
false &&
"not implemented" );
269 groupChanged( groupTree->selectionModel()->currentIndex() );
274 QStandardItemModel *model = qobject_cast<QStandardItemModel *>( listItems->model() );
278 for (
int i = 0; i < symbolNames.count(); ++i )
280 QString name = symbolNames[i];
281 std::unique_ptr< QgsSymbol > symbol( mStyle->
symbol( name ) );
282 if ( symbol && symbol->type() == type )
285 QStandardItem *item =
new QStandardItem( name );
287 item->setIcon( icon );
288 item->setData( name );
289 QFont f = item->data( Qt::FontRole ).value< QFont >();
291 item->setData( f, Qt::FontRole );
292 item->setCheckable( check );
293 item->setToolTip( QStringLiteral(
"<b>%1</b><br><i>%2</i>" ).arg( name, tags.count() > 0 ? tags.join( QStringLiteral(
", " ) ) : tr(
"Not tagged" ) ) );
295 model->appendRow( item );
305 QStandardItemModel *model = qobject_cast<QStandardItemModel *>( listItems->model() );
308 for (
int i = 0; i < colorRamps.count(); ++i )
310 QString name = colorRamps[i];
311 std::unique_ptr< QgsColorRamp > ramp( mStyle->
colorRamp( name ) );
313 QStandardItem *item =
new QStandardItem( name );
315 item->setIcon( icon );
316 item->setData( name );
317 item->setCheckable( check );
318 item->setToolTip( name );
319 model->appendRow( item );
327 switch ( tabItemType->currentIndex() )
344 QModelIndex index = listItems->selectionModel()->currentIndex();
345 if ( !index.isValid() )
347 return index.model()->data( index, 0 ).toString();
352 bool changed =
false;
363 Q_ASSERT(
false &&
"not implemented" );
377 QString name = tr(
"new symbol" );
382 name = tr(
"new marker" );
386 name = tr(
"new line" );
390 name = tr(
"new fill symbol" );
393 Q_ASSERT(
false &&
"unknown symbol type" );
403 if ( dlg.exec() == 0 )
410 if ( !saveDlg.exec() )
416 name = saveDlg.
name();
419 bool nameInvalid =
true;
420 while ( nameInvalid )
423 if ( name.isEmpty() )
425 QMessageBox::warning(
this, tr(
"Save Symbol" ),
426 tr(
"Cannot save symbol without name. Enter a name." ) );
430 int res = QMessageBox::warning(
this, tr(
"Save Symbol" ),
431 tr(
"Symbol with name '%1' already exists. Overwrite?" )
433 QMessageBox::Yes | QMessageBox::No );
434 if ( res == QMessageBox::Yes )
448 name = QInputDialog::getText(
this, tr(
"Symbol Name" ),
449 tr(
"Please enter a name for new symbol:" ),
450 QLineEdit::Normal, name, &ok );
459 QStringList symbolTags = saveDlg.
tags().split(
',' );
474 if ( rampType.isEmpty() )
476 QStringList rampTypes;
477 rampTypes << tr(
"Gradient" ) << tr(
"Color presets" ) << tr(
"Random" ) << tr(
"Catalog: cpt-city" );
478 rampTypes << tr(
"Catalog: ColorBrewer" );
479 rampType = QInputDialog::getItem( parent, tr(
"Color Ramp Type" ),
480 tr(
"Please select color ramp type:" ), rampTypes, 0,
false, &ok );
482 if ( !ok || rampType.isEmpty() )
485 QString name = tr(
"new ramp" );
487 std::unique_ptr< QgsColorRamp > ramp;
488 if ( rampType == tr(
"Gradient" ) )
496 name = tr(
"new gradient ramp" );
498 else if ( rampType == tr(
"Random" ) )
506 name = tr(
"new random ramp" );
508 else if ( rampType == tr(
"Catalog: ColorBrewer" ) )
518 else if ( rampType == tr(
"Color presets" ) )
526 name = tr(
"new preset ramp" );
528 else if ( rampType == tr(
"Catalog: cpt-city" ) )
550 QgsDebugMsg( QStringLiteral(
"invalid ramp type %1" ).arg( rampType ) );
555 if ( !saveDlg.exec() )
560 name = saveDlg.
name();
563 bool nameInvalid =
true;
564 while ( nameInvalid )
567 if ( name.isEmpty() )
569 QMessageBox::warning( parent, tr(
"Save Color Ramp" ),
570 tr(
"Cannot save color ramp without name. Enter a name." ) );
574 int res = QMessageBox::warning( parent, tr(
"Save Color Ramp" ),
575 tr(
"Color ramp with name '%1' already exists. Overwrite?" )
577 QMessageBox::Yes | QMessageBox::No );
578 if ( res == QMessageBox::Yes )
591 name = QInputDialog::getText( parent, tr(
"Color Ramp Name" ),
592 tr(
"Please enter a name for new color ramp:" ),
593 QLineEdit::Normal, name, &ok );
601 QStringList colorRampTags = saveDlg.
tags().split(
',' );
614 setWindowState( windowState() & ~Qt::WindowMinimized );
627 action ? action->text() : QString() );
628 if ( !rampName.isEmpty() )
640 bool changed =
false;
651 Q_ASSERT(
false &&
"not implemented" );
661 if ( symbolName.isEmpty() )
664 std::unique_ptr< QgsSymbol > symbol( mStyle->
symbol( symbolName ) );
668 if ( dlg.exec() == 0 )
674 mStyle->
addSymbol( symbolName, symbol.release(), true );
682 if ( name.isEmpty() )
685 std::unique_ptr< QgsColorRamp > ramp( mStyle->
colorRamp( name ) );
687 if ( ramp->type() == QLatin1String(
"gradient" ) )
697 else if ( ramp->type() == QLatin1String(
"random" ) )
707 else if ( ramp->type() == QLatin1String(
"colorbrewer" ) )
717 else if ( ramp->type() == QLatin1String(
"preset" ) )
727 else if ( ramp->type() == QLatin1String(
"cpt-city" ) )
746 Q_ASSERT(
false &&
"invalid ramp type" );
757 bool changed =
false;
768 Q_ASSERT(
false &&
"not implemented" );
780 const QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
781 if ( QMessageBox::Yes != QMessageBox::question(
this, tr(
"Remove Symbol" ),
782 QString( tr(
"Do you really want to remove %n symbol(s)?",
nullptr, indexes.count() ) ),
789 for (
const QModelIndex &index : indexes )
791 QString symbolName = index.data().toString();
793 if ( !symbolName.isEmpty() )
802 const QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
803 if ( QMessageBox::Yes != QMessageBox::question(
this, tr(
"Remove Color Ramp" ),
804 QString( tr(
"Do you really want to remove %n ramp(s)?",
nullptr, indexes.count() ) ),
811 for (
const QModelIndex &index : indexes )
813 QString rampName = index.data().toString();
815 if ( !rampName.isEmpty() )
825 QString oldName = item->data().toString();
827 bool changed =
false;
830 changed = mStyle->
renameSymbol( oldName, item->text() );
844 QMessageBox::critical(
this, tr(
"Save Item" ),
845 tr(
"Name is already taken by another item. Choose a different name." ) );
846 item->setText( oldName );
852 QString dir = QFileDialog::getExistingDirectory(
this, tr(
"Export Selected Symbols as PNG" ),
853 QDir::home().absolutePath(),
854 QFileDialog::ShowDirsOnly
855 | QFileDialog::DontResolveSymlinks );
861 QString dir = QFileDialog::getExistingDirectory(
this, tr(
"Export Selected Symbols as SVG" ),
862 QDir::home().absolutePath(),
863 QFileDialog::ShowDirsOnly
864 | QFileDialog::DontResolveSymlinks );
874 const QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
875 for (
const QModelIndex &index : indexes )
877 QString name = index.data().toString();
878 QString path = dir +
'/' + name +
'.' + format;
879 std::unique_ptr< QgsSymbol > sym( mStyle->
symbol( name ) );
881 sym->exportImage( path, format, size );
901 QFont font = item->font();
902 font.setBold(
true );
903 item->setFont( font );
908 if ( mBlockGroupUpdates )
911 QStandardItemModel *model = qobject_cast<QStandardItemModel *>( groupTree->model() );
914 QStandardItem *favoriteSymbols =
new QStandardItem( tr(
"Favorites" ) );
915 favoriteSymbols->setData(
"favorite" );
916 favoriteSymbols->setEditable(
false );
918 model->appendRow( favoriteSymbols );
920 QStandardItem *allSymbols =
new QStandardItem( tr(
"All" ) );
921 allSymbols->setData(
"all" );
922 allSymbols->setEditable(
false );
924 model->appendRow( allSymbols );
926 QStandardItem *taggroup =
new QStandardItem( QString() );
927 taggroup->setData(
"tags" );
928 taggroup->setEditable(
false );
929 QStringList tags = mStyle->
tags();
931 for (
const QString &tag : qgis::as_const( tags ) )
933 QStandardItem *item =
new QStandardItem( tag );
934 item->setData( mStyle->
tagId( tag ) );
935 taggroup->appendRow( item );
937 taggroup->setText( tr(
"Tags" ) );
939 model->appendRow( taggroup );
941 QStandardItem *smart =
new QStandardItem( tr(
"Smart Groups" ) );
942 smart->setData(
"smartgroups" );
943 smart->setEditable(
false );
946 QgsSymbolGroupMap::const_iterator i = sgMap.constBegin();
947 while ( i != sgMap.constEnd() )
949 QStandardItem *item =
new QStandardItem( i.value() );
950 item->setData( i.key() );
951 smart->appendRow( item );
954 model->appendRow( smart );
957 int rows = model->rowCount( model->indexFromItem( model->invisibleRootItem() ) );
958 for (
int i = 0; i < rows; i++ )
960 groupTree->setExpanded( model->indexFromItem( model->item( i ) ),
true );
966 QStringList symbolNames;
967 QStringList groupSymbols;
972 QgsDebugMsg( QStringLiteral(
"Entity not implemented" ) );
976 QString category = index.data( Qt::UserRole + 1 ).toString();
977 if ( category == QLatin1String(
"all" ) || category == QLatin1String(
"tags" ) || category == QLatin1String(
"smartgroups" ) )
980 if ( category == QLatin1String(
"tags" ) )
982 actnAddTag->setEnabled(
true );
983 actnAddSmartgroup->setEnabled(
false );
985 else if ( category == QLatin1String(
"smartgroups" ) )
987 actnAddTag->setEnabled(
false );
988 actnAddSmartgroup->setEnabled(
true );
992 else if ( category == QLatin1String(
"favorite" ) )
997 else if ( index.parent().data( Qt::UserRole + 1 ) ==
"smartgroups" )
999 actnRemoveGroup->setEnabled(
true );
1000 btnManageGroups->setEnabled(
true );
1001 int groupId = index.data( Qt::UserRole + 1 ).toInt();
1007 int tagId = index.data( Qt::UserRole + 1 ).toInt();
1009 if ( mGrouppingMode && tagId )
1011 groupSymbols = symbolNames;
1026 if ( mGrouppingMode )
1031 actnEditSmartGroup->setVisible(
false );
1032 actnAddTag->setVisible(
false );
1033 actnAddSmartgroup->setVisible(
false );
1034 actnRemoveGroup->setVisible(
false );
1035 actnTagSymbols->setVisible(
false );
1036 actnFinishTagging->setVisible(
false );
1038 if ( index.parent().isValid() )
1040 if ( index.parent().data( Qt::UserRole + 1 ).toString() == QLatin1String(
"smartgroups" ) )
1042 actnEditSmartGroup->setVisible( !mGrouppingMode );
1044 else if ( index.parent().data( Qt::UserRole + 1 ).toString() == QLatin1String(
"tags" ) )
1046 actnAddTag->setVisible( !mGrouppingMode );
1047 actnTagSymbols->setVisible( !mGrouppingMode );
1048 actnFinishTagging->setVisible( mGrouppingMode );
1050 actnRemoveGroup->setVisible(
true );
1052 else if ( index.data( Qt::UserRole + 1 ) ==
"smartgroups" )
1054 actnAddSmartgroup->setVisible( !mGrouppingMode );
1056 else if ( index.data( Qt::UserRole + 1 ) ==
"tags" )
1058 actnAddTag->setVisible( !mGrouppingMode );
1064 QStandardItemModel *model = qobject_cast<QStandardItemModel *>( groupTree->model() );
1066 for (
int i = 0; i < groupTree->model()->rowCount(); i++ )
1068 index = groupTree->model()->index( i, 0 );
1069 QString data = index.data( Qt::UserRole + 1 ).toString();
1070 if ( data == QLatin1String(
"tags" ) )
1079 itemName = QInputDialog::getText(
this, tr(
"Add Tag" ),
1080 tr(
"Please enter name for the new tag:" ), QLineEdit::Normal, tr(
"New tag" ), &ok ).trimmed();
1081 if ( !ok || itemName.isEmpty() )
1084 int check = mStyle->
tagId( itemName );
1087 QMessageBox::critical(
this, tr(
"Add Tag" ),
1088 tr(
"Tag name already exists in your symbol database." ) );
1094 mBlockGroupUpdates++;
1095 id = mStyle->
addTag( itemName );
1096 mBlockGroupUpdates--;
1100 QMessageBox::critical(
this, tr(
"Add Tag" ),
1101 tr(
"New tag could not be created.\n" 1102 "There was a problem with your symbol database." ) );
1106 QStandardItem *parentItem = model->itemFromIndex( index );
1107 QStandardItem *childItem =
new QStandardItem( itemName );
1108 childItem->setData(
id );
1109 parentItem->appendRow( childItem );
1116 QStandardItemModel *model = qobject_cast<QStandardItemModel *>( groupTree->model() );
1118 for (
int i = 0; i < groupTree->model()->rowCount(); i++ )
1120 index = groupTree->model()->index( i, 0 );
1121 QString data = index.data( Qt::UserRole + 1 ).toString();
1122 if ( data == QLatin1String(
"smartgroups" ) )
1131 if ( dlg.exec() == QDialog::Rejected )
1136 mBlockGroupUpdates++;
1138 mBlockGroupUpdates--;
1144 QStandardItem *parentItem = model->itemFromIndex( index );
1145 QStandardItem *childItem =
new QStandardItem( itemName );
1146 childItem->setData(
id );
1147 parentItem->appendRow( childItem );
1154 QStandardItemModel *model = qobject_cast<QStandardItemModel *>( groupTree->model() );
1155 QModelIndex index = groupTree->currentIndex();
1158 QString data = index.data( Qt::UserRole + 1 ).toString();
1159 if ( data == QLatin1String(
"all" ) || data == QLatin1String(
"favorite" ) || data == QLatin1String(
"tags" ) || index.data() ==
"smartgroups" )
1161 int err = QMessageBox::critical(
this, tr(
"Remove Group" ),
1162 tr(
"Invalid selection. Cannot delete system defined categories.\n" 1163 "Kindly select a group or smart group you might want to delete." ) );
1168 QStandardItem *parentItem = model->itemFromIndex( index.parent() );
1172 mBlockGroupUpdates++;
1174 if ( parentItem->data( Qt::UserRole + 1 ).toString() == QLatin1String(
"smartgroups" ) )
1183 mBlockGroupUpdates--;
1184 parentItem->removeRow( index.row() );
1189 QgsDebugMsg( QStringLiteral(
"Symbol group edited: data=%1 text=%2" ).arg( item->data( Qt::UserRole + 1 ).toString(), item->text() ) );
1190 int id = item->data( Qt::UserRole + 1 ).toInt();
1191 QString name = item->text();
1192 mBlockGroupUpdates++;
1193 if ( item->parent()->data( Qt::UserRole + 1 ) ==
"smartgroups" )
1201 mBlockGroupUpdates--;
1207 QStandardItemModel *treeModel = qobject_cast<QStandardItemModel *>( groupTree->model() );
1208 QStandardItemModel *model = qobject_cast<QStandardItemModel *>( listItems->model() );
1210 if ( mGrouppingMode )
1212 mGrouppingMode =
false;
1213 actnTagSymbols->setVisible(
true );
1214 actnFinishTagging->setVisible(
false );
1216 disconnect( model, &QStandardItemModel::itemChanged,
1224 connect( treeModel, &QStandardItemModel::itemChanged,
1226 connect( model, &QStandardItemModel::itemChanged,
1229 listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
1233 bool validGroup =
false;
1235 QModelIndex present = groupTree->currentIndex();
1236 while ( present.parent().isValid() )
1238 if ( present.parent().data() ==
"Tags" )
1243 present = present.parent();
1248 mGrouppingMode =
true;
1250 actnTagSymbols->setVisible(
false );
1251 actnFinishTagging->setVisible(
true );
1253 disconnect( treeModel, &QStandardItemModel::itemChanged,
1255 disconnect( model, &QStandardItemModel::itemChanged,
1261 btnManageGroups->setEnabled(
true );
1265 connect( model, &QStandardItemModel::itemChanged,
1269 listItems->setSelectionMode( QAbstractItemView::NoSelection );
1278 QgsDebugMsg( QStringLiteral(
"Unknown style entity" ) );
1282 QStandardItemModel *treeModel = qobject_cast<QStandardItemModel *>( groupTree->model() );
1283 QString tag = treeModel->itemFromIndex( groupTree->currentIndex() )->text();
1285 QString symbolName = item->text();
1287 if ( item->checkState() == Qt::Checked )
1288 regrouped = mStyle->
tagSymbol( type, symbolName, QStringList( tag ) );
1290 regrouped = mStyle->
detagSymbol( type, symbolName, QStringList( tag ) );
1293 int er = QMessageBox::critical(
this, tr(
"Group Items" ),
1294 tr(
"There was a problem with the symbols database while regrouping." ) );
1303 QStandardItemModel *model = qobject_cast<QStandardItemModel *>( listItems->model() );
1304 for (
const QString &symbol : symbols )
1306 const QList<QStandardItem *> items = model->findItems( symbol );
1307 for ( QStandardItem *item : items )
1308 item->setCheckState( Qt::Checked );
1329 actnEditItem->setEnabled( index.isValid() && !mGrouppingMode );
1334 Q_UNUSED( selected );
1335 Q_UNUSED( deselected );
1336 bool nothingSelected = listItems->selectionModel()->selectedIndexes().empty();
1337 actnRemoveItem->setDisabled( nothingSelected );
1338 actnAddFavorite->setDisabled( nothingSelected );
1339 actnRemoveFavorite->setDisabled( nothingSelected );
1340 mGroupListMenu->setDisabled( nothingSelected );
1341 actnDetag->setDisabled( nothingSelected );
1342 actnExportAsPNG->setDisabled( nothingSelected );
1343 actnExportAsSVG->setDisabled( nothingSelected );
1344 actnEditItem->setDisabled( nothingSelected );
1349 groupTree->setEnabled( enable );
1350 btnAddTag->setEnabled( enable );
1351 btnAddSmartgroup->setEnabled( enable );
1352 actnAddTag->setEnabled( enable );
1353 actnAddSmartgroup->setEnabled( enable );
1354 actnRemoveGroup->setEnabled( enable );
1355 btnManageGroups->setEnabled( enable || mGrouppingMode );
1356 searchBox->setEnabled( enable );
1361 actnRemoveGroup->setEnabled( enable );
1362 btnManageGroups->setEnabled( enable || mGrouppingMode );
1367 QStandardItemModel *treeModel = qobject_cast<QStandardItemModel *>( groupTree->model() );
1368 for (
int i = 0; i < treeModel->rowCount(); i++ )
1370 treeModel->item( i )->setEnabled( enable );
1372 if ( treeModel->item( i )->data() ==
"smartgroups" )
1374 for (
int j = 0; j < treeModel->item( i )->rowCount(); j++ )
1376 treeModel->item( i )->child( j )->setEnabled( enable );
1383 for (
int i = 0; i < symbolBtnsLayout->count(); i++ )
1385 QWidget *w = qobject_cast<QWidget *>( symbolBtnsLayout->itemAt( i )->widget() );
1387 w->setEnabled( enable );
1391 actnRemoveItem->setEnabled( enable );
1392 actnEditItem->setEnabled( enable );
1397 QPoint globalPos = groupTree->viewport()->mapToGlobal( point );
1399 QModelIndex index = groupTree->indexAt( point );
1400 QgsDebugMsg( QStringLiteral(
"Now you clicked: %1" ).arg( index.data().toString() ) );
1402 if ( index.isValid() && !mGrouppingMode )
1403 mGroupTreeContextMenu->popup( globalPos );
1408 QPoint globalPos = listItems->viewport()->mapToGlobal( point );
1411 mGroupListMenu->clear();
1413 QAction *a =
nullptr;
1414 QStringList tags = mStyle->
tags();
1416 for (
const QString &tag : qgis::as_const( tags ) )
1418 a =
new QAction( tag, mGroupListMenu );
1422 mGroupListMenu->addAction( a );
1425 if ( tags.count() > 0 )
1427 mGroupListMenu->addSeparator();
1429 a =
new QAction( tr(
"Create New Tag…" ), mGroupListMenu );
1432 mGroupListMenu->addAction( a );
1434 mGroupMenu->popup( globalPos );
1442 QgsDebugMsg( QStringLiteral(
"unknown entity type" ) );
1446 const QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1447 for (
const QModelIndex &index : indexes )
1449 mStyle->
addFavorite( type, index.data().toString() );
1459 QgsDebugMsg( QStringLiteral(
"unknown entity type" ) );
1463 const QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1464 for (
const QModelIndex &index : indexes )
1473 QAction *selectedItem = qobject_cast<QAction *>( sender() );
1479 QgsDebugMsg( QStringLiteral(
"unknown entity type" ) );
1492 tag = mStyle->
tag(
id );
1496 tag = selectedItem->data().toString();
1499 const QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1500 for (
const QModelIndex &index : indexes )
1502 mStyle->
tagSymbol( type, index.data().toString(), QStringList( tag ) );
1506 QgsDebugMsg( QStringLiteral(
"Selected Action: %1" ).arg( selectedItem->text() ) );
1512 QAction *selectedItem = qobject_cast<QAction *>( sender() );
1519 QgsDebugMsg( QStringLiteral(
"unknown entity type" ) );
1522 const QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1523 for (
const QModelIndex &index : indexes )
1525 mStyle->
detagSymbol( type, index.data().toString() );
1529 QgsDebugMsg( QStringLiteral(
"Selected Action: %1" ).arg( selectedItem->text() ) );
1535 QStandardItemModel *treeModel = qobject_cast<QStandardItemModel *>( groupTree->model() );
1538 QModelIndex present = groupTree->currentIndex();
1539 if ( present.parent().data( Qt::UserRole + 1 ) !=
"smartgroups" )
1541 QMessageBox::critical(
this, tr(
"Edit Smart Group" ),
1542 tr(
"You have not selected a Smart Group. Kindly select a Smart Group to edit." ) );
1545 QStandardItem *item = treeModel->itemFromIndex( present );
1553 if ( dlg.exec() == QDialog::Rejected )
1556 mBlockGroupUpdates++;
1559 mBlockGroupUpdates--;
1562 QMessageBox::critical(
this, tr(
"Edit Smart Group" ),
1563 tr(
"There was some error while editing the smart group." ) );
1567 item->setData(
id );
1579 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/style_library.html#the-style-manager" ) );
void groupChanged(const QModelIndex &)
void tagSymbolsAction()
carry out symbol tagging using check boxes
bool isFavorite() const
returns whether the favorite element is checked
void populateTypes()
populate combo box with known style items (symbols, color ramps)
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.
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.
bool addSymbol()
add a new symbol to style
Abstract base class for all rendered symbols.
a dialog for setting properties of a newly saved style.
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()
adds symbols of some type to list
void onFinished()
called when the dialog is going to be closed
QgsColorRamp * colorRamp(const QString &name) const
Returns a new copy of the specified color ramp.
QgsSmartConditionMap conditionMap()
returns the condition map
int addSmartgroup()
add a smartgroup
void setSymbolsChecked(const QStringList &)
to set symbols checked when in editing mode
void selectedSymbolsChanged(const QItemSelection &selected, const QItemSelection &deselected)
Perform tasks when the selected symbols change.
QStringList tagsOfSymbol(StyleEntity type, const QString &symbol)
Returns the tags associated with the symbol.
Abstract base class for color ramps.
QMap< int, QString > QgsSymbolGroupMap
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.
int colors() const
Returns the number of colors in the ramp.
void populateGroups()
populate the groups
bool tagSymbol(StyleEntity type, const QString &symbol, const QStringList &tags)
Tags the symbol with the tags in the list.
QgsGradientColorRamp * cloneGradientRamp() const
void filterSymbols(const QString &)
filter the symbols based on input search term
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
const QgsSymbol * symbolRef(const QString &name) const
Returns a const pointer to a symbol (doesn't create new instance)
bool addColorRamp()
add a new color ramp to style
QString schemeName() const
A dialog which allows users to modify the properties of a QgsColorBrewerColorRamp.
QStringList symbolsWithTag(StyleEntity type, int tagid) const
Returns the symbol names with which have the given tag.
void populateSymbols(const QStringList &symbolNames, bool checkable=false)
populate list view with symbols of the current type with the given names
QString smartgroupName()
returns the value from mNameLineEdit
bool removeColorRamp(const QString &name)
Removes color ramp from style (and delete it)
bool rename(StyleEntity type, int id, const QString &newName)
Renames the given entity with the specified id.
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.
A dialog which allows users to modify the properties of a QgsLimitedRandomColorRamp.
StyleEntity
Enum for Entities involved in a style.
void saveGeometry(QWidget *widget, const QString &keyName)
Save the wigget geometry into settings.
QString currentItemName()
void tagSelectedSymbols(bool newTag=false)
Tag selected symbols using menu item selection.
bool restoreGeometry(QWidget *widget, const QString &keyName)
Restore the wigget geometry from settings.
QgsGradientColorRamp * clone() const override
Creates a clone of the color ramp.
bool renameSymbol(const QString &oldName, const QString &newName)
Renames a symbol from oldName to newName.
QString variantName() const
Constrained random color ramp, which returns random colors based on preset parameters.
static QIcon symbolPreviewIcon(QgsSymbol *symbol, QSize size, int padding=0)
Returns an icon preview for a color ramp.
QStringList symbolNames()
Returns a list of names of symbols.
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 QIcon colorRampPreviewIcon(QgsColorRamp *ramp, QSize size, int padding=0)
Returns an icon preview for a color ramp.
bool remove(StyleEntity type, int id)
Removes the specified entity from the db.
QStringList findSymbols(StyleEntity type, const QString &qword)
Returns the names of the symbols which have a matching 'substring' in its definition.
void groupsModified()
Is 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()
edit the selected smart group
void exportSelectedItemsImages(const QString &dir, const QString &format, QSize size)
int addTag(const QString &tagName)
Adds a new tag and returns the tag's id.
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
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...
void removeFavoriteSelectedSymbols()
Remove selected symbols from favorites.
A scheme based color ramp consisting of a list of predefined colors.
void itemChanged(QStandardItem *item)
QgsSmartConditionMap smartgroup(int id)
Returns the QgsSmartConditionMap for the given id.
QStringList colorRampNames()
Returns a list of names of color ramps.
QgsLimitedRandomColorRamp * clone() const override
Creates a clone of the color ramp.
QStringList symbolsOfSmartgroup(StyleEntity type, int id)
Returns the symbols for the smartgroup.
void enableSymbolInputs(bool)
Enables or disbables the symbol specific inputs.
int tagId(const QString &tag)
Returns the DB id for the given tag name.
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.
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
QString name() const
returns the text value of the name element
void removeGroup()
remove a tag or smartgroup
SymbolType type() const
Returns the symbol's type.
bool saveAsGradientRamp() const
Returns true if the ramp should be converted to a QgsGradientColorRamp.
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.
bool renameColorRamp(const QString &oldName, const QString &newName)
Changes ramp's name.
int colorRampCount()
Returns count of color ramps.
void setSmartgroupName(const QString &)
sets the smart group Name
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
void showHelp()
Open the associated help.
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
bool saveSymbol(const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags)
Adds the symbol to the DB with the tags.
void onClose()
Close the dialog.
bool removeSymbol(const QString &name)
Removes symbol from style (and delete it)
A dialog which allows users to modify the properties of a QgsCptCityColorRamp.
QgsColorBrewerColorRamp ramp
void groupRenamed(QStandardItem *)
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 ...
QgsStyleManagerDialog(QgsStyle *style, QWidget *parent SIP_TRANSFERTHIS=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsStyleManagerDialog, with the specified parent widget and window flags...
QgsLimitedRandomColorRamp ramp
void regrouped(QStandardItem *)
symbol changed from one group
QStringList tags() const
Returns a list of all tags in the style database.
void populateColorRamps(const QStringList &colorRamps, bool checkable=false)
populate list view with color ramps
void setConditionMap(const QgsSmartConditionMap &)
sets up the GUI for the given conditionmap
QString tags() const
returns the text value of the tags element
QString schemeName() const
Returns the name of the color brewer color scheme.
bool detagSymbol(StyleEntity type, const QString &symbol, const QStringList &tags)
Detags the symbol with the given list.
QMultiMap< QString, QString > QgsSmartConditionMap
A multimap to hold the smart group conditions as constraint and parameter pairs.
QgsSymbolGroupMap smartgroupsListMap()
Returns the smart groups map with id as key and name as value.
void detagSelectedSymbols()
Remove all tags from selected symbols.
QString conditionOperator()
returns the AND/OR condition
QString tag(int id) const
Returns the tag name for the given id.
void enableGroupInputs(bool)
Enables or disables the groupTree specific inputs.