1 /*************************************************************************** 2 qgsvectortilelabeling.h 3 -------------------------------------- 4 Date : April 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 QGSVECTORTILELABELING_H 17 #define QGSVECTORTILELABELING_H 18 19 #include "qgis_core.h" 20 21 #include "qgsvectorlayerlabelprovider.h" 22 23 class QgsVectorTileLayer; 24 class QgsVectorTileRendererData; 25 26 #ifndef SIP_RUN 27 28 /** 29 * \ingroup core 30 * \brief Internal base class for implementation of label providers for vector tile labeling. 31 * \since QGIS 3.14 32 */ 33 class QgsVectorTileLabelProvider : public QgsVectorLayerLabelProvider 34 { 35 public: 36 //! Constructs base label provider class for the given vector tile layer 37 explicit QgsVectorTileLabelProvider( QgsVectorTileLayer *layer ); 38 39 //! Returns field names for each sub-layer that are required for labeling 40 virtual QMap<QString, QSet<QString> > usedAttributes( const QgsRenderContext &context, int tileZoom ) const = 0; 41 42 //TODO QGIS 4.0 -- make pure virtual 43 44 /** 45 * Returns a list of the layers required for labeling. 46 * 47 * Only layers which are labeled at the specified \a tileZoom should be included in this list. 48 * 49 * An empty string present in the list indicates that all layer in the tiles are required. 50 * 51 * \since QGIS 3.16 52 */ requiredLayers(QgsRenderContext & context,int tileZoom)53 virtual QSet< QString > requiredLayers( QgsRenderContext &context, int tileZoom ) const { Q_UNUSED( context ); Q_UNUSED( tileZoom ); return QSet< QString >() << QString(); } 54 55 //! Sets fields for each sub-layer 56 virtual void setFields( const QMap<QString, QgsFields> &perLayerFields ) = 0; 57 58 //! Registers label features for given tile to the labeling engine 59 virtual void registerTileFeatures( const QgsVectorTileRendererData &tile, QgsRenderContext &context ) = 0; 60 }; 61 62 #endif 63 64 /** 65 * \ingroup core 66 * \brief Base class for labeling configuration classes for vector tile layers. 67 * 68 * \since QGIS 3.14 69 */ 70 class CORE_EXPORT QgsVectorTileLabeling 71 { 72 73 #ifdef SIP_RUN 74 SIP_CONVERT_TO_SUBCLASS_CODE 75 76 const QString type = sipCpp->type(); 77 78 if ( type == QLatin1String( "basic" ) ) 79 sipType = sipType_QgsVectorTileBasicLabeling; 80 else 81 sipType = 0; 82 SIP_END 83 #endif 84 85 public: 86 virtual ~QgsVectorTileLabeling() = default; 87 88 //! Unique type string of the labeling configuration implementation 89 virtual QString type() const = 0; 90 91 //! Returns a new copy of the object 92 virtual QgsVectorTileLabeling *clone() const = 0 SIP_FACTORY; 93 94 /** 95 * Factory for label provider implementation 96 * \note not available in Python bindings 97 */ provider(QgsVectorTileLayer * layer)98 virtual QgsVectorTileLabelProvider *provider( QgsVectorTileLayer *layer ) const SIP_SKIP { Q_UNUSED( layer ) return nullptr; } 99 100 //! Writes labeling properties to given XML element 101 virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const = 0; 102 //! Reads labeling properties from given XML element 103 virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) = 0; 104 //! Resolves references to other objects - second phase of loading - after readXml() resolveReferences(const QgsProject & project)105 virtual void resolveReferences( const QgsProject &project ) { Q_UNUSED( project ) } 106 107 }; 108 109 #endif // QGSVECTORTILELABELING_H 110