Skip to content

Commit c5ab589

Browse files
committedSep 12, 2018
Add a QAbstractItemModel for showing the entities within a QgsStyle object
- also adds QgsStyleProxyModel which handles filtering of entities - lots of unit tests - new signals in QgsStyle for when symbols/tags/etc change (with tests)
1 parent cb0b335 commit c5ab589

File tree

12 files changed

+2180
-82
lines changed

12 files changed

+2180
-82
lines changed
 

‎python/core/auto_generated/symbology/qgsstyle.sip.in

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ Constructor for QgsStyle.
3838
%End
3939
~QgsStyle();
4040

41-
enum StyleEntity { SymbolEntity, TagEntity, ColorrampEntity, SmartgroupEntity };
41+
enum StyleEntity
42+
{
43+
SymbolEntity,
44+
TagEntity,
45+
ColorrampEntity,
46+
SmartgroupEntity
47+
};
4248

4349
bool addSymbol( const QString &name, QgsSymbol *symbol /Transfer/, bool update = false );
4450
%Docstring
@@ -180,7 +186,9 @@ Removes symbol from style (and delete it)
180186

181187
bool renameSymbol( const QString &oldName, const QString &newName );
182188
%Docstring
183-
Changessymbol's name
189+
Renames a symbol from ``oldName`` to ``newName``.
190+
191+
Returns true if symbol was successfully renamed.
184192
%End
185193

186194
QgsSymbol *symbol( const QString &name ) /Factory/;
@@ -256,7 +264,7 @@ Removes the specified symbol from favorites
256264
:return: returns the success state as bool
257265
%End
258266

259-
void rename( StyleEntity type, int id, const QString &newName );
267+
bool rename( StyleEntity type, int id, const QString &newName );
260268
%Docstring
261269
Renames the given entity with the specified id
262270

@@ -265,7 +273,7 @@ Renames the given entity with the specified id
265273
:param newName: is the new name of the entity
266274
%End
267275

268-
void remove( StyleEntity type, int id );
276+
bool remove( StyleEntity type, int id );
269277
%Docstring
270278
Removes the specified entity from the db
271279

@@ -447,13 +455,89 @@ Imports the symbols and colorramps into the default style database from the give
447455
%End
448456

449457
signals:
458+
450459
void symbolSaved( const QString &name, QgsSymbol *symbol );
451460
%Docstring
452-
Is emitted every time a new symbol has been added to the database
461+
Emitted every time a new symbol has been added to the database.
462+
Emitted whenever a symbol has been added to the style and the database
463+
has been updated as a result.
464+
465+
.. seealso:: :py:func:`symbolRemoved`
466+
467+
.. seealso:: :py:func:`rampAdded`
453468
%End
469+
454470
void groupsModified();
455471
%Docstring
456472
Is emitted every time a tag or smartgroup has been added, removed, or renamed
473+
%End
474+
475+
void entityTagsChanged( QgsStyle::StyleEntity entity, const QString &name, const QStringList &newTags );
476+
%Docstring
477+
Emitted whenever an ``entity``'s tags are changed.
478+
479+
.. versionadded:: 3.4
480+
%End
481+
482+
void favoritedChanged( QgsStyle::StyleEntity entity, const QString &name, bool isFavorite );
483+
%Docstring
484+
Emitted whenever an ``entity`` is either favorited or un-favorited.
485+
486+
.. versionadded:: 3.4
487+
%End
488+
489+
void symbolRemoved( const QString &name );
490+
%Docstring
491+
Emitted whenever a symbol has been removed from the style and the database
492+
has been updated as a result.
493+
494+
.. seealso:: :py:func:`symbolSaved`
495+
496+
.. seealso:: :py:func:`rampRemoved`
497+
498+
.. versionadded:: 3.4
499+
%End
500+
501+
void symbolRenamed( const QString &oldName, const QString &newName );
502+
%Docstring
503+
Emitted whenever a symbol has been renamed from ``oldName`` to ``newName``
504+
505+
.. seealso:: :py:func:`rampRenamed`
506+
507+
.. versionadded:: 3.4
508+
%End
509+
510+
void rampRenamed( const QString &oldName, const QString &newName );
511+
%Docstring
512+
Emitted whenever a color ramp has been renamed from ``oldName`` to ``newName``
513+
514+
.. seealso:: :py:func:`symbolRenamed`
515+
516+
.. versionadded:: 3.4
517+
%End
518+
519+
void rampAdded( const QString &name );
520+
%Docstring
521+
Emitted whenever a color ramp has been added to the style and the database
522+
has been updated as a result.
523+
524+
.. seealso:: :py:func:`rampRemoved`
525+
526+
.. seealso:: :py:func:`symbolSaved`
527+
528+
.. versionadded:: 3.4
529+
%End
530+
531+
void rampRemoved( const QString &name );
532+
%Docstring
533+
Emitted whenever a color ramp has been removed from the style and the database
534+
has been updated as a result.
535+
536+
.. seealso:: :py:func:`rampAdded`
537+
538+
.. seealso:: :py:func:`symbolRemoved`
539+
540+
.. versionadded:: 3.4
457541
%End
458542

