File indexing completed on 2024-11-17 04:17:27
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KOSMINDOORMAP_MAPCSSRESULT_P_H 0008 #define KOSMINDOORMAP_MAPCSSRESULT_P_H 0009 0010 #include "kosmindoormap_export.h" 0011 0012 #include "mapcsstypes.h" 0013 0014 #include <qcompilerdetection.h> 0015 0016 #include <memory> 0017 #include <vector> 0018 0019 class QByteArray; 0020 0021 namespace OSM { 0022 class Tag; 0023 class TagKey; 0024 } 0025 0026 namespace KOSMIndoorMap { 0027 0028 class MapCSSDeclaration; 0029 enum class MapCSSProperty; 0030 class MapCSSRule; 0031 0032 class MapCSSResult; 0033 class MapCSSResultLayerPrivate; 0034 0035 /** Result of MapCSS stylesheet evaluation for a single layer selector. */ 0036 class KOSMINDOORMAP_EXPORT MapCSSResultLayer 0037 { 0038 public: 0039 explicit MapCSSResultLayer(); 0040 MapCSSResultLayer(const MapCSSResultLayer&) = delete; 0041 MapCSSResultLayer(MapCSSResultLayer&&) noexcept; 0042 MapCSSResultLayer& operator=(const MapCSSResultLayer&) = delete; 0043 MapCSSResultLayer& operator=(MapCSSResultLayer&&) noexcept; 0044 ~MapCSSResultLayer(); 0045 0046 void clear(); 0047 0048 /** Returns @c true if an area/polygon needs to be drawn. */ 0049 [[nodiscard]] bool hasAreaProperties() const; 0050 /** Returns @c true if a way/line needs to be drawn. */ 0051 [[nodiscard]] bool hasLineProperties() const; 0052 /** Returns @c true if a label needs to be drawn. */ 0053 [[nodiscard]] bool hasLabelProperties() const; 0054 /** Returns @c true if a 3D extrusion is requested. */ 0055 [[nodiscard]] bool hasExtrudeProperties() const; 0056 0057 /** Returns the declaration for property @prop, or @c nullptr is this property isn't set. */ 0058 [[nodiscard]] const MapCSSDeclaration* declaration(MapCSSProperty prop) const; 0059 /** The active declarations for the queried element. */ 0060 [[nodiscard]] const std::vector<const MapCSSDeclaration*>& declarations() const; 0061 0062 /** The layer selector for this result. */ 0063 [[nodiscard]] LayerSelectorKey layerSelector() const; 0064 0065 /** Tag lookup for tags overridden by the style sheet. */ 0066 [[nodiscard]] QByteArray tagValue(OSM::TagKey key) const; 0067 0068 /** Check whether this result layer has class @p cls set. */ 0069 [[nodiscard]] bool hasClass(ClassSelectorKey cls) const; 0070 0071 private: 0072 friend class MapCSSResult; 0073 friend class MapCSSRule; 0074 0075 Q_DECL_HIDDEN void addDeclaration(const MapCSSDeclaration *decl); 0076 Q_DECL_HIDDEN void addClass(ClassSelectorKey cls); 0077 Q_DECL_HIDDEN void setLayerSelector(LayerSelectorKey layer); 0078 Q_DECL_HIDDEN void setTag(OSM::Tag &&tag); 0079 0080 std::unique_ptr<MapCSSResultLayerPrivate> d; 0081 }; 0082 0083 class MapCSSBasicSelector; 0084 class MapCSSResultPrivate; 0085 0086 /** Result of MapCSS stylesheet evaluation for all layer selectors. 0087 * For performance reason it is highly recommended to reuse the same instance 0088 * accross multiple style evaluations. 0089 */ 0090 class KOSMINDOORMAP_EXPORT MapCSSResult 0091 { 0092 public: 0093 explicit MapCSSResult(); 0094 MapCSSResult(const MapCSSResultLayer&) = delete; 0095 MapCSSResult(MapCSSResult&&) noexcept; 0096 MapCSSResult& operator=(const MapCSSResult&) = delete; 0097 MapCSSResult& operator=(MapCSSResult&&) noexcept; 0098 ~MapCSSResult(); 0099 0100 /** Reset result state from a previous evaluation, 0101 * while retaining previously allocated resource for reuse. 0102 */ 0103 void clear(); 0104 0105 /** Results for all layer selectors. */ 0106 [[nodiscard]] const std::vector<MapCSSResultLayer>& results() const; 0107 /** Access a specific result layer selector. */ 0108 [[nodiscard]] const MapCSSResultLayer& operator[](LayerSelectorKey layer) const; 0109 [[nodiscard]] MapCSSResultLayer& operator[](LayerSelectorKey layer); 0110 0111 private: 0112 friend class MapCSSBasicSelector; 0113 /** Apply @p declarations for @p layer to the result. */ 0114 Q_DECL_HIDDEN void applyDeclarations(LayerSelectorKey layer, const std::vector<std::unique_ptr<MapCSSDeclaration>> &declarations); 0115 0116 std::unique_ptr<MapCSSResultPrivate> d; 0117 }; 0118 0119 } 0120 0121 #endif // KOSMINDOORMAP_MAPCSSRESULT_P_H