32 #include <QFileDialog> 33 #include <QInputDialog> 34 #include <QMessageBox> 36 #include <QStandardItemModel> 56 mSplitter->setSizes(
QList<int>() << 170 << 540 );
57 mSplitter->restoreState( settings.
value(
"/Windows/StyleV2Manager/splitter" ).
toByteArray() );
59 tabItemType->setDocumentMode(
true );
60 searchBox->setPlaceholderText(
tr(
"Type here to filter symbols..." ) );
66 connect( btnAddItem, SIGNAL( clicked() ),
this, SLOT(
addItem() ) );
67 connect( actnEditItem, SIGNAL( triggered(
bool ) ),
this, SLOT(
editItem() ) );
68 connect( actnRemoveItem, SIGNAL( triggered(
bool ) ),
this, SLOT(
removeItem() ) );
70 btnRemoveItem->setDefaultAction( actnRemoveItem );
71 btnEditItem->setDefaultAction( actnEditItem );
73 QMenu *shareMenu =
new QMenu(
tr(
"Share menu" ),
this );
86 btnShare->setMenu( shareMenu );
92 listItems->setModel( model );
93 listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
104 groupTree->setModel( groupModel );
105 groupTree->setHeaderHidden(
true );
112 QMenu *groupMenu =
new QMenu(
tr(
"Group actions" ),
this );
114 groupMenu->
addAction( actnGroupSymbols );
116 actnFinishGrouping->setVisible(
false );
117 groupMenu->
addAction( actnFinishGrouping );
118 groupMenu->
addAction( actnEditSmartGroup );
119 btnManageGroups->setMenu( groupMenu );
122 tagsLineEdit->installEventFilter(
this );
125 groupTree->setContextMenuPolicy( Qt::CustomContextMenu );
130 listItems->setContextMenuPolicy( Qt::CustomContextMenu );
136 rampTypes <<
tr(
"Gradient" ) <<
tr(
"Random" ) <<
tr(
"ColorBrewer" );
137 rampTypes <<
tr(
"cpt-city" );
139 Q_FOREACH (
const QString& rampType, rampTypes )
164 connect( actnAddGroup, SIGNAL( triggered(
bool ) ),
this, SLOT(
addGroup() ) );
181 settings.
setValue(
"/Windows/StyleV2Manager/splitter", mSplitter->saveState() );
188 int current = ( tabItemType->count() > 0 ? tabItemType->currentIndex() : 0 );
191 int markerCount = 0, lineCount = 0, fillCount = 0;
194 for (
int i = 0; i < symbolNames.
count(); ++i )
208 Q_ASSERT( 0 &&
"unknown symbol type" );
213 cboItemType->clear();
221 cboItemType->setCurrentIndex( current );
230 actnExportAsPNG->setVisible( flag );
231 actnExportAsSVG->setVisible( flag );
236 listItems->setIconSize(
QSize( 75, 50 ) );
237 listItems->setGridSize(
QSize( 100, 80 ) );
241 listItems->setIconSize(
QSize( 50, 50 ) );
242 listItems->setGridSize(
QSize( 75, 80 ) );
252 Q_ASSERT( 0 &&
"not implemented" );
255 groupChanged( groupTree->selectionModel()->currentIndex() );
265 for (
int i = 0; i < symbolNames.
count(); ++i )
269 if ( symbol && symbol->
type() == type )
292 for (
int i = 0; i < colorRamps.
count(); ++i )
312 switch ( tabItemType->currentIndex() )
337 bool changed =
false;
348 Q_ASSERT( 0 &&
"not implemented" );
367 name =
tr(
"new marker" );
371 name =
tr(
"new line" );
375 name =
tr(
"new fill symbol" );
378 Q_ASSERT( 0 &&
"unknown symbol type" );
388 if ( dlg.
exec() == 0 )
395 bool nameInvalid =
true;
397 while ( nameInvalid )
401 tr(
"Please enter a name for new symbol:" ),
402 QLineEdit::Normal, name, &ok );
412 tr(
"Cannot save symbol without name. Enter a name." ) );
417 tr(
"Symbol with name '%1' already exists. Overwrite?" )
419 QMessageBox::Yes | QMessageBox::No );
420 if ( res == QMessageBox::Yes )
447 rampTypes <<
tr(
"Gradient" ) <<
tr(
"Random" ) <<
tr(
"ColorBrewer" );
448 rampTypes <<
tr(
"cpt-city" );
450 tr(
"Please select color ramp type:" ), rampTypes, 0,
false, &ok );
452 if ( !ok || rampType.
isEmpty() )
458 if ( rampType ==
tr(
"Gradient" ) )
468 name =
tr(
"new gradient ramp" );
470 else if ( rampType ==
tr(
"Random" ) )
480 name =
tr(
"new random ramp" );
482 else if ( rampType ==
tr(
"ColorBrewer" ) )
494 else if ( rampType ==
tr(
"cpt-city" ) )
524 bool nameInvalid =
true;
526 while ( nameInvalid )
530 tr(
"Please enter a name for new color ramp:" ),
531 QLineEdit::Normal, name, &ok );
541 tr(
"Cannot save color ramp without name. Enter a name." ) );
546 tr(
"Color ramp with name '%1' already exists. Overwrite?" )
548 QMessageBox::Yes | QMessageBox::No );
549 if ( res == QMessageBox::Yes )
590 bool changed =
false;
601 Q_ASSERT( 0 &&
"not implemented" );
618 if ( dlg.
exec() == 0 )
638 if ( ramp->
type() ==
"gradient" )
648 else if ( ramp->
type() ==
"random" )
658 else if ( ramp->
type() ==
"colorbrewer" )
668 else if ( ramp->
type() ==
"cpt-city" )
685 Q_ASSERT( 0 &&
"invalid ramp type" );
696 bool changed =
false;
707 Q_ASSERT( 0 &&
"not implemented" );
719 QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
721 QString(
tr(
"Do you really want to remove %n symbol(s)?",
nullptr, indexes.count() ) ),
739 QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
741 QString(
tr(
"Do you really want to remove %n ramps(s)?",
nullptr, indexes.count() ) ),
762 bool changed =
false;
780 tr(
"Name is already taken by another item. Choose a different name." ) );
789 QFileDialog::ShowDirsOnly
790 | QFileDialog::DontResolveSymlinks );
798 QFileDialog::ShowDirsOnly
799 | QFileDialog::DontResolveSymlinks );
809 QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
813 QString path = dir +
'/' + name +
'.' + format;
880 for (
int i = 0; i < rows; i++ )
913 if ( category ==
"all" || category ==
"groups" || category ==
"smartgroups" )
916 if ( category ==
"groups" || category ==
"smartgroups" )
918 btnAddGroup->setEnabled(
true );
919 actnAddGroup->setEnabled(
true );
926 if ( index.
parent().
data( Qt::UserRole + 1 ) ==
"smartgroups" )
928 btnAddGroup->setEnabled(
false );
929 actnAddGroup->setEnabled(
false );
930 btnRemoveGroup->setEnabled(
true );
931 actnRemoveGroup->setEnabled(
true );
932 btnManageGroups->setEnabled(
true );
933 int groupId = index.
data( Qt::UserRole + 1 ).
toInt();
942 int groupId = index.
data( Qt::UserRole + 1 ).
toInt();
946 groupSymbols = symbolNames;
963 actnEditSmartGroup->setVisible(
false );
964 actnAddGroup->setVisible(
false );
965 actnRemoveGroup->setVisible(
false );
966 actnGroupSymbols->setVisible(
false );
967 actnFinishGrouping->setVisible(
false );
981 actnRemoveGroup->setVisible(
true );
983 else if ( index.
data( Qt::UserRole + 1 ) ==
"groups" || index.
data( Qt::UserRole + 1 ) ==
"smartgroups" )
992 QModelIndex parentIndex = groupTree->currentIndex();
995 QString parentData = parentIndex.
data( Qt::UserRole + 1 ).toString();
996 if ( parentData ==
"all" || ( parentIndex.data() ==
"Ungrouped" && parentData ==
"0" ) )
999 tr(
"The parent group you have selected is not user editable.\n" 1000 "Kindly select a user defined group." ) );
1006 if ( parentIndex.parent().data( Qt::UserRole + 1 ).toString() ==
"smartgroups" )
1009 tr(
"Creation of nested smart groups are not allowed\n" 1010 "Select the 'Smart Group' to create a new group." ) );
1019 if ( parentData ==
"smartgroups" )
1024 if ( dlg.
exec() == QDialog::Rejected )
1036 itemName =
QString(
tr(
"New Group" ) );
1037 int parentid = ( parentData ==
"groups" ) ? 0 : parentData.
toInt();
1042 tr(
"New group could not be created.\n" 1043 "There was a problem with your symbol database." ) );
1053 groupTree->setCurrentIndex( childItem->
index() );
1056 groupTree->edit( childItem->
index() );
1066 QString data = index.
data( Qt::UserRole + 1 ).toString();
1067 if ( data ==
"all" || data ==
"groups" || data ==
"smartgroups" || index.
data() ==
"Ungrouped" )
1070 tr(
"Cannot delete system defined categories.\n" 1071 "Kindly select a group or smart group you might want to delete." ) );
1077 if ( parentItem->
data( Qt::UserRole + 1 ).
toString() ==
"smartgroups" )
1088 for (
int i = 0; i < item->
rowCount(); i++ )
1100 int id = item->
data( Qt::UserRole + 1 ).
toInt();
1102 if ( item->
parent()->
data( Qt::UserRole + 1 ) ==
"smartgroups" )
1121 actnGroupSymbols->setVisible(
true );
1122 actnFinishGrouping->setVisible(
false );
1137 listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
1141 bool validGroup =
false;
1152 present = present.
parent();
1159 actnGroupSymbols->setVisible(
false );
1160 actnFinishGrouping->setVisible(
true );
1170 btnManageGroups->setEnabled(
true );
1178 listItems->setSelectionMode( QAbstractItemView::NoSelection );
1190 int groupid = groupTree->currentIndex().data( Qt::UserRole + 1 ).toInt();
1194 regrouped =
mStyle->
group( type, symbolName, groupid );
1200 tr(
"There was a problem with the Symbols database while regrouping." ) );
1210 Q_FOREACH (
const QString& symbol, symbols )
1235 QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
1240 QStringList newtags = tagsLineEdit->text().
split(
',', QString::SkipEmptyParts );
1257 Q_FOREACH (
const QString &tag, oldtags )
1260 removetags.
append( tag );
1270 Q_FOREACH (
const QString &tag, newtags )
1287 tagsLineEdit->clear();
1301 Q_UNUSED( selected );
1302 Q_UNUSED( deselected );
1303 bool nothingSelected = listItems->selectionModel()->selectedIndexes().empty();
1304 actnRemoveItem->setDisabled( nothingSelected );
1306 actnUngroup->setDisabled( nothingSelected );
1307 actnExportAsPNG->setDisabled( nothingSelected );
1308 actnExportAsSVG->setDisabled( nothingSelected );
1309 actnEditItem->setDisabled( nothingSelected );
1314 groupTree->setEnabled( enable );
1315 btnAddGroup->setEnabled( enable );
1316 actnAddGroup->setEnabled( enable );
1317 btnRemoveGroup->setEnabled( enable );
1318 actnRemoveGroup->setEnabled( enable );
1320 searchBox->setEnabled( enable );
1321 tagsLineEdit->setEnabled( enable );
1326 btnAddGroup->setEnabled( enable );
1327 btnRemoveGroup->setEnabled( enable );
1328 actnRemoveGroup->setEnabled( enable );
1335 for (
int i = 0; i < treeModel->
rowCount(); i++ )
1337 if ( treeModel->
item( i )->
data() !=
"groups" )
1341 if ( treeModel->
item( i )->
data() ==
"groups" )
1344 for (
int k = 0; k < treeModel->
item( i )->
rowCount(); k++ )
1350 if ( treeModel->
item( i )->
data() ==
"smartgroups" )
1352 for (
int j = 0; j < treeModel->
item( i )->
rowCount(); j++ )
1361 for (
int i = 0; i < symbolBtnsLayout->count(); i++ )
1363 QWidget *w = qobject_cast<
QWidget*>( symbolBtnsLayout->itemAt( i )->widget() );
1369 actnRemoveItem->setEnabled( enable );
1370 actnEditItem->setEnabled( enable );
1375 QPoint globalPos = groupTree->viewport()->mapToGlobal( point );
1386 QPoint globalPos = listItems->viewport()->mapToGlobal( point );
1393 Q_FOREACH (
int groupId, groupIds )
1416 int groupId = selectedItem->
data().
toInt();
1417 QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1434 if ( present.parent().data( Qt::UserRole + 1 ) !=
"smartgroups" )
1437 tr(
"You have not selected a Smart Group. Kindly select a Smart Group to edit." ) );
1448 if ( dlg.
exec() == QDialog::Rejected )
1456 tr(
"There was some error while editing the smart group." ) );
1468 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
QString schemeName() const
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
Returns a string representing the color ramp type.
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
bool addColorRamp(const QString &name, QgsVectorColorRampV2 *colorRamp, bool update=false)
add color ramp to style. takes ramp's ownership
QgsVectorGradientColorRampV2 * cloneGradientRamp() const
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
const QgsSymbolV2 * symbolRef(const QString &name) const
return a const pointer to a symbol (doesn't create new instance)
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)
QList< int > groupIds() const
return the ids of all the groups in the style
void setBold(bool enable)
void setValue(const QString &key, const QVariant &value)
const char * name() 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
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 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
void setText(const QString &text)
Random color ramp, which returns random colors based on preset parameters.
QString schemeName() const
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
QString groupName(int groupId) const
return the group name for the given DB id
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
bool saveAsGradientRamp() 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)
QString variantName() const
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)
Abstract base class for color ramps.
bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
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