Cppcheck - HTML report - digiKam-master-rev-70b072e127

# Cppcheck report - digiKam-master-rev-70b072e127: ../../core/utilities/geolocation/geoiface/widgets/mapwidget_data.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
    /* ============================================================
     *
     * This file is a part of digiKam project
     * https://www.digikam.org
     *
     * Date        : 2009-12-01
     * Description : world map widget library
     *
     * SPDX-FileCopyrightText: 2010-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
     * SPDX-FileCopyrightText: 2009-2011 by Michael G. Hansen <mike at mghansen dot de>
     * SPDX-FileCopyrightText:      2014 by Justus Schwartz <justus at gmx dot li>
     *
     * SPDX-License-Identifier: GPL-2.0-or-later
     *
     * ============================================================ */

    #include "mapwidget_p.h"

    namespace Digikam
    {

    void MapWidget::addUngroupedModel(GeoModelHelper* const modelHelper)
    {
        s->ungroupedModels << modelHelper;

        /// @todo monitor all model signals!

        connect(modelHelper->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
                this, SLOT(slotUngroupedModelChanged()));

        connect(modelHelper->model(), SIGNAL(rowsInserted(QModelIndex,int,int)),
                this, SLOT(slotUngroupedModelChanged()));

        connect(modelHelper->model(), SIGNAL(modelReset()),
                this, SLOT(slotUngroupedModelChanged()));

        connect(modelHelper, SIGNAL(signalVisibilityChanged()),
                this, SLOT(slotUngroupedModelChanged()));

        if (modelHelper->selectionModel())
        {
            connect(modelHelper->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
                    this, SLOT(slotUngroupedModelChanged()));
        }

        Q_EMIT signalUngroupedModelChanged(s->ungroupedModels.count() - 1);
    }

    void MapWidget::removeUngroupedModel(GeoModelHelper* const modelHelper)<--- Either there is a missing override/final keyword, or the parameter 'modelHelper' can be declared as pointer to const
    {
        if (!modelHelper)
        {
            return;
        }

        const int modelIndex = s->ungroupedModels.indexOf(modelHelper);

        if (modelIndex < 0)
        {
            return;
        }

        /// @todo monitor all model signals!

        disconnect(modelHelper->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
                   this, SLOT(slotUngroupedModelChanged()));

        disconnect(modelHelper->model(), SIGNAL(rowsInserted(QModelIndex,int,int)),
                   this, SLOT(slotUngroupedModelChanged()));

        disconnect(modelHelper->model(), SIGNAL(modelReset()),
                   this, SLOT(slotUngroupedModelChanged()));

        disconnect(modelHelper, SIGNAL(signalVisibilityChanged()),
                   this, SLOT(slotUngroupedModelChanged()));

        if (modelHelper->selectionModel())
        {
            disconnect(modelHelper->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
                       this, SLOT(slotUngroupedModelChanged()));
        }

        s->ungroupedModels.removeAt(modelIndex);

        // the indices changed, therefore send out notifications
        // sending out a signal with i=s->ungroupedModel.count()
        // will cause the backends to see that the last model is missing

        for (int i = modelIndex ; i <= s->ungroupedModels.count() ; ++i)
        {
            Q_EMIT signalUngroupedModelChanged(i);
        }
    }

    void MapWidget::setGroupedModel(AbstractMarkerTiler* const markerModel)
    {
        s->markerModel = markerModel;

        if (s->markerModel)
        {
            s->markerModel->setActive(s->activeState);

            /// @todo this needs some buffering for the google maps backend

            connect(s->markerModel, SIGNAL(signalTilesOrSelectionChanged()),
                    this, SLOT(slotRequestLazyReclustering()));

            if (d->currentBackend)
            {
                connect(s->markerModel, SIGNAL(signalThumbnailAvailableForIndex(QVariant,QPixmap)),
                        d->currentBackend, SLOT(slotThumbnailAvailableForIndex(QVariant,QPixmap)));
            }
        }

        slotRequestLazyReclustering();
    }

    void MapWidget::setDragDropHandler(GeoDragDropHandler* const dragDropHandler)
    {
        d->dragDropHandler = dragDropHandler;
    }

    void MapWidget::setTrackManager(TrackManager* const trackManager)
    {
        s->trackManager = trackManager;

        // Some backends track the track manager activity even when not active
        // therefore they have to be notified.

        for (MapBackend* const backend : std::as_const(d->loadedBackends))
        {
            backend->slotTrackManagerChanged();
        }
    }

    void MapWidget::slotUngroupedModelChanged()
    {
        // determine the index under which we handle this model

        QObject* const senderObject                 = sender();
        const QAbstractItemModel* const senderModel = qobject_cast<QAbstractItemModel*>(senderObject);

        if (senderModel)
        {
            for (int i = 0 ; i < s->ungroupedModels.count() ; ++i)
            {
                if (s->ungroupedModels.at(i)->model() == senderModel)
                {
                    Q_EMIT signalUngroupedModelChanged(i);

                    break;
                }
            }
            return;
        }

        const GeoModelHelper* const senderHelper = qobject_cast<GeoModelHelper*>(senderObject);

        if (senderHelper)
        {
            for (int i = 0 ; i < s->ungroupedModels.count() ; ++i)
            {
                if (s->ungroupedModels.at(i) == senderHelper)
                {
                    Q_EMIT signalUngroupedModelChanged(i);

                    break;
                }
            }
        }

        const QItemSelectionModel* const senderSelectionModel = qobject_cast<QItemSelectionModel*>(senderObject);

        if (senderSelectionModel)
        {
            for (int i = 0 ; i < s->ungroupedModels.count() ; ++i)
            {
                if (s->ungroupedModels.at(i)->selectionModel() == senderSelectionModel)
                {
                    Q_EMIT signalUngroupedModelChanged(i);

                    break;
                }
            }

            return;
        }
    }

    } // namespace Digikam