Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Promote QgsDataItem enums to enum classes, move to Qgis
  • Loading branch information
nyalldawson committed May 27, 2021
1 parent 2b3d299 commit aa93d03
Show file tree
Hide file tree
Showing 83 changed files with 713 additions and 576 deletions.
83 changes: 83 additions & 0 deletions python/core/auto_additions/qgis.py
Expand Up @@ -63,6 +63,89 @@
QgsSymbol.FlagIncludeCrosshairsForMarkerSymbols.__doc__ = "Include a crosshairs reference image in the background of marker symbol previews"
Qgis.SymbolPreviewFlag.__doc__ = 'Flags for controlling how symbol preview images are generated.\n\n.. versionadded:: 3.20\n\n' + '* ``FlagIncludeCrosshairsForMarkerSymbols``: ' + Qgis.SymbolPreviewFlag.FlagIncludeCrosshairsForMarkerSymbols.__doc__
# --
QgsDataItem.Type = Qgis.BrowserItemType
# monkey patching scoped based enum
QgsDataItem.Collection = Qgis.BrowserItemType.Collection
QgsDataItem.Collection.__doc__ = "A collection of items"
QgsDataItem.Directory = Qgis.BrowserItemType.Directory
QgsDataItem.Directory.__doc__ = "Represents a file directory"
QgsDataItem.Layer = Qgis.BrowserItemType.Layer
QgsDataItem.Layer.__doc__ = "Represents a map layer"
QgsDataItem.Error = Qgis.BrowserItemType.Error
QgsDataItem.Error.__doc__ = "Contains an error message"
QgsDataItem.Favorites = Qgis.BrowserItemType.Favorites
QgsDataItem.Favorites.__doc__ = "Represents a favorite item"
QgsDataItem.Project = Qgis.BrowserItemType.Project
QgsDataItem.Project.__doc__ = "Represents a QGIS project"
QgsDataItem.Custom = Qgis.BrowserItemType.Custom
QgsDataItem.Custom.__doc__ = "Custom item type"
QgsDataItem.Fields = Qgis.BrowserItemType.Fields
QgsDataItem.Fields.__doc__ = "Collection of fields"
QgsDataItem.Field = Qgis.BrowserItemType.Field
QgsDataItem.Field.__doc__ = "Vector layer field"
Qgis.BrowserItemType.__doc__ = 'Browser item types.\n\n.. versionadded:: 3.20\n\n' + '* ``Collection``: ' + Qgis.BrowserItemType.Collection.__doc__ + '\n' + '* ``Directory``: ' + Qgis.BrowserItemType.Directory.__doc__ + '\n' + '* ``Layer``: ' + Qgis.BrowserItemType.Layer.__doc__ + '\n' + '* ``Error``: ' + Qgis.BrowserItemType.Error.__doc__ + '\n' + '* ``Favorites``: ' + Qgis.BrowserItemType.Favorites.__doc__ + '\n' + '* ``Project``: ' + Qgis.BrowserItemType.Project.__doc__ + '\n' + '* ``Custom``: ' + Qgis.BrowserItemType.Custom.__doc__ + '\n' + '* ``Fields``: ' + Qgis.BrowserItemType.Fields.__doc__ + '\n' + '* ``Field``: ' + Qgis.BrowserItemType.Field.__doc__
# --
Qgis.BrowserItemType.baseClass = Qgis
QgsDataItem.State = Qgis.BrowserItemState
# monkey patching scoped based enum
QgsDataItem.NotPopulated = Qgis.BrowserItemState.NotPopulated
QgsDataItem.NotPopulated.__doc__ = "Children not yet created"
QgsDataItem.Populating = Qgis.BrowserItemState.Populating
QgsDataItem.Populating.__doc__ = "Creating children in separate thread (populating or refreshing)"
QgsDataItem.Populated = Qgis.BrowserItemState.Populated
QgsDataItem.Populated.__doc__ = "Children created"
Qgis.BrowserItemState.__doc__ = 'Browser item states.\n\n.. versionadded:: 3.20\n\n' + '* ``NotPopulated``: ' + Qgis.BrowserItemState.NotPopulated.__doc__ + '\n' + '* ``Populating``: ' + Qgis.BrowserItemState.Populating.__doc__ + '\n' + '* ``Populated``: ' + Qgis.BrowserItemState.Populated.__doc__
# --
Qgis.BrowserItemState.baseClass = Qgis
QgsDataItem.Capability = Qgis.BrowserItemCapability
# monkey patching scoped based enum
QgsDataItem.NoCapabilities = Qgis.BrowserItemCapability.NoCapabilities
QgsDataItem.NoCapabilities.__doc__ = "Item has no capabilities"
QgsDataItem.SetCrs = Qgis.BrowserItemCapability.SetCrs
QgsDataItem.SetCrs.__doc__ = "Can set CRS on layer or group of layers. \deprecated since QGIS 3.6 -- no longer used by QGIS and will be removed in QGIS 4.0"
QgsDataItem.Fertile = Qgis.BrowserItemCapability.Fertile
QgsDataItem.Fertile.__doc__ = "Can create children. Even items without this capability may have children, but cannot create them, it means that children are created by item ancestors."
QgsDataItem.Fast = Qgis.BrowserItemCapability.Fast
QgsDataItem.Fast.__doc__ = "CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,wfs,wcs,postgres...) are considered fast because they are reading data only from QgsSettings"
QgsDataItem.Collapse = Qgis.BrowserItemCapability.Collapse
QgsDataItem.Collapse.__doc__ = "The collapse/expand status for this items children should be ignored in order to avoid undesired network connections (wms etc.)"
QgsDataItem.Rename = Qgis.BrowserItemCapability.Rename
QgsDataItem.Rename.__doc__ = "Item can be renamed"
QgsDataItem.Delete = Qgis.BrowserItemCapability.Delete
QgsDataItem.Delete.__doc__ = "Item can be deleted"
Qgis.BrowserItemCapability.__doc__ = 'Browser item capabilities.\n\n.. versionadded:: 3.20\n\n' + '* ``NoCapabilities``: ' + Qgis.BrowserItemCapability.NoCapabilities.__doc__ + '\n' + '* ``SetCrs``: ' + Qgis.BrowserItemCapability.SetCrs.__doc__ + '\n' + '* ``Fertile``: ' + Qgis.BrowserItemCapability.Fertile.__doc__ + '\n' + '* ``Fast``: ' + Qgis.BrowserItemCapability.Fast.__doc__ + '\n' + '* ``Collapse``: ' + Qgis.BrowserItemCapability.Collapse.__doc__ + '\n' + '* ``Rename``: ' + Qgis.BrowserItemCapability.Rename.__doc__ + '\n' + '* ``Delete``: ' + Qgis.BrowserItemCapability.Delete.__doc__
# --
QgsLayerItem.LayerType = Qgis.BrowserLayerType
# monkey patching scoped based enum
QgsLayerItem.NoType = Qgis.BrowserLayerType.NoType
QgsLayerItem.NoType.__doc__ = "No type"
QgsLayerItem.Vector = Qgis.BrowserLayerType.Vector
QgsLayerItem.Vector.__doc__ = "Generic vector layer"
QgsLayerItem.Raster = Qgis.BrowserLayerType.Raster
QgsLayerItem.Raster.__doc__ = "Raster layer"
QgsLayerItem.Point = Qgis.BrowserLayerType.Point
QgsLayerItem.Point.__doc__ = "Vector point layer"
QgsLayerItem.Line = Qgis.BrowserLayerType.Line
QgsLayerItem.Line.__doc__ = "Vector line layer"
QgsLayerItem.Polygon = Qgis.BrowserLayerType.Polygon
QgsLayerItem.Polygon.__doc__ = "Vector polygon layer"
QgsLayerItem.TableLayer = Qgis.BrowserLayerType.TableLayer
QgsLayerItem.TableLayer.__doc__ = "Vector non-spatial layer"
QgsLayerItem.Database = Qgis.BrowserLayerType.Database
QgsLayerItem.Database.__doc__ = "Database layer"
QgsLayerItem.Table = Qgis.BrowserLayerType.Table
QgsLayerItem.Table.__doc__ = "Database table"
QgsLayerItem.Plugin = Qgis.BrowserLayerType.Plugin
QgsLayerItem.Plugin.__doc__ = "Plugin based layer"
QgsLayerItem.Mesh = Qgis.BrowserLayerType.Mesh
QgsLayerItem.Mesh.__doc__ = "Mesh layer"
QgsLayerItem.VectorTile = Qgis.BrowserLayerType.VectorTile
QgsLayerItem.VectorTile.__doc__ = "Vector tile layer"
QgsLayerItem.PointCloud = Qgis.BrowserLayerType.PointCloud
QgsLayerItem.PointCloud.__doc__ = "Point cloud layer"
Qgis.BrowserLayerType.__doc__ = 'Browser item layer types\n\n.. versionadded:: 3.20\n\n' + '* ``NoType``: ' + Qgis.BrowserLayerType.NoType.__doc__ + '\n' + '* ``Vector``: ' + Qgis.BrowserLayerType.Vector.__doc__ + '\n' + '* ``Raster``: ' + Qgis.BrowserLayerType.Raster.__doc__ + '\n' + '* ``Point``: ' + Qgis.BrowserLayerType.Point.__doc__ + '\n' + '* ``Line``: ' + Qgis.BrowserLayerType.Line.__doc__ + '\n' + '* ``Polygon``: ' + Qgis.BrowserLayerType.Polygon.__doc__ + '\n' + '* ``TableLayer``: ' + Qgis.BrowserLayerType.TableLayer.__doc__ + '\n' + '* ``Database``: ' + Qgis.BrowserLayerType.Database.__doc__ + '\n' + '* ``Table``: ' + Qgis.BrowserLayerType.Table.__doc__ + '\n' + '* ``Plugin``: ' + Qgis.BrowserLayerType.Plugin.__doc__ + '\n' + '* ``Mesh``: ' + Qgis.BrowserLayerType.Mesh.__doc__ + '\n' + '* ``VectorTile``: ' + Qgis.BrowserLayerType.VectorTile.__doc__ + '\n' + '* ``PointCloud``: ' + Qgis.BrowserLayerType.PointCloud.__doc__
# --
Qgis.BrowserLayerType.baseClass = Qgis
QgsVectorLayerExporter.ExportError = Qgis.VectorExportResult
# monkey patching scoped based enum
QgsVectorLayerExporter.NoError = Qgis.VectorExportResult.Success
Expand Down
3 changes: 0 additions & 3 deletions python/core/auto_additions/qgsdataitem.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/core/auto_additions/qgslayeritem.py

