Skip to content
Permalink
Browse files

better API doc, own category for 3D, fix leak

  • Loading branch information
3nids authored and nyalldawson committed Sep 14, 2018
1 parent e91a42d commit 0df5b9e5930c1441884b689a8b96ac0ba9afca4b
@@ -79,7 +79,8 @@ This is the base class for all map layer types (vector, raster).
{
LayerConfiguration,
Symbology,
Labels,
Symbology3D,
Labeling,
Fields,
Forms,
Actions,
@@ -97,10 +98,25 @@ This is the base class for all map layer types (vector, raster).
{
public:
ReadableStyleCategory( const QString &name, const QString &toolTip = QString() );
%Docstring
Create a ReadableStyleCategory
%End
ReadableStyleCategory( const QString &name, const QIcon &icon, const QString &toolTip = QString() );
%Docstring
Create a ReadableStyleCategory
%End
QString name() const;
%Docstring
Return the translated name of the category
%End
QString toolTip() const;
%Docstring
Return the translated tooltip of the category
%End
QIcon icon() const;
%Docstring
Return the icon of the category
%End
};

QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, const QString &name = QString(), const QString &source = QString() );
@@ -531,17 +547,17 @@ Returns true if the layer is considered a spatial layer, ie it has some form of

bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context );
%Docstring
Sets state from Dom document
Sets state from DOM document

:param layerElement: The Dom element corresponding to ``maplayer'' tag
:param layerElement: The DOM element corresponding to ``maplayer'' tag
:param context: writing context (e.g. for conversion between relative and absolute paths)
\note

The Dom node corresponds to a Dom document project file XML element read
The DOM node corresponds to a DOM document project file XML element read
by :py:class:`QgsProject`.

This, in turn, calls readXml() (and then readSymbology()), which is over-rideable
by sub-classes so that they can read their own specific state from the given Dom node.
This, in turn, calls readXml() (and then readSymbology()), which is overridable
by sub-classes so that they can read their own specific state from the given DOM node.

Invoked by :py:func:`QgsProject.read()`

@@ -550,18 +566,18 @@ Invoked by :py:func:`QgsProject.read()`

bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
%Docstring
Stores state in Dom node
Stores state in DOM node

:param layerElement: is a Dom element corresponding to ``maplayer'' tag
:param document: is a the dom document being written
:param layerElement: is a DOM element corresponding to ``maplayer'' tag
:param document: is a the DOM document being written
:param context: reading context (e.g. for conversion between relative and absolute paths)
\note

The Dom node corresponds to a Dom document project file XML element to be
The DOM node corresponds to a DOM document project file XML element to be
written by :py:class:`QgsProject`.

This, in turn, calls writeXml() (and then writeSymbology), which is over-rideable
by sub-classes so that they can write their own specific state to the given Dom node.
by sub-classes so that they can write their own specific state to the given DOM node.

Invoked by :py:func:`QgsProject.write()`

@@ -909,7 +925,7 @@ Attempts to style the layer using the formatting from an SLD type file.
virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
QgsReadWriteContext &context, StyleCategories categories = AllCategories ) = 0;
%Docstring
Read the symbology for the current layer from the Dom node supplied.
Read the symbology for the current layer from the DOM node supplied.

:param node: node that will contain the symbology definition for this layer.
:param errorMessage: reference to string that will be updated with any error messages
@@ -921,7 +937,7 @@ Read the symbology for the current layer from the Dom node supplied.
virtual bool readStyle( const QDomNode &node, QString &errorMessage,
QgsReadWriteContext &context, StyleCategories categories = AllCategories );
%Docstring
Read the style for the current layer from the Dom node supplied.
Read the style for the current layer from the DOM node supplied.

:param node: node that will contain the style definition for this layer.
:param errorMessage: reference to string that will be updated with any error messages
@@ -1486,7 +1502,7 @@ passwords or drivers prefixes ("HDF5:")
:param source: data source to encode, typically :py:func:`QgsMapLayer.source()`
:param context: writing context (e.g. for conversion between relative and absolute paths)

:return: encoded source, typically to be written in the dom element "datasource"
:return: encoded source, typically to be written in the DOM element "datasource"

.. versionadded:: 3.2
%End
@@ -1497,8 +1513,8 @@ Called by readLayerXML(), used by derived classes to decode provider's specific
source from project files. Typically resolving absolute or relative paths, usernames and
passwords or drivers prefixes ("HDF5:")

:param source: data source to decode, typically read from layer's dom element "datasource"
:param dataProvider: string identification of data provider (e.g. "ogr"), typically read from layer's dom element
:param source: data source to decode, typically read from layer's DOM element "datasource"
:param dataProvider: string identification of data provider (e.g. "ogr"), typically read from layer's DOM element
:param context: reading context (e.g. for conversion between relative and absolute paths)

