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 GeoDataPlacemark *placemark = geodata_cast<GeoDataPlacemark>(d->m_feature)) {
85 auto styling = StyleParameters(placemark, d->m_renderContext.tileLevel());
86 for (auto relation: 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(),
160 [](const GeoDataRelation * a, const GeoDataRelation * b) {
161 return *a < *b;
162 });
163
164 d->m_style = GeoDataStyle::ConstPtr();
165 handleRelationUpdate(d->m_relations);
166}
167
168void GeoGraphicsItem::handleRelationUpdate(const QVector<const GeoDataRelation *> &)
169{
170 // does nothing
171}
172
173int GeoGraphicsItem::minZoomLevel() const
174{
175 return d->m_minZoomLevel;
176}
177
178void GeoGraphicsItem::setMinZoomLevel(int zoomLevel)
179{
180 d->m_minZoomLevel = zoomLevel;
181}
182
183bool GeoGraphicsItem::zValueLessThan(GeoGraphicsItem *one, GeoGraphicsItem *two)
184{
185 return one->d->m_zValue < two->d->m_zValue;
186}
187
188bool GeoGraphicsItem::styleLessThan(GeoGraphicsItem *one, GeoGraphicsItem *two)
189{
190 return reinterpret_cast<quint64>(one->d->m_style.data()) < reinterpret_cast<quint64>(two->d->m_style.data());
191}
192
193bool GeoGraphicsItem::zValueAndStyleLessThan(GeoGraphicsItem *one, GeoGraphicsItem *two)
194{
195 if (one->d->m_zValue == two->d->m_zValue) {
196 return reinterpret_cast<quint64>(one->d->m_style.data()) < reinterpret_cast<quint64>(two->d->m_style.data());
197 }
198
199 return one->d->m_zValue < two->d->m_zValue;
200}
201
202
203bool RenderContext::operator==(const RenderContext &other) const
204{
205 return m_tileLevel == other.m_tileLevel;
206}
207
208bool RenderContext::operator!=(const RenderContext &other) const
209{
210 return !operator==(other);
211}
212
213int RenderContext::tileLevel() const
214{
215 return m_tileLevel;
216}
217
218RenderContext::RenderContext(int tileLevel) :
219 m_tileLevel(tileLevel)
220{
221 // nothing to do
222}
A base class for all geodata features.
a class representing a point of interest on the map
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.
iterator begin()
iterator end()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.