32 #include <QFileDialog>
33 #include <QInputDialog>
34 #include <QMessageBox>
36 #include <QStandardItemModel>
44 :
QDialog( parent ), mStyle( style ), mModified( false )
53 mSplitter->setSizes(
QList<int>() << 170 << 540 );
54 mSplitter->restoreState( settings.
value(
"/Windows/StyleV2Manager/splitter" ).
toByteArray() );
56 tabItemType->setDocumentMode(
true );
57 searchBox->setPlaceholderText(
tr(
"Type here to filter symbols..." ) );
63 connect( btnAddItem, SIGNAL( clicked() ),
this, SLOT(
addItem() ) );
67 QMenu *shareMenu =
new QMenu(
tr(
"Share Menu" ),
this );
80 btnShare->setMenu( shareMenu );
86 listItems->setModel( model );
87 listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
96 groupTree->setModel( groupModel );
97 groupTree->setHeaderHidden(
true );
104 QMenu *groupMenu =
new QMenu(
tr(
"Group Actions" ),
this );
107 btnManageGroups->setMenu( groupMenu );
117 tagsLineEdit->installEventFilter(
this );
120 groupTree->setContextMenuPolicy( Qt::CustomContextMenu );
125 listItems->setContextMenuPolicy( Qt::CustomContextMenu );
140 settings.
setValue(
"/Windows/StyleV2Manager/splitter", mSplitter->saveState() );
147 int current = ( tabItemType->count() > 0 ? tabItemType->currentIndex() : 0 );
150 int markerCount = 0, lineCount = 0, fillCount = 0;
153 for (
int i = 0; i < symbolNames.
count(); ++i )
166 default: Q_ASSERT( 0 &&
"unknown symbol type" );
171 cboItemType->clear();
179 cboItemType->setCurrentIndex( current );
188 btnShare->menu()->actions().at( 0 )->setVisible(
false );
189 btnShare->menu()->actions().at( 1 )->setVisible(
false );
192 rampTypes <<
tr(
"Gradient" ) <<
tr(
"Random" ) <<
tr(
"ColorBrewer" );
193 rampTypes <<
tr(
"cpt-city" );
195 Q_FOREACH (
const QString& rampType, rampTypes )
199 btnAddItem->setMenu( menu );
205 btnShare->menu()->actions().at( 0 )->setVisible(
true );
206 btnShare->menu()->actions().at( 1 )->setVisible(
true );
208 if ( btnAddItem->menu() )
212 btnAddItem->setMenu( 0 );
219 listItems->setIconSize(
QSize( 75, 50 ) );
220 listItems->setGridSize(
QSize( 100, 80 ) );
224 listItems->setIconSize(
QSize( 50, 50 ) );
225 listItems->setGridSize(
QSize( 75, 80 ) );
235 Q_ASSERT( 0 &&
"not implemented" );
238 groupChanged( groupTree->selectionModel()->currentIndex() );
248 for (
int i = 0; i < symbolNames.
count(); ++i )
252 if ( symbol && symbol->
type() == type )
273 for (
int i = 0; i < colorRamps.
count(); ++i )
291 switch ( tabItemType->currentIndex() )
311 bool changed =
false;
322 Q_ASSERT( 0 &&
"not implemented" );
341 name =
tr(
"new marker" );
345 name =
tr(
"new line" );
349 name =
tr(
"new fill symbol" );
352 Q_ASSERT( 0 &&
"unknown symbol type" );
362 if ( dlg.
exec() == 0 )
369 bool nameInvalid =
true;
371 while ( nameInvalid )
375 tr(
"Please enter a name for new symbol:" ),
376 QLineEdit::Normal, name, &ok );
386 tr(
"Cannot save symbol without name. Enter a name." ) );
391 tr(
"Symbol with name '%1' already exists. Overwrite?" )
393 QMessageBox::Yes | QMessageBox::No );
394 if ( res == QMessageBox::Yes )
421 rampTypes <<
tr(
"Gradient" ) <<
tr(
"Random" ) <<
tr(
"ColorBrewer" );
422 rampTypes <<
tr(
"cpt-city" );
424 tr(
"Please select color ramp type:" ), rampTypes, 0,
false, &ok );
426 if ( !ok || rampType.
isEmpty() )
432 if ( rampType ==
tr(
"Gradient" ) )
442 name =
tr(
"new gradient ramp" );
444 else if ( rampType ==
tr(
"Random" ) )
454 name =
tr(
"new random ramp" );
456 else if ( rampType ==
tr(
"ColorBrewer" ) )
468 else if ( rampType ==
tr(
"cpt-city" ) )
498 bool nameInvalid =
true;
500 while ( nameInvalid )
504 tr(
"Please enter a name for new color ramp:" ),
505 QLineEdit::Normal, name, &ok );
515 tr(
"Cannot save color ramp without name. Enter a name." ) );
520 tr(
"Color ramp with name '%1' already exists. Overwrite?" )
522 QMessageBox::Yes | QMessageBox::No );
523 if ( res == QMessageBox::Yes )
564 bool changed =
false;
575 Q_ASSERT( 0 &&
"not implemented" );
592 if ( dlg.
exec() == 0 )
612 if ( ramp->
type() ==
"gradient" )
622 else if ( ramp->
type() ==
"random" )
632 else if ( ramp->
type() ==
"colorbrewer" )
642 else if ( ramp->
type() ==
"cpt-city" )
659 Q_ASSERT( 0 &&
"invalid ramp type" );
670 bool changed =
false;
681 Q_ASSERT( 0 &&
"not implemented" );
693 QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
721 bool changed =
false;
739 tr(
"Name is already taken by another item. Choose a different name." ) );
748 QFileDialog::ShowDirsOnly
749 | QFileDialog::DontResolveSymlinks );
757 QFileDialog::ShowDirsOnly
758 | QFileDialog::DontResolveSymlinks );
768 QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
772 QString path = dir +
"/" + name +
"." + format;
839 for (
int i = 0; i < rows; i++ )
872 if ( category ==
"all" || category ==
"groups" || category ==
"smartgroups" )
875 if ( category ==
"groups" || category ==
"smartgroups" )
877 btnAddGroup->setEnabled(
true );
884 if ( index.
parent().
data( Qt::UserRole + 1 ) ==
"smartgroups" )
886 btnAddGroup->setEnabled(
false );
887 btnRemoveGroup->setEnabled(
true );
888 btnManageGroups->setEnabled(
true );
889 int groupId = index.
data( Qt::UserRole + 1 ).
toInt();
898 int groupId = index.
data( Qt::UserRole + 1 ).
toInt();
902 groupSymbols = symbolNames;
923 QModelIndex parentIndex = groupTree->currentIndex();
926 QString parentData = parentIndex.
data( Qt::UserRole + 1 ).toString();
927 if ( parentData ==
"all" || ( parentIndex.data() ==
"Ungrouped" && parentData ==
"0" ) )
930 tr(
"The parent group you have selected is not user editable.\n"
931 "Kindly select a user defined group." ) );
937 if ( parentIndex.parent().data( Qt::UserRole + 1 ).toString() ==
"smartgroups" )
940 tr(
"Creation of nested smart groups are not allowed\n"
941 "Select the 'Smart Group' to create a new group." ) );
951 if ( parentIndex.data( Qt::UserRole + 1 ).toString() ==
"smartgroups" )
954 if ( dlg.
exec() == QDialog::Rejected )
972 childItem->
setData( itemData );
975 groupTree->setCurrentIndex( childItem->
index() );
978 groupTree->edit( childItem->
index() );
988 QString data = index.
data( Qt::UserRole + 1 ).toString();
989 if ( data ==
"all" || data ==
"groups" || data ==
"smartgroups" || index.
data() ==
"Ungrouped" )
992 tr(
"Cannot delete system defined categories.\n"
993 "Kindly select a group or smart group you might want to delete." ) );
999 if ( parentItem->
data( Qt::UserRole + 1 ).
toString() ==
"smartgroups" )
1010 for (
int i = 0; i < item->
rowCount(); i++ )
1022 QgsDebugMsg(
"Symbol group edited: data=" + data +
" text=" + item->
text() );
1023 if ( data ==
"newgroup" )
1038 tr(
"New group could not be created.\n"
1039 "There was a problem with your symbol database." ) );
1050 int id = item->
data( Qt::UserRole + 1 ).
toInt();
1052 if ( item->
parent()->
data( Qt::UserRole + 1 ) ==
"smartgroups" )
1073 senderAction->setText(
tr(
"Group Symbols" ) );
1088 listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
1092 bool validGroup =
false;
1103 present = present.
parent();
1110 senderAction->setText(
tr(
"Finish Grouping" ) );
1120 btnManageGroups->setEnabled(
true );
1128 listItems->setSelectionMode( QAbstractItemView::NoSelection );
1140 int groupid = groupTree->currentIndex().data( Qt::UserRole + 1 ).toInt();
1144 regrouped =
mStyle->
group( type, symbolName, groupid );
1150 tr(
"There was a problem with the Symbols database while regrouping." ) );
1160 Q_FOREACH (
const QString& symbol, symbols )
1185 QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
1190 QStringList newtags = tagsLineEdit->text().
split(
",", QString::SkipEmptyParts );
1207 Q_FOREACH (
const QString &tag, oldtags )
1210 removetags.
append( tag );
1212 if ( removetags.
size() > 0 )
1220 Q_FOREACH (
const QString &tag, newtags )
1225 if ( addtags.
size() > 0 )
1237 tagsLineEdit->clear();
1246 groupTree->setEnabled( enable );
1247 btnAddGroup->setEnabled( enable );
1248 btnRemoveGroup->setEnabled( enable );
1249 btnManageGroups->setEnabled( enable );
1250 searchBox->setEnabled( enable );
1251 tagsLineEdit->setEnabled( enable );
1256 btnAddGroup->setEnabled( enable );
1257 btnRemoveGroup->setEnabled( enable );
1258 btnManageGroups->setEnabled( enable );
1264 for (
int i = 0; i < treeModel->
rowCount(); i++ )
1266 if ( treeModel->
item( i )->
data() !=
"groups" )
1270 if ( treeModel->
item( i )->
data() ==
"groups" )
1273 for (
int k = 0; k < treeModel->
item( i )->
rowCount(); k++ )
1279 if ( treeModel->
item( i )->
data() ==
"smartgroups" )
1281 for (
int j = 0; j < treeModel->
item( i )->
rowCount(); j++ )
1290 for (
int i = 0; i < symbolBtnsLayout->count(); i++ )
1292 QWidget *w = qobject_cast<
QWidget*>( symbolBtnsLayout->itemAt( i )->widget() );
1301 QPoint globalPos = groupTree->viewport()->mapToGlobal( point );
1316 groupMenu.addAction(
tr(
"Add Group" ) );
1318 groupMenu.addAction(
tr(
"Remove Group" ) );
1320 else if ( index.
data( Qt::UserRole + 1 ) ==
"groups" || index.
data( Qt::UserRole + 1 ) ==
"smartgroups" )
1322 groupMenu.addAction(
tr(
"Add Group" ) );
1326 QAction* selectedItem = groupMenu.exec( globalPos );
1330 if ( selectedItem->
text() ==
tr(
"Add Group" ) )
1332 else if ( selectedItem->
text() ==
tr(
"Remove Group" ) )
1334 else if ( selectedItem->
text() ==
tr(
"Edit Group" ) )
1341 QPoint globalPos = listItems->viewport()->mapToGlobal( point );
1348 Q_FOREACH (
const QString& group, groups )
1352 groupMenu->
addMenu( groupList );
1355 QAction* selectedItem = groupMenu->
exec( globalPos );
1366 if ( selectedItem->
text() !=
tr(
"Un-group" ) )
1370 QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1387 if ( present.parent().data( Qt::UserRole + 1 ) !=
"smartgroups" )
1390 tr(
"You have not selected a Smart Group. Kindly select a Smart Group to edit." ) );
1401 if ( dlg.
exec() == QDialog::Rejected )
1409 tr(
"There was some error while editing the smart group." ) );
1421 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
QByteArray toByteArray() const
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)
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
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 &)
int groupId(const QString &group)
return the DB id for the given group name
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
QgsStyleV2ManagerDialog(QgsStyleV2 *style, QWidget *parent=NULL)
void exportImage(const QString &path, const QString &format, const QSize &size)
export symbol as image format. PNG and SVG supported
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
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
void setConditionMap(QgsSmartConditionMap)
sets up the GUI for the given conditionmap
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
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)
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
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
virtual QVariant data(const QModelIndex &index, int role) const =0
void grouptreeContextMenu(const QPoint &)
Context menu for the groupTree.
void setSymbolsChecked(const QStringList &)
to set symbols checked when in editing mode
void populateTypes()
populate combo box with known style items (symbols, color ramps)
QModelIndex parent() const
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 setEnabled(bool enabled)
QgsSymbolV2 * symbol(const QString &name)
return a NEW copy of symbol
QStandardItem * item(int row, int column) const
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)
void exportSelectedItemsImages(const QString &dir, const QString &format, const QSize &size)
QVariant value(const QString &key, const QVariant &defaultValue) const
void symbolSelected(const QModelIndex &)
Perform symbol specific tasks when selected.
const QAbstractItemModel * model() const
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 listitemsContextMenu(const QPoint &)
Context menu for the listItems ( symbols list )
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 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
QStringList groupNames()
return the all the groups in the style
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
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