This file was deleted.

9 changes: 6 additions & 3 deletions python/core/auto_generated/browser/qgsbrowsermodel.sip.in
Expand Up @@ -9,7 +9,6 @@




class QgsBrowserModel : QAbstractItemModel
{
%Docstring(signature="appended")
Expand Down Expand Up @@ -165,7 +164,7 @@ and on Linux the "/" root directory.
%End
signals:

void stateChanged( const QModelIndex &index, QgsDataItem::State oldState );
void stateChanged( const QModelIndex &index, Qgis::BrowserItemState oldState );
%Docstring
Emitted when item children fetch was finished
%End
Expand Down Expand Up @@ -196,7 +195,11 @@ drives and adding newly added drives.
void beginRemoveItems( QgsDataItem *parent, int first, int last );
void endRemoveItems();
void itemDataChanged( QgsDataItem *item );
void itemStateChanged( QgsDataItem *item, QgsDataItem::State oldState );

void itemStateChanged( QgsDataItem *item, Qgis::BrowserItemState oldState );
%Docstring
Emitted when an ``item``'s state is changed.
%End

void addFavoriteDirectory( const QString &directory, const QString &name = QString() );
%Docstring
Expand Down
54 changes: 11 additions & 43 deletions python/core/auto_generated/browser/qgsdataitem.sip.in
Expand Up @@ -47,21 +47,8 @@ Parent/children hierarchy is not based on QObject.
sipType = 0;
%End
public:
enum Type
{
Collection,
Directory,
Layer,
Error,
Favorites,
Project,
Custom,
Fields,
Field,
};


QgsDataItem( QgsDataItem::Type type, QgsDataItem *parent /TransferThis/, const QString &name, const QString &path, const QString &providerKey = QString() );
QgsDataItem( Qgis::BrowserItemType type, QgsDataItem *parent /TransferThis/, const QString &name, const QString &path, const QString &providerKey = QString() );
%Docstring
Constructor for QgsDataItem, with the specified ``parent`` item.

Expand Down Expand Up @@ -119,20 +106,13 @@ Create children. Children are not expected to have parent set.
}
%End

