File indexing completed on 2025-02-16 04:21:47
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_PAINTERRENDERER_H 0008 #define KOSMINDOORMAP_PAINTERRENDERER_H 0009 0010 #include "kosmindoormap_export.h" 0011 0012 #include <KOSMIndoorMap/SceneGraphItem> 0013 0014 class QPainter; 0015 0016 namespace KOSMIndoorMap { 0017 0018 class SceneGraph; 0019 class View; 0020 0021 /** QPainter-based renderer of a SceneGraph. 0022 * Trying to keep this somewhat backend-agnostic to possibly implement a 3D renderer in the future. 0023 */ 0024 class KOSMINDOORMAP_EXPORT PainterRenderer 0025 { 0026 public: 0027 explicit PainterRenderer(); 0028 ~PainterRenderer(); 0029 0030 void setPainter(QPainter *painter); 0031 void render(const SceneGraph &sg, View *view); 0032 0033 private: 0034 void beginRender(); 0035 void beginPhase(SceneGraphItemPayload::RenderPhase phase); 0036 void prepareBatch(SceneGraphItemPayload::RenderPhase phase); 0037 void renderBackground(const QColor &bgColor); 0038 void renderPolygon(PolygonItem *item, SceneGraphItemPayload::RenderPhase phase); 0039 void renderMultiPolygon(MultiPolygonItem *item, SceneGraphItemPayload::RenderPhase phase); 0040 void renderPolyline(PolylineItem *item, SceneGraphItemPayload::RenderPhase phase); 0041 void renderLabel(LabelItem *item, SceneGraphItemPayload::RenderPhase phase); 0042 void renderForeground(const QColor &bgColor); 0043 void endRender(); 0044 0045 template <typename T> 0046 void renderPolygonFill(PolygonBaseItem *item, const T &geom); 0047 template <typename T> 0048 void renderPolygonLine(PolygonBaseItem *item, const T &geom); 0049 template <typename T> 0050 void renderPolygonCasing(PolygonBaseItem *item, const T &geom); 0051 0052 [[nodiscard]] double mapToSceneWidth(double width, Unit unit) const; 0053 // inverse view transformation with translation applied 0054 // needed for textured brushes 0055 [[nodiscard]] QTransform brushTransform() const; 0056 0057 QPainter *m_painter = nullptr; 0058 View *m_view = nullptr; 0059 0060 std::vector<SceneGraphItemPayload*> m_renderBatch; // member rather than function-local to preserve allocations 0061 }; 0062 0063 } 0064 0065 #endif // KOSMINDOORMAP_PAINTERRENDERER_H