32 #include <QFileDialog> 33 #include <QInputDialog> 34 #include <QMessageBox> 36 #include <QStandardItemModel> 44 :
QDialog( parent ), mStyle( style ), mModified( false )
54 mSplitter->setSizes(
QList<int>() << 170 << 540 );
55 mSplitter->restoreState( settings.
value(
"/Windows/StyleV2Manager/splitter" ).
toByteArray() );
57 tabItemType->setDocumentMode(
true );
58 searchBox->setPlaceholderText(
tr(
"Type here to filter symbols..." ) );
64 connect( btnAddItem, SIGNAL( clicked() ),
this, SLOT(
addItem() ) );
65 connect( actnEditItem, SIGNAL( triggered(
bool ) ),
this, SLOT(
editItem() ) );
66 connect( actnRemoveItem, SIGNAL( triggered(
bool ) ),
this, SLOT(
removeItem() ) );
68 btnRemoveItem->setDefaultAction( actnRemoveItem );
69 btnEditItem->setDefaultAction( actnEditItem );
71 QMenu *shareMenu =
new QMenu(
tr(
"Share menu" ),
this );
84 btnShare->setMenu( shareMenu );
90 listItems->setModel( model );
91 listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
102 groupTree->setModel( groupModel );
103 groupTree->setHeaderHidden(
true );
110 QMenu *groupMenu =
new QMenu(
tr(
"Group actions" ),
this );
112 groupMenu->
addAction( actnGroupSymbols );
114 actnFinishGrouping->setVisible(
false );
115 groupMenu->
addAction( actnFinishGrouping );
116 groupMenu->
addAction( actnEditSmartGroup );
117 btnManageGroups->setMenu( groupMenu );
120 tagsLineEdit->installEventFilter(
this );
123 groupTree->setContextMenuPolicy( Qt::CustomContextMenu );
128 listItems->setContextMenuPolicy( Qt::CustomContextMenu );
134 rampTypes <<
tr(
"Gradient" ) <<
tr(
"Random" ) <<
tr(
"ColorBrewer" );
135 rampTypes <<
tr(
"cpt-city" );
137 Q_FOREACH (
const QString& rampType, rampTypes )
162 connect( actnAddGroup, SIGNAL( triggered(
bool ) ),
this, SLOT(
addGroup() ) );
179 settings.
setValue(
"/Windows/StyleV2Manager/splitter", mSplitter->saveState() );
186 int current = ( tabItemType->count() > 0 ? tabItemType->currentIndex() : 0 );
189 int markerCount = 0, lineCount = 0, fillCount = 0;
192 for (
int i = 0; i < symbolNames.
count(); ++i )
206 Q_ASSERT( 0 &&
"unknown symbol type" );
211 cboItemType->clear();
219 cboItemType->setCurrentIndex( current );
228 actnExportAsPNG->setVisible( flag );
229 actnExportAsSVG->setVisible( flag );
234 listItems->setIconSize(
QSize( 75, 50 ) );
235 listItems->setGridSize(
QSize( 100, 80 ) );
239 listItems->setIconSize(
QSize( 50, 50 ) );
240 listItems->setGridSize(
QSize( 75, 80 ) );
250 Q_ASSERT( 0 &&
"not implemented" );
253 groupChanged( groupTree->selectionModel()->currentIndex() );
263 for (
int i = 0; i < symbolNames.
count(); ++i )
267 if ( symbol && symbol->
type() == type )
290 for (
int i = 0; i < colorRamps.
count(); ++i )
310 switch ( tabItemType->currentIndex() )
335 bool changed =
false;
346 Q_ASSERT( 0 &&
"not implemented" );
365 name =
tr(
"new marker" );
369 name =
tr(
"new line" );
373 name =
tr(
"new fill symbol" );
376 Q_ASSERT( 0 &&
"unknown symbol type" );
386 if ( dlg.
exec() == 0 )
393 bool nameInvalid =
true;
395 while ( nameInvalid )
399 tr(
"Please enter a name for new symbol:" ),
400 QLineEdit::Normal, name, &ok );
410 tr(
"Cannot save symbol without name. Enter a name." ) );
415 tr(
"Symbol with name '%1' already exists. Overwrite?" )
417 QMessageBox::Yes | QMessageBox::No );
418 if ( res == QMessageBox::Yes )
445 rampTypes <<
tr(
"Gradient" ) <<
tr(
"Random" ) <<
tr(
"ColorBrewer" );
446 rampTypes <<
tr(
"cpt-city" );
448 tr(
"Please select color ramp type:" ), rampTypes, 0,
false, &ok );
450 if ( !ok || rampType.
isEmpty() )
456 if ( rampType ==
tr(
"Gradient" ) )
466 name =
tr(
"new gradient ramp" );
468 else if ( rampType ==
tr(
"Random" ) )
478 name =
tr(
"new random ramp" );
480 else if ( rampType ==
tr(
"ColorBrewer" ) )
492 else if ( rampType ==
tr(
"cpt-city" ) )
522 bool nameInvalid =
true;
524 while ( nameInvalid )
528 tr(
"Please enter a name for new color ramp:" ),
529 QLineEdit::Normal, name, &ok );
539 tr(
"Cannot save color ramp without name. Enter a name." ) );
544 tr(
"Color ramp with name '%1' already exists. Overwrite?" )
546 QMessageBox::Yes | QMessageBox::No );
547 if ( res == QMessageBox::Yes )
588 bool changed =
false;
599 Q_ASSERT( 0 &&
"not implemented" );
616 if ( dlg.
exec() == 0 )
636 if ( ramp->
type() ==
"gradient" )
646 else if ( ramp->
type() ==
"random" )
656 else if ( ramp->
type() ==
"colorbrewer" )
666 else if ( ramp->
type() ==
"cpt-city" )
683 Q_ASSERT( 0 &&
"invalid ramp type" );
694 bool changed =
false;
705 Q_ASSERT( 0 &&
"not implemented" );
717 QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
719 QString(
tr(
"Do you really want to remove %n symbol(s)?",
nullptr, indexes.count() ) ),
737 QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
739 QString(
tr(
"Do you really want to remove %n ramps(s)?",
nullptr, indexes.count() ) ),
760 bool changed =
false;
778 tr(
"Name is already taken by another item. Choose a different name." ) );
787 QFileDialog::ShowDirsOnly
788 | QFileDialog::DontResolveSymlinks );
796 QFileDialog::ShowDirsOnly
797 | QFileDialog::DontResolveSymlinks );
807 QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
811 QString path = dir +
'/' + name +
'.' + format;
878 for (
int i = 0; i < rows; i++ )
911 if ( category ==
"all" || category ==
"groups" || category ==
"smartgroups" )
914 if ( category ==
"groups" || category ==
"smartgroups" )
916 btnAddGroup->setEnabled(
true );
917 actnAddGroup->setEnabled(
true );
924 if ( index.
parent().
data( Qt::UserRole + 1 ) ==
"smartgroups" )
926 btnAddGroup->setEnabled(
false );
927 actnAddGroup->setEnabled(
false );
928 btnRemoveGroup->setEnabled(
true );
929 actnRemoveGroup->setEnabled(
true );
930 btnManageGroups->setEnabled(
true );
931 int groupId = index.
data( Qt::UserRole + 1 ).
toInt();
940 int groupId = index.
data( Qt::UserRole + 1 ).
toInt();
944 groupSymbols = symbolNames;
961 actnEditSmartGroup->setVisible(
false );
962 actnAddGroup->setVisible(
false );
963 actnRemoveGroup->setVisible(
false );
964 actnGroupSymbols->setVisible(
false );
965 actnFinishGrouping->setVisible(
false );
979 actnRemoveGroup->setVisible(
true );
981 else if ( index.
data( Qt::UserRole + 1 ) ==
"groups" || index.
data( Qt::UserRole + 1 ) ==
"smartgroups" )
990 QModelIndex parentIndex = groupTree->currentIndex();
993 QString parentData = parentIndex.
data( Qt::UserRole + 1 ).toString();
994 if ( parentData ==
"all" || ( parentIndex.data() ==
"Ungrouped" && parentData ==
"0" ) )
997 tr(
"The parent group you have selected is not user editable.\n" 998 "Kindly select a user defined group." ) );
1004 if ( parentIndex.parent().data( Qt::UserRole + 1 ).toString() ==
"smartgroups" )
1007 tr(
"Creation of nested smart groups are not allowed\n" 1008 "Select the 'Smart Group' to create a new group." ) );
1017 if ( parentData ==
"smartgroups" )
1022 if ( dlg.
exec() == QDialog::Rejected )
1034 itemName =
QString(
tr(
"New Group" ) );
1035 int parentid = ( parentData ==
"groups" ) ? 0 : parentData.
toInt();
1040 tr(
"New group could not be created.\n" 1041 "There was a problem with your symbol database." ) );
1051 groupTree->setCurrentIndex( childItem->
index() );
1054 groupTree->edit( childItem->
index() );
1064 QString data = index.
data( Qt::UserRole + 1 ).toString();
1065 if ( data ==
"all" || data ==
"groups" || data ==
"smartgroups" || index.
data() ==
"Ungrouped" )
1068 tr(
"Cannot delete system defined categories.\n" 1069 "Kindly select a group or smart group you might want to delete." ) );
1075 if ( parentItem->
data( Qt::UserRole + 1 ).
toString() ==
"smartgroups" )
1086 for (
int i = 0; i < item->
rowCount(); i++ )
1098 QgsDebugMsg(
"Symbol group edited: data=" + data +
" text=" + item->
text() );
1099 int id = item->
data( Qt::UserRole + 1 ).
toInt();
1101 if ( item->
parent()->
data( Qt::UserRole + 1 ) ==
"smartgroups" )
1120 actnGroupSymbols->setVisible(
true );
1121 actnFinishGrouping->setVisible(
false );
1136 listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
1140 bool validGroup =
false;
1151 present = present.
parent();
1158 actnGroupSymbols->setVisible(
false );
1159 actnFinishGrouping->setVisible(
true );
1169 btnManageGroups->setEnabled(
true );
1177 listItems->setSelectionMode( QAbstractItemView::NoSelection );
1189 int groupid = groupTree->currentIndex().data( Qt::UserRole + 1 ).toInt();
1193 regrouped =
mStyle->
group( type, symbolName, groupid );
1199 tr(
"There was a problem with the Symbols database while regrouping." ) );
1209 Q_FOREACH (
const QString& symbol, symbols )
1234 QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
1239 QStringList newtags = tagsLineEdit->text().
split(
',', QString::SkipEmptyParts );
1256 Q_FOREACH (
const QString &tag, oldtags )
1259 removetags.
append( tag );
1269 Q_FOREACH (
const QString &tag, newtags )
1286 tagsLineEdit->clear();
1300 Q_UNUSED( selected );
1301 Q_UNUSED( deselected );
1302 bool nothingSelected = listItems->selectionModel()->selectedIndexes().empty();
1303 actnRemoveItem->setDisabled( nothingSelected );
1305 actnUngroup->setDisabled( nothingSelected );
1306 actnExportAsPNG->setDisabled( nothingSelected );
1307 actnExportAsSVG->setDisabled( nothingSelected );
1308 actnEditItem->setDisabled( nothingSelected );
1313 groupTree->setEnabled( enable );
1314 btnAddGroup->setEnabled( enable );
1315 actnAddGroup->setEnabled( enable );
1316 btnRemoveGroup->setEnabled( enable );
1317 actnRemoveGroup->setEnabled( enable );
1319 searchBox->setEnabled( enable );
1320 tagsLineEdit->setEnabled( enable );
1325 btnAddGroup->setEnabled( enable );
1326 btnRemoveGroup->setEnabled( enable );
1327 actnRemoveGroup->setEnabled( enable );
1334 for (
int i = 0; i < treeModel->
rowCount(); i++ )
1336 if ( treeModel->
item( i )->
data() !=
"groups" )
1340 if ( treeModel->
item( i )->
data() ==
"groups" )
1343 for (
int k = 0; k < treeModel->
item( i )->
rowCount(); k++ )
1349 if ( treeModel->
item( i )->
data() ==
"smartgroups" )
1351 for (
int j = 0; j < treeModel->
item( i )->
rowCount(); j++ )
1360 for (
int i = 0; i < symbolBtnsLayout->count(); i++ )
1362 QWidget *w = qobject_cast<
QWidget*>( symbolBtnsLayout->itemAt( i )->widget() );
1368 actnRemoveItem->setEnabled( enable );
1369 actnEditItem->setEnabled( enable );
1374 QPoint globalPos = groupTree->viewport()->mapToGlobal( point );
1385 QPoint globalPos = listItems->viewport()->mapToGlobal( point );
1392 Q_FOREACH (
int groupId, groupIds )
1415 int groupId = selectedItem->
data().
toInt();
1416 QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1433 if ( present.parent().data( Qt::UserRole + 1 ) !=
"smartgroups" )
1436 tr(
"You have not selected a Smart Group. Kindly select a Smart Group to edit." ) );
1447 if ( dlg.
exec() == QDialog::Rejected )
1455 tr(
"There was some error while editing the smart group." ) );
1467 if (( obj == tagsLineEdit ) && ( event->
type() == QEvent::FocusOut ) )
QStringList tagsOfSymbol(StyleEntity type, const QString &symbol)
return the tags associated with the symbol
QString smartgroupOperator(int id)
returns the operator for the smartgroup
QList< int > groupIds() const
return the ids of all the groups in the style
QByteArray toByteArray() const
virtual bool event(QEvent *e)
void remove(StyleEntity type, int id)
remove the specified entity from the db
QgsVectorColorRampV2 * colorRamp(const QString &name)
return a NEW copy of color ramp
QString getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, QFlags< QFileDialog::Option > options)
QMenu * mMenuBtnAddItemColorRamp
Menu for the "Add item" toolbutton when in colorramp mode.
void setIcon(const QIcon &icon)
static QIcon colorRampPreviewIcon(QgsVectorColorRampV2 *ramp, QSize size)
virtual QString type() const =0
bool tagSymbol(StyleEntity type, const QString &symbol, const QStringList &tags)
tags the symbol with the tags in the list
bool group(StyleEntity type, const QString &name, int groupid)
applies the specified group to the symbol or colorramp specified by StyleEntity
void selectedSymbolsChanged(const QItemSelection &selected, const QItemSelection &deselected)
Perform tasks when the selected symbols change.
QStandardItem * invisibleRootItem() const
bool addSymbol(const QString &name, QgsSymbolV2 *symbol, bool update=false)
add symbol to style. takes symbol's ownership
QgsSmartConditionMap conditionMap()
returns the condition map
void itemChanged(QStandardItem *item)
void groupChanged(const QModelIndex &)
void enableItemsForGroupingMode(bool)
Enables or diables the groupTree items for grouping mode.
void tagsChanged()
Listen to tag changes.
const_iterator constBegin() const
void setIcon(const QIcon &icon)
QStringList symbolsOfGroup(StyleEntity type, int groupid)
returns the symbolnames of a given groupid
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QString groupName(int groupId) const
return the group name for the given DB id
bool saveAsGradientRamp() const
bool addColorRamp(const QString &name, QgsVectorColorRampV2 *colorRamp, bool update=false)
add color ramp to style. takes ramp's ownership
bool detagSymbol(StyleEntity type, const QString &symbol, const QStringList &tags)
detags the symbol with the given list
QString join(const QString &separator) const
void groupSelectedSymbols()
QString smartgroupName()
returns the value from mNameLineEdit
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QStringList colorRampNames()
return a list of names of color ramps
QString tr(const char *sourceText, const char *disambiguation, int n)
Qt::CheckState checkState() const
virtual void setData(const QVariant &value, int role)
void finished(int result)
bool save(QString filename=QString())
save style into a file (will use current filename if empty string is passed)
void setBold(bool enable)
void setValue(const QString &key, const QVariant &value)
const char * name() const
QString variantName() const
QString number(int n, int base)
static QIcon symbolPreviewIcon(QgsSymbolV2 *symbol, QSize size)
QgsSymbolGroupMap childGroupNames(const QString &parent="")
return a map of groupid and names for the given parent group
int count(const T &value) const
bool addSymbol()
add a new symbol to style
void append(const T &value)
bool renameColorRamp(const QString &oldName, const QString &newName)
change ramp's name
int toInt(bool *ok) const
int colorRampCount()
return count of color ramps
QModelIndex indexFromItem(const QStandardItem *item) const
void filterSymbols(const QString &)
filter the symbols based on input search term
StandardButton question(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
void populateSymbols(const QStringList &symbolNames, bool checkable=false)
populate list view with symbols of the current type with the given names
void populateGroups()
populate the groups
void appendRow(const QList< QStandardItem * > &items)
int toInt(bool *ok, int base) const
QStringList mTagList
space to store symbol tags
const QgsSymbolV2 * symbolRef(const QString &name) const
return a const pointer to a symbol (doesn't create new instance)
QStandardItem * parent() const
const_iterator constEnd() const
QMenu * mGroupMenu
Context menu for the symbols/colorramps.
void groupRenamed(QStandardItem *)
void rename(StyleEntity type, int id, const QString &newName)
rename the given entity with the specified id
void populateColorRamps(const QStringList &colorRamps, bool checkable=false)
populate list view with color ramps
QList< QStandardItem * > findItems(const QString &text, QFlags< Qt::MatchFlag > flags, int column) const
void buildGroupTree(QStandardItem *&parent)
build the groups tree
QStringList symbolsOfSmartgroup(StyleEntity type, int id)
returns the symbols for the smartgroup
void exportSelectedItemsImages(const QString &dir, const QString &format, QSize size)
virtual QVariant data(const QModelIndex &index, int role) const =0
void setSymbolsChecked(const QStringList &)
to set symbols checked when in editing mode
QMenu * mGroupTreeContextMenu
Context menu for the group tree.
void populateTypes()
populate combo box with known style items (symbols, color ramps)
QModelIndex parent() const
QgsStyleV2ManagerDialog(QgsStyleV2 *style, QWidget *parent=nullptr)
QStringList symbolNames()
return a list of names of symbols
QgsSymbolGroupMap smartgroupsListMap()
returns the smart groups map with id as key and name as value
QStandardItem * child(int row, int column) const
void setFont(const QFont &font)
QString schemeName() const
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, QFlags< Qt::WindowType > flags, QFlags< Qt::InputMethodHint > inputMethodHints)
void setData(const QVariant &userData)
void setEnabled(bool enabled)
QgsSymbolV2 * symbol(const QString &name)
return a NEW copy of symbol
QStandardItem * item(int row, int column) const
void setParent(QObject *parent)
void exportImage(const QString &path, const QString &format, QSize size)
export symbol as image format. PNG and SVG supported
void on_tabItemType_currentChanged(int)
bool eventFilter(QObject *, QEvent *) override
Event filter to capture tagsLineEdit out of focus.
bool mGrouppingMode
Mode to display the symbol list.
void setBold(QStandardItem *)
sets the text of the item with bold font
QgsVectorGradientColorRampV2 * cloneGradientRamp() const
void setText(const QString &text)
QVariant value(const QString &key, const QVariant &defaultValue) const
void symbolSelected(const QModelIndex &)
Perform symbol specific tasks when selected.
const QAbstractItemModel * model() const
void listitemsContextMenu(QPoint)
Context menu for the listItems ( symbols list )
void groupSymbolsAction()
carryout symbol grouping using check boxes
bool renameSymbol(const QString &oldName, const QString &newName)
change symbol's name
QVariant data(int role) const
void setOperator(const QString &)
sets the operator AND/OR
QStandardItem * itemFromIndex(const QModelIndex &index) const
void grouptreeContextMenu(QPoint)
Context menu for the groupTree.
StandardButton critical(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
virtual int rowCount(const QModelIndex &parent) const
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
QModelIndex index() const
void setSmartgroupName(const QString &)
sets the smart group Name
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
void editSmartgroupAction()
edit the selected smart group
bool removeColorRamp(const QString &name)
remove color ramp from style (and delete it)
static QString addColorRampStatic(QWidget *parent, QgsStyleV2 *style, QString RampType=QString())
open add color ramp dialog, return color ramp's name if the ramp has been added
void setCheckState(Qt::CheckState state)
void enableGroupInputs(bool)
Enables or disables the groupTree specific inputs.
void enableSymbolInputs(bool)
Enables or disbables the symbol specific inputs.
void onFinished()
called when the dialog is going to be closed
QStandardItem * takeChild(int row, int column)
StyleEntity
Enum for Entities involved in a style.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString schemeName() const
bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
void setCheckable(bool checkable)
void setConditionMap(const QgsSmartConditionMap &)
sets up the GUI for the given conditionmap
void appendRow(const QList< QStandardItem * > &items)
virtual QVariant data(int role) const
QStringList findSymbols(StyleEntity type, const QString &qword)
return the names of the symbols which have a matching 'substring' in its defintion ...
void setEditable(bool editable)
void regrouped(QStandardItem *)
symbol changed from one group
int addGroup(const QString &groupName, int parent=0)
adds a new group and returns the group's id
QgsSmartConditionMap smartgroup(int id)
returns the QgsSmartConditionMap for the given id
QString currentItemName()
bool removeSymbol(const QString &name)
remove symbol from style (and delete it)
int addSmartgroup(const QString &name, const QString &op, const QgsSmartConditionMap &conditions)
adds new smartgroup to the database and returns the id
QMenu * mGroupListMenu
Sub-menu of mGroupMenu, dynamically filled to show one entry for every group.
QString conditionOperator()
returns the AND/OR condition
bool addColorRamp()
add a new color ramp to style
void populateList()
adds symbols of some type to list