459543
};
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/symbology/qgsstylemodel.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsStyleModel: QAbstractItemModel
13+
{
14+
%Docstring
15+
16+
A QAbstractItemModel subclass for showing symbol and color ramp entities contained
17+
within a QgsStyle database.
18+
19+
.. seealso:: :py:class:`QgsStyleProxyModel`
20+
21+
.. versionadded:: 3.4
22+
%End
23+
24+
%TypeHeaderCode
25+
#include "qgsstylemodel.h"
26+
%End
27+
public:
28+
29+
enum Column
30+
{
31+
Name,
32+
Tags,
33+
};
34+
35+
enum Role
36+
{
37+
TypeRole,
38+
TagRole,
39+
SymbolTypeRole,
40+
};
41+
42+
explicit QgsStyleModel( QgsStyle *style, QObject *parent /TransferThis/ = 0 );
43+
%Docstring
44+
Constructor for QgsStyleModel, for the specified ``style`` and ``parent`` object.
45+
46+
The ``style`` object must exist for the lifetime of this model.
47+
%End
48+
49+
virtual QVariant data( const QModelIndex &index, int role ) const;
50+
51+
virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );
52+
53+
virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
54+
55+
virtual QVariant headerData( int section, Qt::Orientation orientation,
56+
int role = Qt::DisplayRole ) const;
57+
virtual QModelIndex index( int row, int column,
58+
const QModelIndex &parent = QModelIndex() ) const;
59+
virtual QModelIndex parent( const QModelIndex &index ) const;
60+
61+
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
62+
63+
virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
64+
65+
66+
};
67+
68+
class QgsStyleProxyModel: QSortFilterProxyModel
69+
{
70+
%Docstring
71+
72+
A QSortFilterProxyModel subclass for showing filtered symbol and color ramps entries from a QgsStyle database.
73+
74+
.. seealso:: :py:class:`QgsStyleModel`
75+
76+
.. versionadded:: 3.4
77+
%End
78+
79+
%TypeHeaderCode
80+
#include "qgsstylemodel.h"
81+
%End
82+
public:
83+
84+
explicit QgsStyleProxyModel( QgsStyle *style, QObject *parent /TransferThis/ = 0 );
85+
%Docstring
86+
Constructor for QgsStyleProxyModel, for the specified ``style`` and ``parent`` object.
87+
88+
The ``style`` object must exist for the lifetime of this model.
89+
%End
90+
91+
QString filterString() const;
92+
%Docstring
93+
Returns the current filter string, if set.
94+
95+
.. seealso:: :py:func:`setFilterString`
96+
%End
97+
98+
QgsStyle::StyleEntity entityFilter() const;
99+
%Docstring
100+
Returns the style entity type filter.
101+
102+
.. note::
103+
104+
This filter is only active if entityFilterEnabled() is true.
105+
106+
.. seealso:: :py:func:`setEntityFilter`
107+
%End
108+
109+
void setEntityFilter( QgsStyle::StyleEntity filter );
110+
%Docstring
111+
Sets the style entity type ``filter``.
112+
113+
.. note::
114+
115+
This filter is only active if entityFilterEnabled() is true.
116+
117+
.. seealso:: :py:func:`entityFilter`
118+
%End
119+
120+
bool entityFilterEnabled() const;
121+
%Docstring
122+
Returns true if filtering by entity type is enabled.
123+
124+
.. seealso:: :py:func:`setEntityFilterEnabled`
125+
126+
.. seealso:: :py:func:`entityFilter`
127+
%End
128+
129+
void setEntityFilterEnabled( bool enabled );
130+
%Docstring
131+
Sets whether filtering by entity type is ``enabled``.
132+
133+
If ``enabled`` is false, then the value of entityFilter() will have no
134+
effect on the model filtering.
135+
136+
.. seealso:: :py:func:`entityFilterEnabled`
137+
138+
.. seealso:: :py:func:`setEntityFilter`
139+
%End
140+
141+
QgsSymbol::SymbolType symbolType() const;
142+
%Docstring
143+
Returns the symbol type filter.
144+
145+
.. note::
146+
147+
This filter is only active if symbolTypeFilterEnabled() is true, and has
148+
no effect on non-symbol entities (i.e. color ramps).
149+
150+
.. seealso:: :py:func:`setSymbolType`
151+
%End
152+
153+
void setSymbolType( QgsSymbol::SymbolType type );
154+
%Docstring
155+
Sets the symbol ``type`` filter.
156+
157+
.. note::
158+
159+
This filter is only active if symbolTypeFilterEnabled() is true.
160+
161+
.. seealso:: :py:func:`symbolType`
162+
%End
163+
164+
bool symbolTypeFilterEnabled() const;
165+
%Docstring
166+
Returns true if filtering by symbol type is enabled.
167+
168+
.. seealso:: :py:func:`setSymbolTypeFilterEnabled`
169+
170+
.. seealso:: :py:func:`symbolType`
171+
%End
172+
173+
void setSymbolTypeFilterEnabled( bool enabled );
174+
%Docstring
175+
Sets whether filtering by symbol type is ``enabled``.
176+
177+
If ``enabled`` is false, then the value of symbolType() will have no
178+
effect on the model filtering. This has
179+
no effect on non-symbol entities (i.e. color ramps).
180+
181+
.. seealso:: :py:func:`symbolTypeFilterEnabled`
182+
183+
.. seealso:: :py:func:`setSymbolType`
184+
%End
185+
186+
void setTagId( int id );
187+
%Docstring
188+
Sets a tag ``id`` to filter style entities by. Only entities with the given
189+
tag will be shown in the model.
190+
191+
Set ``id`` to -1 to disable tag filtering.
192+
193+
.. seealso:: :py:func:`tagId`
194+
%End
195+
196+
int tagId() const;
197+
%Docstring
198+
Returns the tag id used to filter style entities by.
199+
200+
If returned value is -1, then no tag filtering is being conducted.
201+
202+
.. seealso:: :py:func:`setTagId`
203+
%End
204+
205+
void setSmartGroupId( int id );
206+
%Docstring
207+
Sets a smart group ``id`` to filter style entities by. Only entities within the given
208+
smart group will be shown in the model.
209+
210+
Set ``id`` to -1 to disable smart group filtering.
211+
212+
.. seealso:: :py:func:`smartGroupId`
213+
%End
214+
215+
int smartGroupId() const;
216+
%Docstring
217+
Returns the smart group id used to filter style entities by.
218+
219+
If returned value is -1, then no smart group filtering is being conducted.
220+
221+
.. seealso:: :py:func:`setSmartGroupId`
222+
%End
223+
224+
virtual bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const;
225+
226+
227+
bool favoritesOnly() const;
228+
%Docstring
229+
Returns true if the model is showing only favorited entities.
230+
231+
.. seealso:: :py:func:`setFavoritesOnly`
232+
%End
233+
234+
void setFavoritesOnly( bool favoritesOnly );
235+
%Docstring
236+
Sets whether the model should show only favorited entities.
237+
238+
.. seealso:: :py:func:`setFavoritesOnly`
239+
%End
240+
241+
public slots:
242+
243+
void setFilterString( const QString &filter );
244+
%Docstring
245+
Sets a ``filter`` string, such that only symbol entities with names matching the
246+
specified string will be shown.
247+
248+
.. seealso:: :py:func:`filterString`
249+
%End
250+
251+
};
252+
253+
/************************************************************************
254+
* This file has been generated automatically from *
255+
* *
256+
* src/core/symbology/qgsstylemodel.h *
257+
* *
258+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
259+
************************************************************************/

0 commit comments

Comments
 (0)