32 #include <QFileDialog>
33 #include <QInputDialog>
34 #include <QMessageBox>
36 #include <QStandardItemModel>
45 :
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() ) );
68 QMenu *shareMenu =
new QMenu(
tr(
"Share Menu" ),
this );
75 btnShare->setMenu( shareMenu );
81 listItems->setModel( model );
82 listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
91 groupTree->setModel( groupModel );
92 groupTree->setHeaderHidden(
true );
99 QMenu *groupMenu =
new QMenu(
tr(
"Group Actions" ),
this );
102 btnManageGroups->setMenu( groupMenu );
112 tagsLineEdit->installEventFilter(
this );
115 groupTree->setContextMenuPolicy( Qt::CustomContextMenu );
120 listItems->setContextMenuPolicy( Qt::CustomContextMenu );
135 settings.
setValue(
"/Windows/StyleV2Manager/splitter", mSplitter->saveState() );
142 int current = ( tabItemType->count() > 0 ? tabItemType->currentIndex() : 0 );
145 int markerCount = 0, lineCount = 0, fillCount = 0;
148 for (
int i = 0; i < symbolNames.
count(); ++i )
161 default: Q_ASSERT( 0 &&
"unknown symbol type" );
166 cboItemType->clear();
174 cboItemType->setCurrentIndex( current );
184 rampTypes <<
tr(
"Gradient" ) <<
tr(
"Random" ) <<
tr(
"ColorBrewer" );
185 rampTypes <<
tr(
"cpt-city" );
187 foreach (
QString rampType, rampTypes )
191 btnAddItem->setMenu( menu );
197 if ( btnAddItem->menu() )
201 btnAddItem->setMenu( 0 );
208 listItems->setIconSize(
QSize( 75, 50 ) );
209 listItems->setGridSize(
QSize( 100, 80 ) );
213 listItems->setIconSize(
QSize( 50, 50 ) );
214 listItems->setGridSize(
QSize( 75, 80 ) );
224 Q_ASSERT( 0 &&
"not implemented" );
227 groupChanged( groupTree->selectionModel()->currentIndex() );
237 for (
int i = 0; i < symbolNames.
count(); ++i )
241 if ( symbol && symbol->
type() == type )
262 for (
int i = 0; i < colorRamps.
count(); ++i )
280 switch ( tabItemType->currentIndex() )
300 bool changed =
false;
311 Q_ASSERT( 0 &&
"not implemented" );
330 name =
tr(
"new marker" );
334 name =
tr(
"new line" );
338 name =
tr(
"new fill symbol" );
341 Q_ASSERT( 0 &&
"unknown symbol type" );
351 if ( dlg.
exec() == 0 )
358 bool nameInvalid =
true;
360 while ( nameInvalid )
364 tr(
"Please enter a name for new symbol:" ),
365 QLineEdit::Normal, name, &ok );
375 tr(
"Cannot save symbol without name. Enter a name." ) );
380 tr(
"Symbol with name '%1' already exists. Overwrite?" )
382 QMessageBox::Yes | QMessageBox::No );
383 if ( res == QMessageBox::Yes )
410 rampTypes <<
tr(
"Gradient" ) <<
tr(
"Random" ) <<
tr(
"ColorBrewer" );
411 rampTypes <<
tr(
"cpt-city" );
413 tr(
"Please select color ramp type:" ), rampTypes, 0,
false, &ok );
415 if ( !ok || rampType.
isEmpty() )
421 if ( rampType ==
tr(
"Gradient" ) )
431 name =
tr(
"new gradient ramp" );
433 else if ( rampType ==
tr(
"Random" ) )
443 name =
tr(
"new random ramp" );
445 else if ( rampType ==
tr(
"ColorBrewer" ) )
457 else if ( rampType ==
tr(
"cpt-city" ) )
487 bool nameInvalid =
true;
489 while ( nameInvalid )
493 tr(
"Please enter a name for new color ramp:" ),
494 QLineEdit::Normal, name, &ok );
504 tr(
"Cannot save color ramp without name. Enter a name." ) );
509 tr(
"Color ramp with name '%1' already exists. Overwrite?" )
511 QMessageBox::Yes | QMessageBox::No );
512 if ( res == QMessageBox::Yes )
553 bool changed =
false;
564 Q_ASSERT( 0 &&
"not implemented" );
581 if ( dlg.
exec() == 0 )
601 if ( ramp->
type() ==
"gradient" )
611 else if ( ramp->
type() ==
"random" )
621 else if ( ramp->
type() ==
"colorbrewer" )
631 else if ( ramp->
type() ==
"cpt-city" )
648 Q_ASSERT( 0 &&
"invalid ramp type" );
659 bool changed =
false;
670 Q_ASSERT( 0 &&
"not implemented" );
682 QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
710 bool changed =
false;
728 tr(
"Name is already taken by another item. Choose a different name." ) );
794 for (
int i = 0; i < rows; i++ )
827 if ( category ==
"all" || category ==
"groups" || category ==
"smartgroups" )
830 if ( category ==
"groups" || category ==
"smartgroups" )
832 btnAddGroup->setEnabled(
true );
839 if ( index.
parent().
data( Qt::UserRole + 1 ) ==
"smartgroups" )
841 btnAddGroup->setEnabled(
false );
842 btnRemoveGroup->setEnabled(
true );
843 btnManageGroups->setEnabled(
true );
844 int groupId = index.
data( Qt::UserRole + 1 ).
toInt();
853 int groupId = index.
data( Qt::UserRole + 1 ).
toInt();
857 groupSymbols = symbolNames;
878 QModelIndex parentIndex = groupTree->currentIndex();
881 QString parentData = parentIndex.
data( Qt::UserRole + 1 ).toString();
882 if ( parentData ==
"all" || ( parentIndex.data() ==
"Ungrouped" && parentData ==
"0" ) )
885 tr(
"The parent group you have selected is not user editable.\n"
886 "Kindly select a user defined group." ) );
892 if ( parentIndex.parent().data( Qt::UserRole + 1 ).toString() ==
"smartgroups" )
895 tr(
"Creation of nested smart groups are not allowed\n"
896 "Select the 'Smart Group' to create a new group." ) );
906 if ( parentIndex.data( Qt::UserRole + 1 ).toString() ==
"smartgroups" )
909 if ( dlg.
exec() == QDialog::Rejected )
927 childItem->
setData( itemData );
930 groupTree->setCurrentIndex( childItem->
index() );
933 groupTree->edit( childItem->
index() );
943 QString data = index.
data( Qt::UserRole + 1 ).toString();
944 if ( data ==
"all" || data ==
"groups" || data ==
"smartgroups" || index.
data() ==
"Ungrouped" )
947 tr(
"Cannot delete system defined categories.\n"
948 "Kindly select a group or smart group you might want to delete." ) );
954 if ( parentItem->
data( Qt::UserRole + 1 ).
toString() ==
"smartgroups" )
965 for (
int i = 0; i < item->
rowCount(); i++ )
977 QgsDebugMsg(
"Symbol group edited: data=" + data +
" text=" + item->
text() );
978 if ( data ==
"newgroup" )
993 tr(
"New group could not be created.\n"
994 "There was a problem with your symbol database." ) );
1005 int id = item->
data( Qt::UserRole + 1 ).
toInt();
1007 if ( item->
parent()->
data( Qt::UserRole + 1 ) ==
"smartgroups" )
1028 senderAction->setText(
tr(
"Group Symbols" ) );
1043 listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
1047 bool validGroup =
false;
1058 present = present.
parent();
1065 senderAction->setText(
tr(
"Finish Grouping" ) );
1075 btnManageGroups->setEnabled(
true );
1083 listItems->setSelectionMode( QAbstractItemView::NoSelection );
1095 int groupid = groupTree->currentIndex().data( Qt::UserRole + 1 ).toInt();
1099 regrouped =
mStyle->
group( type, symbolName, groupid );
1105 tr(
"There was a problem with the Symbols database while regrouping." ) );
1115 foreach (
const QString symbol, symbols )
1140 QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
1145 QStringList newtags = tagsLineEdit->text().
split(
",", QString::SkipEmptyParts );
1162 foreach (
const QString &tag, oldtags )
1165 removetags.
append( tag );
1167 if ( removetags.
size() > 0 )
1175 foreach (
const QString &tag, newtags )
1180 if ( addtags.
size() > 0 )
1192 tagsLineEdit->clear();
1201 groupTree->setEnabled( enable );
1202 btnAddGroup->setEnabled( enable );
1203 btnRemoveGroup->setEnabled( enable );
1204 btnManageGroups->setEnabled( enable );
1205 searchBox->setEnabled( enable );
1206 tagsLineEdit->setEnabled( enable );
1211 btnAddGroup->setEnabled( enable );
1212 btnRemoveGroup->setEnabled( enable );
1213 btnManageGroups->setEnabled( enable );
1219 for (
int i = 0; i < treeModel->
rowCount(); i++ )
1221 if ( treeModel->
item( i )->
data() !=
"groups" )
1225 if ( treeModel->
item( i )->
data() ==
"groups" )
1228 for (
int k = 0; k < treeModel->
item( i )->
rowCount(); k++ )
1234 if ( treeModel->
item( i )->
data() ==
"smartgroups" )
1236 for (
int j = 0; j < treeModel->
item( i )->
rowCount(); j++ )
1245 for (
int i = 0; i < symbolBtnsLayout->count(); i++ )
1247 QWidget *w = qobject_cast<
QWidget*>( symbolBtnsLayout->itemAt( i )->widget() );
1256 QPoint globalPos = groupTree->viewport()->mapToGlobal( point );
1271 groupMenu.addAction(
tr(
"Add Group" ) );
1273 groupMenu.addAction(
tr(
"Remove Group" ) );
1275 else if ( index.
data( Qt::UserRole + 1 ) ==
"groups" || index.
data( Qt::UserRole + 1 ) ==
"smartgroups" )
1277 groupMenu.addAction(
tr(
"Add Group" ) );
1281 QAction* selectedItem = groupMenu.exec( globalPos );
1285 if ( selectedItem->
text() ==
tr(
"Add Group" ) )
1287 else if ( selectedItem->
text() ==
tr(
"Remove Group" ) )
1289 else if ( selectedItem->
text() ==
tr(
"Edit Group" ) )
1296 QPoint globalPos = listItems->viewport()->mapToGlobal( point );
1303 foreach (
QString group, groups )
1307 groupMenu->
addMenu( groupList );
1310 QAction* selectedItem = groupMenu->
exec( globalPos );
1321 if ( selectedItem->
text() !=
tr(
"Un-group" ) )
1325 QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1342 if ( present.parent().data( Qt::UserRole + 1 ) !=
"smartgroups" )
1345 tr(
"You have not selected a Smart Group. Kindly select a Smart Group to edit." ) );
1356 if ( dlg.
exec() == QDialog::Rejected )
1364 tr(
"There was some error while editing the smart group." ) );
1376 if (( obj == tagsLineEdit ) && ( event->
type() == QEvent::FocusOut ) )
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
QStringList tagsOfSymbol(StyleEntity type, QString symbol)
return the tags associated with the symbol
void setIcon(const QIcon &icon)
int addSmartgroup(QString name, QString op, QgsSmartConditionMap conditions)
adds new smartgroup to the database and returns the id
static QIcon colorRampPreviewIcon(QgsVectorColorRampV2 *ramp, QSize size)
virtual QString type() const =0
void filterSymbols(QString)
filter the symbols based on input search term
QStandardItem * invisibleRootItem() const
QgsSmartConditionMap conditionMap()
returns the condition map
void itemChanged(QStandardItem *item)
void groupChanged(const QModelIndex &)
bool group(StyleEntity type, QString name, int groupid)
applies the specified group to the symbol or colorramp specified by StyleEntity
static QString iconPath(QString iconFile)
Returns path to the desired icon file.
void enableItemsForGroupingMode(bool)
Enables or diables the groupTree items for grouping mode.
void setSymbolsChecked(QStringList)
to set symbols checked when in editing 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
bool contains(const QString &str, Qt::CaseSensitivity cs) const
void populateSymbols(QStringList symbolNames, bool checkable=false)
populate list view with symbols of the current type with the given names
QgsStyleV2ManagerDialog(QgsStyleV2 *style, QWidget *parent=NULL)
bool saveAsGradientRamp() const
QgsSymbolV2 * symbol(QString name)
return a NEW copy of symbol
void rename(StyleEntity type, int id, QString newName)
rename the given entity with the specified id
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)
bool renameSymbol(QString oldName, QString newName)
change symbol's name
Qt::CheckState checkState() const
virtual void setData(const QVariant &value, int role)
QgsSymbolGroupMap childGroupNames(QString parent="")
return a map of groupid and names for the given parent group
bool addSymbol(QString name, QgsSymbolV2 *symbol, bool update=false)
add symbol to style. takes symbol's ownership
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)
int count(const T &value) const
bool addSymbol()
add a new symbol to style
void append(const T &value)
const QgsSymbolV2 * symbolRef(QString name) const
return a const pointer to a symbol (doesn't create new instance)
int toInt(bool *ok) const
int colorRampCount()
return count of color ramps
QModelIndex indexFromItem(const QStandardItem *item) const
void populateGroups()
populate the groups
void appendRow(const QList< QStandardItem * > &items)
QStringList mTagList
space to store symbol tags
QStandardItem * parent() const
const_iterator constEnd() const
bool renameColorRamp(QString oldName, QString newName)
change ramp's name
void groupRenamed(QStandardItem *)
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 setOperator(QString)
sets the operator AND/OR
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)
QStandardItem * item(int row, int column) const
void setSmartgroupName(QString)
sets the smart group Name
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 groupSymbolsAction()
carryout symbol grouping using check boxes
QVariant data(int role) const
bool detagSymbol(StyleEntity type, QString symbol, QStringList tags)
detags the symbol with the given list
QStandardItem * itemFromIndex(const QModelIndex &index) const
bool removeSymbol(QString name)
remove symbol from style (and delete it)
bool addColorRamp(QString name, QgsVectorColorRampV2 *colorRamp, bool update=false)
add color ramp to style. takes ramp's ownership
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
bool tagSymbol(StyleEntity type, QString symbol, QStringList tags)
tags the symbol with the tags in the list
bool removeColorRamp(QString name)
remove color ramp from style (and delete it)
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
void editSmartgroupAction()
edit the selected smart group
void populateColorRamps(QStringList colorRamps, bool checkable=false)
populate list view with color ramps
int addGroup(QString groupName, int parent=0)
adds a new group and returns the group's id
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.
QgsVectorColorRampV2 * colorRamp(QString name)
return a NEW copy of color ramp
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
QStringList findSymbols(StyleEntity type, QString qword)
return the names of the symbols which have a matching 'substring' in its defintion ...
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
void setEditable(bool editable)
void regrouped(QStandardItem *)
symbol changed from one group
QStringList groupNames()
return the all the groups in the style
QgsSmartConditionMap smartgroup(int id)
returns the QgsSmartConditionMap for the given id
QString currentItemName()
QString conditionOperator()
returns the AND/OR condition
bool addColorRamp()
add a new color ramp to style
int groupId(QString group)
return the DB id for the given group name
void populateList()
adds symbols of some type to list