enum State
{
NotPopulated,
Populating,
Populated
};

State state() const;
Qgis::BrowserItemState state() const;
%Docstring

.. versionadded:: 2.8
%End

virtual void setState( State state );
virtual void setState( Qgis::BrowserItemState state );
%Docstring
Set item state. It also take care about starting/stopping loading icon animation.

Expand Down Expand Up @@ -276,19 +256,6 @@ Items that return valid URI will be returned in mime data when dragging a select
.. versionadded:: 3.18
%End

enum Capability
{
NoCapabilities,
SetCrs,
Fertile,
Fast,
Collapse,
Rename,
Delete,
};
typedef QFlags<QgsDataItem::Capability> Capabilities;


virtual bool setCrs( const QgsCoordinateReferenceSystem &crs ) /Deprecated/;
%Docstring
Writes the selected crs into data source. The original data source will be modified when calling this
Expand All @@ -315,14 +282,14 @@ Use :py:class:`QgsDataItemGuiProvider`:
%End


virtual Capabilities capabilities2() const;
virtual Qgis::BrowserItemCapabilities capabilities2() const;
%Docstring
Returns the capabilities for the data item.

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

virtual void setCapabilities( Capabilities capabilities );
virtual void setCapabilities( Qgis::BrowserItemCapabilities capabilities );
%Docstring
Sets the capabilities for the data item.

