Cppcheck - HTML report - digiKam-master-rev-960d3ce42d

# Cppcheck report - digiKam-master-rev-960d3ce42d: ../../core/utilities/geolocation/engine/geodata/data/GeoDataRelation.cpp

      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
    /* ============================================================
     *
     * 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-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
     *
     * SPDX-License-Identifier: LGPL-2.1-or-later
     *
     * ============================================================ */

    #include "GeoDataRelation.h"

    // Qt includes

    #include <QSet>

    // Local includes

    #include "GeoDataTypes.h"
    #include "OsmPlacemarkData.h"

    namespace Marble
    {

    class Q_DECL_HIDDEN GeoDataRelationPrivate
    {
    public:

        QSet<const GeoDataFeature*>                          m_features;
        OsmPlacemarkData                                     m_osmData;
        QSet<qint64>                                         m_memberIds;

        mutable GeoDataRelation::RelationType                m_relationType = GeoDataRelation::UnknownType;
        mutable bool                                         m_relationTypeDirty = true;
        static QHash<QString, GeoDataRelation::RelationType> s_relationTypes;
    };

    QHash<QString, GeoDataRelation::RelationType> GeoDataRelationPrivate::s_relationTypes;

    GeoDataRelation::GeoDataRelation()
        : GeoDataFeature(),
          d_ptr         (new GeoDataRelationPrivate)
    {
        // nothing to do
    }

    GeoDataRelation::~GeoDataRelation()
    {
        delete d_ptr;
    }

    GeoDataRelation::GeoDataRelation(const GeoDataRelation& other) :
        GeoDataFeature(other),
        d_ptr         (new GeoDataRelationPrivate)
    {
        Q_D(GeoDataRelation);
        d->m_features           = other.d_func()->m_features;
        d->m_osmData            = other.d_func()->m_osmData;
        d->m_memberIds          = other.d_func()->m_memberIds;
        d->m_relationType       = other.d_func()->m_relationType;
        d->m_relationTypeDirty  = other.d_func()->m_relationTypeDirty;
    }

    // passed by value
    GeoDataRelation& GeoDataRelation::operator=(GeoDataRelation other)  // clazy:exclude=function-args-by-ref
    {
        GeoDataFeature::operator=(other);
        std::swap(*this->d_ptr, *other.d_ptr);
        return *this;
    }

    bool GeoDataRelation::operator<(const GeoDataRelation& other) const
    {
        if (relationType() == other.relationType())
        {
            Q_D(const GeoDataRelation);
            auto const refA = d->m_osmData.tagValue(QStringLiteral("ref"));
            auto const refB = other.osmData().tagValue(QStringLiteral("ref"));

            if (refA == refB)
            {
                return name() < other.name();
            }

            return refA < refB;
        }

        return relationType() < other.relationType();
    }

    const char* GeoDataRelation::nodeType() const
    {
        return GeoDataTypes::GeoDataRelationType;
    }

    GeoDataFeature* GeoDataRelation::clone() const
    {
        return new GeoDataRelation(*this);
    }

    void GeoDataRelation::addMember(const GeoDataFeature* feature, qint64 id, OsmType type, const QString& role)
    {
        Q_D(GeoDataRelation);
        d->m_features << feature;
        d->m_osmData.addRelation(id, type, role);
        d->m_memberIds << id;
    }

    QSet<const GeoDataFeature*> GeoDataRelation::members() const
    {
        Q_D(const GeoDataRelation);
        return d->m_features;
    }

    OsmPlacemarkData& GeoDataRelation::osmData()
    {
        Q_D(GeoDataRelation);
        d->m_relationTypeDirty = true;
        return d->m_osmData;
    }

    const OsmPlacemarkData& GeoDataRelation::osmData() const
    {
        Q_D(const GeoDataRelation);
        return d->m_osmData;
    }

    GeoDataRelation::RelationType GeoDataRelation::relationType() const
    {
        Q_D(const GeoDataRelation);

        if (!d->m_relationTypeDirty)
        {
            return d->m_relationType;
        }

        if (GeoDataRelationPrivate::s_relationTypes.isEmpty())
        {
            auto& map = GeoDataRelationPrivate::s_relationTypes;
            map[QStringLiteral("road")] = RouteRoad;
            map[QStringLiteral("detour")] = RouteDetour;
            map[QStringLiteral("ferry")] = RouteFerry;
            map[QStringLiteral("train")] = RouteTrain;
            map[QStringLiteral("subway")] = RouteSubway;
            map[QStringLiteral("tram")] = RouteTram;
            map[QStringLiteral("bus")] = RouteBus;
            map[QStringLiteral("trolleybus")] = RouteTrolleyBus;
            map[QStringLiteral("bicycle")] = RouteBicycle;
            map[QStringLiteral("mtb")] = RouteMountainbike;
            map[QStringLiteral("foot")] = RouteFoot;
            map[QStringLiteral("hiking")] = GeoDataRelation::RouteHiking;
            map[QStringLiteral("horse")] = RouteHorse;
            map[QStringLiteral("inline_skates")] = RouteInlineSkates;
        }

        d->m_relationType = GeoDataRelation::UnknownType;
        d->m_relationTypeDirty = false;

        if (d->m_osmData.containsTag(QStringLiteral("type"), QStringLiteral("route")))
        {
            auto const route = d->m_osmData.tagValue(QStringLiteral("route"));

            if (route == QStringLiteral("piste"))
            {
                auto const piste = d->m_osmData.tagValue(QStringLiteral("piste:type"));

                if (piste == QStringLiteral("downhill"))
                {
                    d->m_relationType = RouteSkiDownhill;
                }

                else if (piste == QStringLiteral("nordic"))
                {
                    d->m_relationType = RouteSkiNordic;
                }

                else if (piste == QStringLiteral("skitour"))
                {
                    d->m_relationType = RouteSkitour;
                }

                else if (piste == QStringLiteral("sled"))
                {
                    d->m_relationType = RouteSled;
                }
            }

            else
            {
                d->m_relationType = GeoDataRelationPrivate::s_relationTypes.value(route, UnknownType);
            }
        }

        return d->m_relationType;
    }

    QSet<qint64> GeoDataRelation::memberIds() const
    {
        Q_D(const GeoDataRelation);
        return d->m_memberIds;
    }

    bool GeoDataRelation::containsAnyOf(const QSet<qint64>& memberIds) const<--- Shadow argument
    {
        Q_D(const GeoDataRelation);
        return d->m_memberIds.intersects(memberIds);
    }

    Q_DECLARE_OPERATORS_FOR_FLAGS(GeoDataRelation::RelationTypes)

    } // namespace Marble