1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2023-05-15
 * Description : geolocation engine based on Marble.
 *               (c) 2007-2022 Marble Team
 *               https://invent.kde.org/education/marble/-/raw/master/data/credits_authors.html
 *
 * SPDX-FileCopyrightText: 2023-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 * ============================================================ */

#include "GeoGraphicsItem.h"
#include "GeoGraphicsItem_p.h"

// Qt includes

#include <QColor>

// Local includes

#include "GeoDataPlacemark.h"
#include "digikam_debug.h"

namespace Marble
{

GeoGraphicsItem::GeoGraphicsItem(const GeoDataFeature* feature)
    : d(new GeoGraphicsItemPrivate(feature))<--- Class 'GeoGraphicsItem' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).<--- Class 'GeoGraphicsItem' does not have a operator= which is recommended since it has dynamic memory/resource allocation(s).
{
    setFlag(ItemIsVisible, true);
}

GeoGraphicsItem::~GeoGraphicsItem()
{
    delete d;
}

bool GeoGraphicsItem::visible() const
{
    return d->m_flags & ItemIsVisible;
}

void GeoGraphicsItem::setVisible(bool visible)
{
    setFlag(ItemIsVisible, visible);
}

GeoGraphicsItem::GeoGraphicsItemFlags GeoGraphicsItem::flags() const
{
    return d->m_flags;
}

void GeoGraphicsItem::setFlag(GeoGraphicsItemFlag flag, bool enabled)
{
    if (enabled)
    {
        d->m_flags = d->m_flags | flag;
    }

    else
    {
        d->m_flags = d->m_flags & ~flag;
    }
}

void GeoGraphicsItem::setFlags(GeoGraphicsItemFlags flags)
{
    d->m_flags = flags;
}

const GeoDataFeature* GeoGraphicsItem::feature() const
{
    return d->m_feature;
}

void GeoGraphicsItem::setHighlightStyle(const GeoDataStyle::ConstPtr& highlightStyle)
{
    /**
     * Delete any previously set style
     * and assign the new style highlightStyle
     */
    d->m_highlightStyle = highlightStyle;
}

GeoDataStyle::ConstPtr GeoGraphicsItem::style() const
{
    /**
     * m_isHighlight is set true when the item is
     * supposed to be colored highlighted
     */
    if (d->m_highlighted && d->m_highlightStyle)
    {
        return d->m_highlightStyle;
    }

    if (!d->m_style)
    {
        if (const GeoDataPlacemark* placemark = geodata_cast<GeoDataPlacemark>(d->m_feature))
        {
            auto styling = StyleParameters(placemark, d->m_renderContext.tileLevel());

            for (auto relation : d->m_relations)
            {
                if (relation->isVisible())
                {
                    styling.relation = relation;
                    break;
                }
            }

            d->m_style = d->m_styleBuilder->createStyle(styling);
        }

        else
        {
            d->m_style = d->m_feature->style();
        }
    }

    return d->m_style;
}

void GeoGraphicsItem::setStyleBuilder(const StyleBuilder* styleBuilder)
{
    d->m_styleBuilder = styleBuilder;
}

void GeoGraphicsItem::resetStyle()
{
    d->m_style = GeoDataStyle::ConstPtr();
    handleRelationUpdate(d->m_relations);
}

qreal GeoGraphicsItem::zValue() const
{
    return d->m_zValue;
}

void GeoGraphicsItem::setZValue(qreal z)
{
    d->m_zValue = z;
}

void GeoGraphicsItem::setHighlighted(bool highlight)
{
    d->m_highlighted = highlight;
}

bool GeoGraphicsItem::isHighlighted() const
{
    return d->m_highlighted;
}

QStringList GeoGraphicsItem::paintLayers() const
{
    return d->m_paintLayers;
}

void GeoGraphicsItem::setPaintLayers(const QStringList& paintLayers)
{
    d->m_paintLayers = paintLayers;
}

void GeoGraphicsItem::setRenderContext(const RenderContext& renderContext)
{
    if (renderContext != d->m_renderContext)
    {
        d->m_renderContext = renderContext;
        d->m_style = GeoDataStyle::ConstPtr();
    }
}

bool GeoGraphicsItem::contains(const QPoint&, const ViewportParams*) const
{
    return false;
}

void GeoGraphicsItem::setRelations(const QSet<const GeoDataRelation*>& relations)
{
    d->m_relations.clear();
    std::copy(relations.begin(), relations.end(), std::back_inserter(d->m_relations));
    std::sort(d->m_relations.begin(), d->m_relations.end(),
              [](const GeoDataRelation * a, const GeoDataRelation * b)
    {
        return *a < *b;
    });

    d->m_style = GeoDataStyle::ConstPtr();
    handleRelationUpdate(d->m_relations);
}

void GeoGraphicsItem::handleRelationUpdate(const QVector<const GeoDataRelation*>&)
{
    // does nothing
}

int GeoGraphicsItem::minZoomLevel() const
{
    return d->m_minZoomLevel;
}

void GeoGraphicsItem::setMinZoomLevel(int zoomLevel)
{
    d->m_minZoomLevel = zoomLevel;
}

bool GeoGraphicsItem::zValueLessThan(GeoGraphicsItem* one, GeoGraphicsItem* two)
{
    return one->d->m_zValue < two->d->m_zValue;
}

bool GeoGraphicsItem::styleLessThan(GeoGraphicsItem* one, GeoGraphicsItem* two)
{
    return reinterpret_cast<quint64>(one->d->m_style.data()) < reinterpret_cast<quint64>(two->d->m_style.data());
}

bool GeoGraphicsItem::zValueAndStyleLessThan(GeoGraphicsItem* one, GeoGraphicsItem* two)
{
    if (one->d->m_zValue == two->d->m_zValue)
    {
        return reinterpret_cast<quint64>(one->d->m_style.data()) < reinterpret_cast<quint64>(two->d->m_style.data());
    }

    return one->d->m_zValue < two->d->m_zValue;
}


bool RenderContext::operator==(const RenderContext& other) const
{
    return m_tileLevel == other.m_tileLevel;
}

bool RenderContext::operator!=(const RenderContext& other) const
{
    return !operator==(other);
}

int RenderContext::tileLevel() const
{
    return m_tileLevel;
}

RenderContext::RenderContext(int tileLevel) :
    m_tileLevel(tileLevel)
{
    // nothing to do
}

} // namespace Marble