Expand All @@ -333,7 +300,7 @@ Sets the capabilities for the data item.
static int findItem( QVector<QgsDataItem *> items, QgsDataItem *item );


Type type() const;
Qgis::BrowserItemType type() const;

QgsDataItem *parent() const;
%Docstring
Expand Down Expand Up @@ -496,7 +463,11 @@ all providers will be refreshed (which is potentially very expensive!).
void beginRemoveItems( QgsDataItem *parent, int first, int last );
void endRemoveItems();
void dataChanged( QgsDataItem *item );
void stateChanged( QgsDataItem *item, QgsDataItem::State oldState );

void stateChanged( QgsDataItem *item, Qgis::BrowserItemState oldState );
%Docstring
Emitted when an item's state is changed.
%End

void connectionsChanged( const QString &providerKey = QString() );
%Docstring
Expand All @@ -518,9 +489,6 @@ Will request a repaint of this icon.

};

QFlags<QgsDataItem::Capability> operator|(QgsDataItem::Capability f1, QFlags<QgsDataItem::Capability> f2);


class QgsErrorItem : QgsDataItem
{
%Docstring(signature="appended")
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/browser/qgsdirectoryitem.sip.in
Expand Up @@ -52,7 +52,7 @@ items pointing to different ``dirPaths`` should always use a different item ``pa
The optional ``providerKey`` string can be used to specify the key for the :py:class:`QgsDataItemProvider` that created this item.
%End

virtual void setState( State state );
virtual void setState( Qgis::BrowserItemState state );


virtual QVector<QgsDataItem *> createChildren();
Expand Down
30 changes: 8 additions & 22 deletions python/core/auto_generated/browser/qgslayeritem.sip.in
Expand Up @@ -18,25 +18,11 @@ Item that represents a layer that can be opened with one of the providers
#include "qgslayeritem.h"
%End
public:
enum LayerType
{
NoType,
Vector,
Raster,
Point,
Line,
Polygon,
TableLayer,
Database,
Table,
Plugin,
Mesh,
VectorTile,
PointCloud
};


QgsLayerItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &uri, LayerType layerType, const QString &providerKey );

QgsLayerItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &uri, Qgis::BrowserLayerType layerType, const QString &providerKey );
%Docstring
Constructor for QgsLayerItem.
%End


virtual bool equal( const QgsDataItem *other );
Expand All @@ -53,7 +39,7 @@ Item that represents a layer that can be opened with one of the providers
Returns :py:class:`QgsMapLayerType`
%End

static LayerType typeFromMapLayer( QgsMapLayer *layer );
static Qgis::BrowserLayerType typeFromMapLayer( QgsMapLayer *layer );
%Docstring
Returns the layer item type corresponding to a :py:class:`QgsMapLayer` ``layer``.

Expand Down Expand Up @@ -91,14 +77,14 @@ Returns comments of the layer
.. versionadded:: 2.12
%End

static QString layerTypeAsString( LayerType layerType );
static QString layerTypeAsString( Qgis::BrowserLayerType layerType );
%Docstring
Returns the string representation of the given ``layerType``

.. versionadded:: 3
%End

static QString iconName( LayerType layerType );
static QString iconName( Qgis::BrowserLayerType layerType );
%Docstring
Returns the icon name of the given ``layerType``

Expand Down
52 changes: 52 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -152,6 +152,56 @@ The development version
typedef QFlags<Qgis::SymbolPreviewFlag> SymbolPreviewFlags;


enum class BrowserItemType
{
Collection,
Directory,
Layer,
Error,
Favorites,
Project,
Custom,
Fields,
Field,
};

enum class BrowserItemState
{
NotPopulated,
Populating,
Populated,
};

enum class BrowserItemCapability
{
NoCapabilities,
SetCrs,
Fertile,
Fast,
Collapse,
Rename,
Delete,
};
typedef QFlags<Qgis::BrowserItemCapability> BrowserItemCapabilities;


enum class BrowserLayerType
{
NoType,
Vector,
Raster,
Point,
Line,
Polygon,
TableLayer,
Database,
Table,
Plugin,
Mesh,
VectorTile,
PointCloud
};

enum class VectorExportResult
{
Success,
Expand Down Expand Up @@ -256,6 +306,8 @@ QFlags<Qgis::SymbolFlag> operator|(Qgis::SymbolFlag f1, QFlags<Qgis::SymbolFlag>

QFlags<Qgis::SymbolPreviewFlag> operator|(Qgis::SymbolPreviewFlag f1, QFlags<Qgis::SymbolPreviewFlag> f2);

QFlags<Qgis::BrowserItemCapability> operator|(Qgis::BrowserItemCapability f1, QFlags<Qgis::BrowserItemCapability> f2);




Expand Down

0 comments on commit aa93d03

Please sign in to comment.