LCOV - code coverage report
Current view: top level - core/vectortile - qgsvectortilebasicrenderer.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 14 0.0 %
Date: 2021-03-26 12:19:53 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :   qgsvectortilebasicrenderer.h
       3                 :            :   --------------------------------------
       4                 :            :   Date                 : March 2020
       5                 :            :   Copyright            : (C) 2020 by Martin Dobias
       6                 :            :   Email                : wonder dot sk at gmail dot com
       7                 :            :  ***************************************************************************
       8                 :            :  *                                                                         *
       9                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      10                 :            :  *   it under the terms of the GNU General Public License as published by  *
      11                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      12                 :            :  *   (at your option) any later version.                                   *
      13                 :            :  *                                                                         *
      14                 :            :  ***************************************************************************/
      15                 :            : 
      16                 :            : #ifndef QGSVECTORTILEBASICRENDERER_H
      17                 :            : #define QGSVECTORTILEBASICRENDERER_H
      18                 :            : 
      19                 :            : #include "qgis_core.h"
      20                 :            : #include "qgis_sip.h"
      21                 :            : 
      22                 :            : #include "qgsvectortilerenderer.h"
      23                 :            : 
      24                 :            : class QgsLineSymbol;
      25                 :            : class QgsFillSymbol;
      26                 :            : class QgsMarkerSymbol;
      27                 :            : 
      28                 :            : class QgsSymbol;
      29                 :            : 
      30                 :            : /**
      31                 :            :  * \ingroup core
      32                 :            :  * \brief Definition of map rendering of a subset of vector tile data. The subset of data is defined by:
      33                 :            :  *
      34                 :            :  * - sub-layer name
      35                 :            :  * - geometry type (a single sub-layer may have multiple geometry types)
      36                 :            :  * - filter expression
      37                 :            :  *
      38                 :            :  * Rendering is determined by the associated symbol (QgsSymbol). Symbol has to be of the same
      39                 :            :  * type as the chosen geometryType() - i.e. QgsMarkerSymbol for points, QgsLineSymbol for linestrings
      40                 :            :  * and QgsFillSymbol for polygons.
      41                 :            :  *
      42                 :            :  * It is possible to further constrain when this style is applied by setting a range of allowed
      43                 :            :  * zoom levels, or by disabling it.
      44                 :            :  *
      45                 :            :  * \since QGIS 3.14
      46                 :            :  */
      47                 :            : class CORE_EXPORT QgsVectorTileBasicRendererStyle
      48                 :            : {
      49                 :            :   public:
      50                 :            :     //! Constructs a style object
      51                 :            :     QgsVectorTileBasicRendererStyle( const QString &stName = QString(), const QString &laName = QString(), QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry );
      52                 :            :     //! Constructs a style object as a copy of another style
      53                 :            :     QgsVectorTileBasicRendererStyle( const QgsVectorTileBasicRendererStyle &other );
      54                 :            :     QgsVectorTileBasicRendererStyle &operator=( const QgsVectorTileBasicRendererStyle &other );
      55                 :            :     ~QgsVectorTileBasicRendererStyle();
      56                 :            : 
      57                 :            :     //! Sets human readable name of this style
      58                 :          0 :     void setStyleName( const QString &name ) { mStyleName = name; }
      59                 :            :     //! Returns human readable name of this style
      60                 :            :     QString styleName() const { return mStyleName; }
      61                 :            : 
      62                 :            :     //! Sets name of the sub-layer to render (empty layer means that all layers match)
      63                 :          0 :     void setLayerName( const QString &name ) { mLayerName = name; }
      64                 :            :     //! Returns name of the sub-layer to render (empty layer means that all layers match)
      65                 :          0 :     QString layerName() const { return mLayerName; }
      66                 :            : 
      67                 :            :     //! Sets type of the geometry that will be used (point / line / polygon)
      68                 :          0 :     void setGeometryType( QgsWkbTypes::GeometryType geomType ) { mGeometryType = geomType; }
      69                 :            :     //! Returns type of the geometry that will be used (point / line / polygon)
      70                 :          0 :     QgsWkbTypes::GeometryType geometryType() const { return mGeometryType; }
      71                 :            : 
      72                 :            :     //! Sets filter expression (empty filter means that all features match)
      73                 :          0 :     void setFilterExpression( const QString &expr ) { mExpression = expr; }
      74                 :            :     //! Returns filter expression (empty filter means that all features match)
      75                 :          0 :     QString filterExpression() const { return mExpression; }
      76                 :            : 
      77                 :            :     //! Sets symbol for rendering. Takes ownership of the symbol.
      78                 :            :     void setSymbol( QgsSymbol *sym SIP_TRANSFER );
      79                 :            :     //! Returns symbol for rendering
      80                 :          0 :     QgsSymbol *symbol() const { return mSymbol.get(); }
      81                 :            : 
      82                 :            :     //! Sets whether this style is enabled (used for rendering)
      83                 :          0 :     void setEnabled( bool enabled ) { mEnabled = enabled; }
      84                 :            :     //! Returns whether this style is enabled (used for rendering)
      85                 :            :     bool isEnabled() const { return mEnabled; }
      86                 :            : 
      87                 :            :     //! Sets minimum zoom level index (negative number means no limit)
      88                 :          0 :     void setMinZoomLevel( int minZoom ) { mMinZoomLevel = minZoom; }
      89                 :            :     //! Returns minimum zoom level index (negative number means no limit)
      90                 :            :     int minZoomLevel() const { return mMinZoomLevel; }
      91                 :            : 
      92                 :            :     //! Sets maximum zoom level index (negative number means no limit)
      93                 :          0 :     void setMaxZoomLevel( int maxZoom ) { mMaxZoomLevel = maxZoom; }
      94                 :            :     //! Returns maxnimum zoom level index (negative number means no limit)
      95                 :            :     int maxZoomLevel() const { return mMaxZoomLevel; }
      96                 :            : 
      97                 :            :     //! Returns whether the style is active at given zoom level (also checks "enabled" flag)
      98                 :          0 :     bool isActive( int zoomLevel ) const
      99                 :            :     {
     100                 :          0 :       return mEnabled && ( mMinZoomLevel == -1 || zoomLevel >= mMinZoomLevel ) && ( mMaxZoomLevel == -1 || zoomLevel <= mMaxZoomLevel );
     101                 :            :     }
     102                 :            : 
     103                 :            :     //! Writes object content to given DOM element
     104                 :            :     void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;
     105                 :            :     //! Reads object content from given DOM element
     106                 :            :     void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
     107                 :            : 
     108                 :            :   private:
     109                 :            :     QString mStyleName;
     110                 :            :     QString mLayerName;
     111                 :            :     QgsWkbTypes::GeometryType mGeometryType;
     112                 :            :     std::unique_ptr<QgsSymbol> mSymbol;
     113                 :            :     bool mEnabled = true;
     114                 :            :     QString mExpression;
     115                 :            :     int mMinZoomLevel = -1;
     116                 :            :     int mMaxZoomLevel = -1;
     117                 :            : };
     118                 :            : 
     119                 :            : 
     120                 :            : /**
     121                 :            :  * \ingroup core
     122                 :            :  * \brief The default vector tile renderer implementation. It has an ordered list of "styles",
     123                 :            :  * each defines a rendering rule.
     124                 :            :  *
     125                 :            :  * \since QGIS 3.14
     126                 :            :  */
     127                 :          0 : class CORE_EXPORT QgsVectorTileBasicRenderer : public QgsVectorTileRenderer
     128                 :            : {
     129                 :            :   public:
     130                 :            :     //! Constructs renderer with no styles
     131                 :            :     QgsVectorTileBasicRenderer();
     132                 :            : 
     133                 :            :     QString type() const override;
     134                 :            :     QgsVectorTileBasicRenderer *clone() const override SIP_FACTORY;
     135                 :            :     void startRender( QgsRenderContext &context, int tileZoom, const QgsTileRange &tileRange ) override;
     136                 :            :     QMap<QString, QSet<QString> > usedAttributes( const QgsRenderContext & ) override SIP_SKIP;
     137                 :            :     QSet< QString > requiredLayers( QgsRenderContext &context, int tileZoom ) const override;
     138                 :            :     void stopRender( QgsRenderContext &context ) override;
     139                 :            :     void renderTile( const QgsVectorTileRendererData &tile, QgsRenderContext &context ) override;
     140                 :            :     void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
     141                 :            :     void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
     142                 :            : 
     143                 :            :     //! Sets list of styles of the renderer
     144                 :            :     void setStyles( const QList<QgsVectorTileBasicRendererStyle> &styles );
     145                 :            :     //! Returns list of styles of the renderer
     146                 :            :     QList<QgsVectorTileBasicRendererStyle> styles() const;
     147                 :            :     //! Updates style definition at the paricular index of the list (the index must be in interval [0,N-1] otherwise this function does nothing)
     148                 :            :     void setStyle( int index, const QgsVectorTileBasicRendererStyle &style ) { mStyles[index] = style; }
     149                 :            :     //! Returns style definition at the particular index
     150                 :            :     QgsVectorTileBasicRendererStyle style( int index ) const { return mStyles[index]; }
     151                 :            : 
     152                 :            :     //! Returns a list of styles to render all layers with the given fill/stroke colors, stroke widths and marker sizes
     153                 :            :     static QList<QgsVectorTileBasicRendererStyle> simpleStyle(
     154                 :            :       const QColor &polygonFillColor, const QColor &polygonStrokeColor, double polygonStrokeWidth,
     155                 :            :       const QColor &lineStrokeColor, double lineStrokeWidth,
     156                 :            :       const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize );
     157                 :            : 
     158                 :            :     //! Returns a list of styles to render all layers, using random colors
     159                 :            :     static QList<QgsVectorTileBasicRendererStyle> simpleStyleWithRandomColors();
     160                 :            : 
     161                 :            :   private:
     162                 :            :     void setDefaultStyle();
     163                 :            : 
     164                 :            :   private:
     165                 :            :     //! List of rendering styles
     166                 :            :     QList<QgsVectorTileBasicRendererStyle> mStyles;
     167                 :            : 
     168                 :            :     // temporary bits
     169                 :            : 
     170                 :            :     //! Names of required fields for each sub-layer (only valid between startRender/stopRender calls)
     171                 :            :     QMap<QString, QSet<QString> > mRequiredFields;
     172                 :            : 
     173                 :            : };
     174                 :            : 
     175                 :            : #endif // QGSVECTORTILEBASICRENDERER_H

Generated by: LCOV version 1.14