Marble

GeoGraphicsItem.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2009 Bastian Holst <[email protected]>
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 
17 using namespace Marble;
18 
19 GeoGraphicsItem::GeoGraphicsItem( const GeoDataFeature *feature )
20  : d( new GeoGraphicsItemPrivate( feature ) )
21 {
22  setFlag( ItemIsVisible, true );
23 }
24 
25 GeoGraphicsItem::~GeoGraphicsItem()
26 {
27  delete d;
28 }
29 
30 bool GeoGraphicsItem::visible() const
31 {
32  return d->m_flags & ItemIsVisible;
33 }
34 
35 void GeoGraphicsItem::setVisible( bool visible )
36 {
37  setFlag( ItemIsVisible, visible );
38 }
39 
40 GeoGraphicsItem::GeoGraphicsItemFlags GeoGraphicsItem::flags() const
41 {
42  return d->m_flags;
43 }
44 
45 void 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 
54 void GeoGraphicsItem::setFlags( GeoGraphicsItemFlags flags )
55 {
56  d->m_flags = flags;
57 }
58 
59 const GeoDataFeature* GeoGraphicsItem::feature() const
60 {
61  return d->m_feature;
62 }
63 
64 void 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 
73 GeoDataStyle::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 
101 void GeoGraphicsItem::setStyleBuilder(const StyleBuilder *styleBuilder)
102 {
103  d->m_styleBuilder = styleBuilder;
104 }
105 
106 void GeoGraphicsItem::resetStyle()
107 {
108  d->m_style = GeoDataStyle::ConstPtr();
109  handleRelationUpdate(d->m_relations);
110 }
111 
112 qreal GeoGraphicsItem::zValue() const
113 {
114  return d->m_zValue;
115 }
116 
117 void GeoGraphicsItem::setZValue( qreal z )
118 {
119  d->m_zValue = z;
120 }
121 
122 void GeoGraphicsItem::setHighlighted( bool highlight )
123 {
124  d->m_highlighted = highlight;
125 }
126 
127 bool GeoGraphicsItem::isHighlighted() const
128 {
129  return d->m_highlighted;
130 }
131 
132 QStringList GeoGraphicsItem::paintLayers() const
133 {
134  return d->m_paintLayers;
135 }
136 
137 void GeoGraphicsItem::setPaintLayers(const QStringList &paintLayers)
138 {
139  d->m_paintLayers = paintLayers;
140 }
141 
142 void 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 
150 bool GeoGraphicsItem::contains(const QPoint &, const ViewportParams *) const
151 {
152  return false;
153 }
154 
155 void 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 
168 void GeoGraphicsItem::handleRelationUpdate(const QVector<const GeoDataRelation *> &)
169 {
170  // does nothing
171 }
172 
173 int GeoGraphicsItem::minZoomLevel() const
174 {
175  return d->m_minZoomLevel;
176 }
177 
178 void GeoGraphicsItem::setMinZoomLevel(int zoomLevel)
179 {
180  d->m_minZoomLevel = zoomLevel;
181 }
182 
183 bool GeoGraphicsItem::zValueLessThan(GeoGraphicsItem *one, GeoGraphicsItem *two)
184 {
185  return one->d->m_zValue < two->d->m_zValue;
186 }
187 
188 bool 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 
193 bool 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 
203 bool RenderContext::operator==(const RenderContext &other) const
204 {
205  return m_tileLevel == other.m_tileLevel;
206 }
207 
208 bool RenderContext::operator!=(const RenderContext &other) const
209 {
210  return !operator==(other);
211 }
212 
213 int RenderContext::tileLevel() const
214 {
215  return m_tileLevel;
216 }
217 
218 RenderContext::RenderContext(int tileLevel) :
219  m_tileLevel(tileLevel)
220 {
221  // nothing to do
222 }
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
A public class that controls what is visible in the viewport of a Marble map.
A base class for all geodata features.
Binds a QML item to a specific geodetic location in screen coordinates.
QSet::iterator begin()
a class representing a point of interest on the map
QSet::iterator end()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Oct 2 2023 03:52:08 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.