:return: decoded source, typically to be used as the layer's datasource
@@ -325,7 +325,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
for ( QgsMapLayer::StyleCategory category : categories )
{
QgsMapLayer::ReadableStyleCategory readableCategory = QgsMapLayer::readableStyleCategory( category );
QAction *copyAction = new QAction( readableCategory.icon(), readableCategory.name() );
QAction *copyAction = new QAction( readableCategory.icon(), readableCategory.name(), copyStyleMenu );
copyAction->setToolTip( readableCategory.toolTip() );
connect( copyAction, &QAction::triggered, this, [ = ]() {app->copyStyle( layer, category );} );
copyStyleMenu->addAction( copyAction );
@@ -74,11 +74,14 @@ QgsMapLayer::ReadableStyleCategory QgsMapLayer::readableStyleCategory( QgsMapLay
case LayerConfiguration:
return ReadableStyleCategory( tr( "Layer Configuration" ),
QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/system.svg" ) ),
tr( "Flags, display expression, read-only" ) );
tr( "Identifiable, removable, searchable, display expression, read-only" ) );
case Symbology :
return ReadableStyleCategory( tr( "Symbology" ),
QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/symbology.svg" ) ) );
case Labels :
case Symbology3D:
return ReadableStyleCategory( tr( "3D Symbology" ),
QgsApplication::getThemeIcon( QStringLiteral( "/3d.svg" ) ) );
case Labeling :
return ReadableStyleCategory( tr( "Labels" ),
QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/labels.svg" ) ) );
case Fields :
@@ -98,8 +101,9 @@ QgsMapLayer::ReadableStyleCategory QgsMapLayer::readableStyleCategory( QgsMapLay
return ReadableStyleCategory( tr( "Diagrams" ),
QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/diagram.svg" ) ) );
case AttributeTable :
return ReadableStyleCategory( tr( "Attribute Table" ),
QgsApplication::getThemeIcon( QStringLiteral( "/mActionOpenTable.svg" ) ) );
return ReadableStyleCategory( tr( "Attribute Table Settings" ),
QgsApplication::getThemeIcon( QStringLiteral( "/mActionOpenTable.svg" ) ),
tr( "Choice and order of columns, conditional styling" ) );
case Rendering :
return ReadableStyleCategory( tr( "Rendering" ),
QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/rendering.svg" ) ),
@@ -108,7 +112,7 @@ QgsMapLayer::ReadableStyleCategory QgsMapLayer::readableStyleCategory( QgsMapLay
return ReadableStyleCategory( tr( "Custom Properties" ),
QgsApplication::getThemeIcon( QStringLiteral( "/mActionOptions.svg" ) ) );
case AllCategories :
return ReadableStyleCategory( tr( "All categories" ) );
return ReadableStyleCategory( tr( "All Categories" ) );
}
}

@@ -604,7 +608,7 @@ void QgsMapLayer::writeCommonStyle( QDomElement &layerElement, QDomDocument &doc
layerElement.setAttribute( QStringLiteral( "minScale" ), QString::number( minimumScale() ) );
}

if ( categories.testFlag( Symbology ) )
if ( categories.testFlag( Symbology3D ) )
{
if ( m3DRenderer )
{
@@ -1613,7 +1617,7 @@ bool QgsMapLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorM
void QgsMapLayer::readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
QgsMapLayer::StyleCategories categories )
{
if ( categories.testFlag( Symbology ) )
if ( categories.testFlag( Symbology3D ) )
{
QgsAbstract3DRenderer *r3D = nullptr;
QDomElement renderer3DElem = layerElement.firstChildElement( QStringLiteral( "renderer-3d" ) );
@@ -141,39 +141,46 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
enum StyleCategory
{
LayerConfiguration = 1 << 0, //!< Flags, display expression, read-only
Symbology = 1 << 1,
Labels = 1 << 2,
Fields = 1 << 3, //!< Aliases, widgets, WMS/WFS, expressions, constraints, virtual fields
Forms = 1 << 4,
Actions = 1 << 5,
MapTips = 1 << 6,
Diagrams = 1 << 7,
AttributeTable = 1 << 8,
Rendering = 1 << 9, //!< Scale visibility, simplify method, opacity
CustomProperties = 1 << 10,
AllCategories = LayerConfiguration | Symbology | Labels | Fields | Forms | Actions |
LayerConfiguration = 1 << 0, //!< General configuration: identifiable, removable, searchable, display expression, read-only
Symbology = 1 << 1, //!< Symbology
Symbology3D = 1 << 2, //!< 3D symbology
Labeling = 1 << 3, //!< Labeling
Fields = 1 << 4, //!< Aliases, widgets, WMS/WFS, expressions, constraints, virtual fields
Forms = 1 << 5, //!< Feature form
Actions = 1 << 6, //!< Actions
MapTips = 1 << 7, //!< Map tips
Diagrams = 1 << 8, //!< Diagrams
AttributeTable = 1 << 9, //!< Attribute table settings: choice and order of columns, conditional styling
Rendering = 1 << 10, //!< Rendering: scale visibility, simplify method, opacity
CustomProperties = 1 << 11, //!< Custom properties (by plugins for instance)
AllCategories = LayerConfiguration | Symbology | Labeling | Fields | Forms | Actions |
MapTips | Diagrams | AttributeTable | Rendering | CustomProperties,
};
Q_ENUM( StyleCategory )
Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
Q_FLAG( StyleCategories )

/**
* Style category with its name and its tooltip translated and readable
* Style category with its name, tooltip and icon.
* Text are translated and readable
* \since QGIS 3.4
*/
struct ReadableStyleCategory
{
public:
//! Create a ReadableStyleCategory
ReadableStyleCategory( const QString &name, const QString &toolTip = QString() )
: mName( name ), mToolTip( toolTip )
{}
//! Create a ReadableStyleCategory
ReadableStyleCategory( const QString &name, const QIcon &icon, const QString &toolTip = QString() )
: mName( name ), mToolTip( toolTip ), mIcon( icon )
{}
//! Return the translated name of the category
QString name() const {return mName;}
//! Return the translated tooltip of the category
QString toolTip() const {return mToolTip;}
//! Return the icon of the category
QIcon icon() const {return mIcon;}
private:
QString mName;
@@ -544,16 +551,16 @@ class CORE_EXPORT QgsMapLayer : public QObject
virtual bool isSpatial() const;

/**
* Sets state from Dom document
* \param layerElement The Dom element corresponding to ``maplayer'' tag
* Sets state from DOM document
* \param layerElement The DOM element corresponding to ``maplayer'' tag
* \param context writing context (e.g. for conversion between relative and absolute paths)
* \note
*
* The Dom node corresponds to a Dom document project file XML element read
* The DOM node corresponds to a DOM document project file XML element read
* by QgsProject.
*
* This, in turn, calls readXml() (and then readSymbology()), which is over-rideable
* by sub-classes so that they can read their own specific state from the given Dom node.
* This, in turn, calls readXml() (and then readSymbology()), which is overridable
* by sub-classes so that they can read their own specific state from the given DOM node.
*
* Invoked by QgsProject::read().
*
@@ -562,17 +569,17 @@ class CORE_EXPORT QgsMapLayer : public QObject
bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context );

/**
* Stores state in Dom node
* \param layerElement is a Dom element corresponding to ``maplayer'' tag
* \param document is a the dom document being written
* Stores state in DOM node
* \param layerElement is a DOM element corresponding to ``maplayer'' tag
* \param document is a the DOM document being written
* \param context reading context (e.g. for conversion between relative and absolute paths)
* \note
*
* The Dom node corresponds to a Dom document project file XML element to be
* The DOM node corresponds to a DOM document project file XML element to be
* written by QgsProject.
*
* This, in turn, calls writeXml() (and then writeSymbology), which is over-rideable
* by sub-classes so that they can write their own specific state to the given Dom node.
* by sub-classes so that they can write their own specific state to the given DOM node.
*
* Invoked by QgsProject::write().
*
@@ -860,7 +867,7 @@ class CORE_EXPORT QgsMapLayer : public QObject


/**
* Read the symbology for the current layer from the Dom node supplied.
* Read the symbology for the current layer from the DOM node supplied.
* \param node node that will contain the symbology definition for this layer.
* \param errorMessage reference to string that will be updated with any error messages
* \param context reading context (used for transform from relative to absolute paths)
@@ -870,7 +877,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
QgsReadWriteContext &context, StyleCategories categories = AllCategories ) = 0;

/**
* Read the style for the current layer from the Dom node supplied.
* Read the style for the current layer from the DOM node supplied.
* \param node node that will contain the style definition for this layer.
* \param errorMessage reference to string that will be updated with any error messages
* \param context reading context (used for transform from relative to absolute paths)
@@ -1312,7 +1319,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
*
* \param source data source to encode, typically QgsMapLayer::source()
* \param context writing context (e.g. for conversion between relative and absolute paths)
* \return encoded source, typically to be written in the dom element "datasource"
* \return encoded source, typically to be written in the DOM element "datasource"
*
* \since QGIS 3.2
*/
@@ -1323,8 +1330,8 @@ class CORE_EXPORT QgsMapLayer : public QObject
* source from project files. Typically resolving absolute or relative paths, usernames and
* passwords or drivers prefixes ("HDF5:")
*
* \param source data source to decode, typically read from layer's dom element "datasource"
* \param dataProvider string identification of data provider (e.g. "ogr"), typically read from layer's dom element
* \param source data source to decode, typically read from layer's DOM element "datasource"
* \param dataProvider string identification of data provider (e.g. "ogr"), typically read from layer's DOM element
* \param context reading context (e.g. for conversion between relative and absolute paths)
* \return decoded source, typically to be used as the layer's datasource
*
@@ -2124,7 +2124,7 @@ bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage,
}

// read labeling definition
if ( categories.testFlag( Labels ) )
if ( categories.testFlag( Labeling ) )
{
QDomElement labelingElement = node.firstChildElement( QStringLiteral( "labeling" ) );
QgsAbstractVectorLayerLabeling *labeling = nullptr;
@@ -2465,7 +2465,7 @@ bool QgsVectorLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &err
}
}

if ( categories.testFlag( Labels ) )
if ( categories.testFlag( Labeling ) )
{
if ( mLabeling )
{

0 comments on commit 0df5b9e

Please sign in to comment.
You can’t perform that action at this time.