Cppcheck - HTML report - digiKam-nl-search-more-criteria-rev-e2466e0973

# Cppcheck report - digiKam-nl-search-more-criteria-rev-e2466e0973: ../../core/utilities/geolocation/engine/geodata/data/GeoDataLabelStyle.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
    /* ============================================================
     *
     * 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 "GeoDataLabelStyle.h"

    // Qt includes

    #include <QFont>
    #include <QColor>
    #include <QDataStream>

    // Local includes

    #include "GeoDataTypes.h"

    namespace Marble
    {
    #ifdef Q_OS_MACOS
    static const int defaultSize = 10;
    #else
    static const int defaultSize = 8;
    #endif

    class Q_DECL_HIDDEN GeoDataLabelStylePrivate
    {
    public:

        GeoDataLabelStylePrivate()
            : m_scale(1.0),
              m_alignment(GeoDataLabelStyle::Corner),
              m_font(QFont(QStringLiteral("Sans Serif")).family(), defaultSize, 50, false),
              m_glow(true)
        {
        }

        explicit GeoDataLabelStylePrivate(const QFont& font)
            : m_scale(1.0),
              m_alignment(GeoDataLabelStyle::Corner),
              m_font(font),
              m_glow(true)
        {
        }

        /// The current scale of the label
        float                        m_scale;
        /// The current alignment of the label
        GeoDataLabelStyle::Alignment m_alignment;
        /// The current font of the label
        QFont                        m_font;   // Not a KML property
        /// Whether or not the text should glow
        bool                         m_glow; // Not a KML property
    };

    GeoDataLabelStyle::GeoDataLabelStyle()
        : d(new GeoDataLabelStylePrivate)
    {
        setColor(QColor(Qt::black));
    }

    GeoDataLabelStyle::GeoDataLabelStyle(const GeoDataLabelStyle& other)
        : GeoDataColorStyle(other), d(new GeoDataLabelStylePrivate(*other.d))
    {
    }

    GeoDataLabelStyle::GeoDataLabelStyle(const QFont& font, const QColor& color)
        : d(new GeoDataLabelStylePrivate(font))
    {
        setColor(color);
    }

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

    GeoDataLabelStyle& GeoDataLabelStyle::operator=(const GeoDataLabelStyle& other)
    {
        GeoDataColorStyle::operator=(other);
        *d = *other.d;
        return *this;
    }

    bool GeoDataLabelStyle::operator==(const GeoDataLabelStyle& other) const
    {
        if (GeoDataColorStyle::operator!=(other))
        {
            return false;
        }

        return d->m_scale == other.d->m_scale &&
               d->m_alignment == other.d->m_alignment &&
               d->m_font == other.d->m_font &&
               d->m_glow == other.d->m_glow;
    }

    bool GeoDataLabelStyle::operator!=(const GeoDataLabelStyle& other) const
    {
        return !this->operator==(other);
    }

    const char* GeoDataLabelStyle::nodeType() const
    {
        return GeoDataTypes::GeoDataLabelStyleType;
    }

    void GeoDataLabelStyle::setAlignment(GeoDataLabelStyle::Alignment alignment)<--- Shadow argument
    {
        d->m_alignment = alignment;
    }

    GeoDataLabelStyle::Alignment GeoDataLabelStyle::alignment() const
    {
        return d->m_alignment;
    }

    void GeoDataLabelStyle::setScale(float scale)<--- Shadow argument
    {
        d->m_scale = scale;
    }

    float GeoDataLabelStyle::scale() const
    {
        return d->m_scale;
    }

    void GeoDataLabelStyle::setFont(const QFont& font)<--- Shadow argument
    {
        d->m_font = font;
    }

    QFont GeoDataLabelStyle::font() const
    {
        return d->m_font;
    }

    QFont GeoDataLabelStyle::scaledFont() const
    {
        // Font shouldn't be smaller (or equal to) than 0, but if it is, regular font is returned
        // setPointSize() takes an integer as parameter, so rounded value should be checked
        if (qRound(font().pointSize() * scale()) <= 0)
        {
            return font();
        }

        QFont scaledFont = font();
        scaledFont.setPointSize(qRound(scaledFont.pointSize() * scale()));
        return scaledFont;
    }

    bool GeoDataLabelStyle::glow() const
    {
        return d->m_glow;
    }

    void GeoDataLabelStyle::setGlow(bool on)
    {
        d->m_glow = on;
    }

    void GeoDataLabelStyle::pack(QDataStream& stream) const
    {
        GeoDataColorStyle::pack(stream);

        stream << d->m_scale;
        stream << d->m_alignment;
        stream << d->m_font;
    }

    void GeoDataLabelStyle::unpack(QDataStream& stream)
    {
        int a;
        GeoDataColorStyle::unpack(stream);

        stream >> d->m_scale;
        stream >> a;
        stream >> d->m_font;

        d->m_alignment = static_cast<GeoDataLabelStyle::Alignment>(a);
    }

    } // namespace Marble