Skip to content

Commit

Permalink
Add a QAbstractItemModel for showing the entities within a QgsStyle o…
Browse files Browse the repository at this point in the history
…bject

- also adds QgsStyleProxyModel which handles filtering of entities
- lots of unit tests
- new signals in QgsStyle for when symbols/tags/etc change (with tests)
  • Loading branch information
nyalldawson committed Sep 12, 2018
1 parent cb0b335 commit c5ab589
Show file tree
Hide file tree
Showing 12 changed files with 2,180 additions and 82 deletions.
94 changes: 89 additions & 5 deletions python/core/auto_generated/symbology/qgsstyle.sip.in
Expand Up @@ -38,7 +38,13 @@ Constructor for QgsStyle.
%End
~QgsStyle();

enum StyleEntity { SymbolEntity, TagEntity, ColorrampEntity, SmartgroupEntity };
enum StyleEntity
{
SymbolEntity,
TagEntity,
ColorrampEntity,
SmartgroupEntity
};

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

bool renameSymbol( const QString &oldName, const QString &newName );
%Docstring
Changessymbol's name
Renames a symbol from ``oldName`` to ``newName``.

Returns true if symbol was successfully renamed.
%End

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

void rename( StyleEntity type, int id, const QString &newName );
bool rename( StyleEntity type, int id, const QString &newName );
%Docstring
Renames the given entity with the specified id

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

void remove( StyleEntity type, int id );
bool remove( StyleEntity type, int id );
%Docstring
Removes the specified entity from the db

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

signals:

void symbolSaved( const QString &name, QgsSymbol *symbol );
%Docstring
Is emitted every time a new symbol has been added to the database
Emitted every time a new symbol has been added to the database.
Emitted whenever a symbol has been added to the style and the database
has been updated as a result.

.. seealso:: :py:func:`symbolRemoved`

.. seealso:: :py:func:`rampAdded`
%End

void groupsModified();
%Docstring
Is emitted every time a tag or smartgroup has been added, removed, or renamed
%End

void entityTagsChanged( QgsStyle::StyleEntity entity, const QString &name, const QStringList &newTags );
%Docstring
Emitted whenever an ``entity``'s tags are changed.

.. versionadded:: 3.4
%End

void favoritedChanged( QgsStyle::StyleEntity entity, const QString &name, bool isFavorite );
%Docstring
Emitted whenever an ``entity`` is either favorited or un-favorited.

.. versionadded:: 3.4
%End

void symbolRemoved( const QString &name );
%Docstring
Emitted whenever a symbol has been removed from the style and the database
has been updated as a result.

.. seealso:: :py:func:`symbolSaved`

.. seealso:: :py:func:`rampRemoved`

.. versionadded:: 3.4
%End

void symbolRenamed( const QString &oldName, const QString &newName );
%Docstring
Emitted whenever a symbol has been renamed from ``oldName`` to ``newName``

.. seealso:: :py:func:`rampRenamed`

.. versionadded:: 3.4
%End

void rampRenamed( const QString &oldName, const QString &newName );
%Docstring
Emitted whenever a color ramp has been renamed from ``oldName`` to ``newName``

.. seealso:: :py:func:`symbolRenamed`

.. versionadded:: 3.4
%End

void rampAdded( const QString &name );
%Docstring
Emitted whenever a color ramp has been added to the style and the database
has been updated as a result.

.. seealso:: :py:func:`rampRemoved`

.. seealso:: :py:func:`symbolSaved`

.. versionadded:: 3.4
%End

void rampRemoved( const QString &name );
%Docstring
Emitted whenever a color ramp has been removed from the style and the database
has been updated as a result.

.. seealso:: :py:func:`rampAdded`

.. seealso:: :py:func:`symbolRemoved`

.. versionadded:: 3.4
%End

};
Expand Down
259 changes: 259 additions & 0 deletions python/core/auto_generated/symbology/qgsstylemodel.sip.in
@@ -0,0 +1,259 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/symbology/qgsstylemodel.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsStyleModel: QAbstractItemModel
{
%Docstring

A QAbstractItemModel subclass for showing symbol and color ramp entities contained
within a QgsStyle database.

.. seealso:: :py:class:`QgsStyleProxyModel`

.. versionadded:: 3.4
%End

%TypeHeaderCode
#include "qgsstylemodel.h"
%End
public:

enum Column
{
Name,
Tags,
};

enum Role
{
TypeRole,
TagRole,
SymbolTypeRole,
};

explicit QgsStyleModel( QgsStyle *style, QObject *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsStyleModel, for the specified ``style`` and ``parent`` object.

The ``style`` object must exist for the lifetime of this model.
%End

virtual QVariant data( const QModelIndex &index, int role ) const;

virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );

virtual Qt::ItemFlags flags( const QModelIndex &index ) const;

virtual QVariant headerData( int section, Qt::Orientation orientation,
int role = Qt::DisplayRole ) const;
virtual QModelIndex index( int row, int column,
const QModelIndex &parent = QModelIndex() ) const;
virtual QModelIndex parent( const QModelIndex &index ) const;

virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;

virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;


};

