Marble

GeoGraphicsItem.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de>
4//
5
6// Self
7#include "GeoGraphicsItem.h"
8#include "GeoGraphicsItem_p.h"
9
10#include "GeoDataPlacemark.h"
11
12// Qt
13#include "MarbleDebug.h"
14
15#include <QColor>
16
17using namespace Marble;
18
19GeoGraphicsItem::GeoGraphicsItem(const GeoDataFeature *feature)
20 : d(new GeoGraphicsItemPrivate(feature))
21{
22 setFlag(ItemIsVisible, true);
23}
24
25GeoGraphicsItem::~GeoGraphicsItem()
26{
27 delete d;
28}
29
30bool GeoGraphicsItem::visible() const
31{
32 return d->m_flags & ItemIsVisible;
33}
34
35void GeoGraphicsItem::setVisible(bool visible)
36{
37 setFlag(ItemIsVisible, visible);
38}
39
40GeoGraphicsItem::GeoGraphicsItemFlags GeoGraphicsItem::flags() const
41{
42 return d->m_flags;
43}
44
45void GeoGraphicsItem::setFlag(GeoGraphicsItemFlag flag, bool enabled)
46{
47 if (enabled) {
48 d->m_flags = d->m_flags | flag;
49 } else {
50 d->m_flags = d->m_flags & ~flag;
51 }
52}
53
54void GeoGraphicsItem::setFlags(GeoGraphicsItemFlags flags)
55{
56 d->m_flags = flags;
57}
58
59const GeoDataFeature *GeoGraphicsItem::feature() const
60{
61 return d->m_feature;
62}
63
64void GeoGraphicsItem::setHighlightStyle(const GeoDataStyle::ConstPtr &highlightStyle)
65{
66 /**
67 * Delete any previously set style
68 * and assign the new style highlightStyle
69 */
70 d->m_highlightStyle = highlightStyle;
71}
72
73GeoDataStyle::ConstPtr GeoGraphicsItem::style() const
74{
75 /**
76 * m_isHighlight is set true when the item is
77 * supposed to be colored highlighted
78 */
79 if (d->m_highlighted && d->m_highlightStyle) {
80 return d->m_highlightStyle;
81 }
82
83 if (!d->m_style) {
84 if (const auto placemark = geodata_cast<GeoDataPlacemark>(d->m_feature)) {
85 auto styling = StyleParameters(placemark, d->m_renderContext.tileLevel());
86 for (auto relation : std::as_const(d->m_relations)) {
87 if (relation->isVisible()) {
88 styling.relation = relation;
89 break;
90 }
91 }
92 d->m_style = d->m_styleBuilder->createStyle(styling);
93 } else {
94 d->m_style = d->m_feature->style();
95 }
96 }
97
98 return d->m_style;
99}
100
101void GeoGraphicsItem::setStyleBuilder(const StyleBuilder *styleBuilder)
102{
103 d->m_styleBuilder = styleBuilder;
104}
105
106void GeoGraphicsItem::resetStyle()
107{
108 d->m_style = GeoDataStyle::ConstPtr();
109 handleRelationUpdate(d->m_relations);
110}
111
112qreal GeoGraphicsItem::zValue() const
113{
114 return d->m_zValue;
115}
116
117void GeoGraphicsItem::setZValue(qreal z)
118{
119 d->m_zValue = z;
120}
121
122void GeoGraphicsItem::setHighlighted(bool highlight)
123{
124 d->m_highlighted = highlight;
125}
126
127bool GeoGraphicsItem::isHighlighted() const
128{
129 return d->m_highlighted;
130}
131
132QStringList GeoGraphicsItem::paintLayers() const
133{
134 return d->m_paintLayers;
135}
136
137void GeoGraphicsItem::setPaintLayers(const QStringList &paintLayers)
138{
139 d->m_paintLayers = paintLayers;
140}
141
142void GeoGraphicsItem::setRenderContext(const RenderContext &renderContext)
143{
144 if (renderContext != d->m_renderContext) {
145 d->m_renderContext = renderContext;
146 d->m_style = GeoDataStyle::ConstPtr();
147 }
148}
149
150bool GeoGraphicsItem::contains(const QPoint &, const ViewportParams *) const
151{
152 return false;
153}
154
155void GeoGraphicsItem::setRelations(const QSet<const GeoDataRelation *> &relations)
156{
157 d->m_relations.clear();
158 std::copy(relations.begin(), relations.end(), std::back_inserter(d->m_relations));
159 std::sort(d->m_relations.begin(), d->m_relations.end(), [](const GeoDataRelation *a, const GeoDataRelation *b) {
160 return *a < *b;
161 });
162
163 d->m_style = GeoDataStyle::ConstPtr();
164 handleRelationUpdate(d->m_relations);
165}
166
167void GeoGraphicsItem::handleRelationUpdate(const QList<const GeoDataRelation *> &)
168{
169 // does nothing
170}
171
172int GeoGraphicsItem::minZoomLevel() const
173{
174 return d->m_minZoomLevel;
175}
176
177void GeoGraphicsItem::setMinZoomLevel(int zoomLevel)
178{
179 d->m_minZoomLevel = zoomLevel;
180}
181
182bool GeoGraphicsItem::zValueLessThan(GeoGraphicsItem *one, GeoGraphicsItem *two)
183{
184 return one->d->m_zValue < two->d->m_zValue;
185}
186
187bool GeoGraphicsItem::styleLessThan(GeoGraphicsItem *one, GeoGraphicsItem *two)
188{
189 return reinterpret_cast<quint64>(one->d->m_style.data()) < reinterpret_cast<quint64>(two->d->m_style.data());
190}
191
192bool GeoGraphicsItem::zValueAndStyleLessThan(GeoGraphicsItem *one, GeoGraphicsItem *two)
193{
194 if (one->d->m_zValue == two->d->m_zValue) {
195 return reinterpret_cast<quint64>(one->d->m_style.data()) < reinterpret_cast<quint64>(two->d->m_style.data());
196 }
197
198 return one->d->m_zValue < two->d->m_zValue;
199}
200
201bool RenderContext::operator==(const RenderContext &other) const
202{
203 return m_tileLevel == other.m_tileLevel;
204}
205
206bool RenderContext::operator!=(const RenderContext &other) const
207{
208 return !operator==(other);
209}
210
211int RenderContext::tileLevel() const
212{
213 return m_tileLevel;
214}
215
216RenderContext::RenderContext(int tileLevel)
217 : m_tileLevel(tileLevel)
218{
219 // nothing to do
220}
A base class for all geodata features.
A public class that controls what is visible in the viewport of a Marble map.
Binds a QML item to a specific geodetic location in screen coordinates.
T * geodata_cast(GeoDataObject *node)
Returns the given node cast to type T if the node was instantiated as type T; otherwise returns 0.
iterator begin()
iterator end()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.