class QgsStyleProxyModel: QSortFilterProxyModel
{
%Docstring

A QSortFilterProxyModel subclass for showing filtered symbol and color ramps entries from a QgsStyle database.

.. seealso:: :py:class:`QgsStyleModel`

.. versionadded:: 3.4
%End

%TypeHeaderCode
#include "qgsstylemodel.h"
%End
public:

explicit QgsStyleProxyModel( QgsStyle *style, QObject *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsStyleProxyModel, for the specified ``style`` and ``parent`` object.

The ``style`` object must exist for the lifetime of this model.
%End

QString filterString() const;
%Docstring
Returns the current filter string, if set.

.. seealso:: :py:func:`setFilterString`
%End

QgsStyle::StyleEntity entityFilter() const;
%Docstring
Returns the style entity type filter.

.. note::

This filter is only active if entityFilterEnabled() is true.

.. seealso:: :py:func:`setEntityFilter`
%End

void setEntityFilter( QgsStyle::StyleEntity filter );
%Docstring
Sets the style entity type ``filter``.

.. note::

This filter is only active if entityFilterEnabled() is true.

.. seealso:: :py:func:`entityFilter`
%End

bool entityFilterEnabled() const;
%Docstring
Returns true if filtering by entity type is enabled.

.. seealso:: :py:func:`setEntityFilterEnabled`

.. seealso:: :py:func:`entityFilter`
%End

void setEntityFilterEnabled( bool enabled );
%Docstring
Sets whether filtering by entity type is ``enabled``.

If ``enabled`` is false, then the value of entityFilter() will have no
effect on the model filtering.

.. seealso:: :py:func:`entityFilterEnabled`

.. seealso:: :py:func:`setEntityFilter`
%End

QgsSymbol::SymbolType symbolType() const;
%Docstring
Returns the symbol type filter.

.. note::

This filter is only active if symbolTypeFilterEnabled() is true, and has
no effect on non-symbol entities (i.e. color ramps).

.. seealso:: :py:func:`setSymbolType`
%End

void setSymbolType( QgsSymbol::SymbolType type );
%Docstring
Sets the symbol ``type`` filter.

.. note::

This filter is only active if symbolTypeFilterEnabled() is true.

.. seealso:: :py:func:`symbolType`
%End

bool symbolTypeFilterEnabled() const;
%Docstring
Returns true if filtering by symbol type is enabled.

.. seealso:: :py:func:`setSymbolTypeFilterEnabled`

.. seealso:: :py:func:`symbolType`
%End

void setSymbolTypeFilterEnabled( bool enabled );
%Docstring
Sets whether filtering by symbol type is ``enabled``.

If ``enabled`` is false, then the value of symbolType() will have no
effect on the model filtering. This has
no effect on non-symbol entities (i.e. color ramps).

.. seealso:: :py:func:`symbolTypeFilterEnabled`

.. seealso:: :py:func:`setSymbolType`
%End

void setTagId( int id );
%Docstring
Sets a tag ``id`` to filter style entities by. Only entities with the given
tag will be shown in the model.

Set ``id`` to -1 to disable tag filtering.

.. seealso:: :py:func:`tagId`
%End

int tagId() const;
%Docstring
Returns the tag id used to filter style entities by.

If returned value is -1, then no tag filtering is being conducted.

.. seealso:: :py:func:`setTagId`
%End

void setSmartGroupId( int id );
%Docstring
Sets a smart group ``id`` to filter style entities by. Only entities within the given
smart group will be shown in the model.

Set ``id`` to -1 to disable smart group filtering.

.. seealso:: :py:func:`smartGroupId`
%End

int smartGroupId() const;
%Docstring
Returns the smart group id used to filter style entities by.

If returned value is -1, then no smart group filtering is being conducted.

.. seealso:: :py:func:`setSmartGroupId`
%End

virtual bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const;


bool favoritesOnly() const;
%Docstring
Returns true if the model is showing only favorited entities.

.. seealso:: :py:func:`setFavoritesOnly`
%End

void setFavoritesOnly( bool favoritesOnly );
%Docstring
Sets whether the model should show only favorited entities.

.. seealso:: :py:func:`setFavoritesOnly`
%End

public slots:

void setFilterString( const QString &filter );
%Docstring
Sets a ``filter`` string, such that only symbol entities with names matching the
specified string will be shown.

.. seealso:: :py:func:`filterString`
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/symbology/qgsstylemodel.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

0 comments on commit c5ab589

Please sign in to comment.