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

# Cppcheck report - digiKam-master-rev-70b072e127: ../../core/app/date/datefolderview.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
    /* ============================================================
     *
     * This file is a part of digiKam project
     * https://www.digikam.org
     *
     * Date        : 2005-04-27
     * Description : a folder view for date albums.
     *
     * SPDX-FileCopyrightText: 2005      by Renchi Raju <renchi dot raju at gmail dot com>
     * SPDX-FileCopyrightText: 2006-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
     * SPDX-FileCopyrightText: 2009-2010 by Johannes Wienke <languitar at semipol dot de>
     * SPDX-FileCopyrightText: 2014      by Michael G. Hansen <mike at mghansen dot de>
     *
     * SPDX-License-Identifier: GPL-2.0-or-later
     *
     * ============================================================ */

    #include "datefolderview.h"

    // KDE includes

    #include <kconfiggroup.h>

    // Local includes

    #include "digikam_debug.h"
    #include "album.h"
    #include "coredb.h"
    #include "applicationsettings.h"
    #include "datetreeview.h"
    #include "monthwidget.h"

    namespace Digikam
    {

    class Q_DECL_HIDDEN DateFolderView::Private
    {
    public:

        Private() = default;

    public:

        bool          active        = false;

        DateTreeView* dateTreeView  = nullptr;
        MonthWidget*  monthview     = nullptr;
    };

    DateFolderView::DateFolderView(QWidget* const parent, DateAlbumModel* const dateAlbumModel)
        : DVBox            (parent),
          StateSavingObject(this),
          d                (new Private)
    {
        setObjectName(QLatin1String("DateFolderView"));

        d->dateTreeView = new DateTreeView(this);
        d->dateTreeView->setDAlbumModel(dateAlbumModel);
        d->dateTreeView->setAlbumManagerCurrentAlbum(true);
        d->monthview    = new MonthWidget(this);

        connect(d->dateTreeView, SIGNAL(currentAlbumChanged(Album*)),
                this, SLOT(slotSelectionChanged(Album*)));

        // Loading of DAlbums may take longer that setting up the gui. Therefore
        // the first call to setActive may not set the current album in the album
        // manager as it is not yet loaded. To achieve this, we wait for loading
        // DAlbums and set the active album in the album manager if this tab is
        // active

        connect(AlbumManager::instance(), SIGNAL(signalAllDAlbumsLoaded()),
                this, SLOT(slotAllAlbumsLoaded()));
    }

    DateFolderView::~DateFolderView()
    {
        saveState();
    }

    void DateFolderView::setItemModel(ItemFilterModel* const model)
    {
        d->monthview->setItemModel(model);
    }

    void DateFolderView::setActive(const bool val)
    {
        if (d->active == val)
        {
            return;
        }

        d->active = val;

        if (d->active)
        {
            AlbumManager::instance()->setCurrentAlbums(QList<Album*>()
                                                       << d->dateTreeView->currentAlbum());
            slotSelectionChanged(d->dateTreeView->currentAlbum());
        }
        else
        {
            d->monthview->setActive(false);
        }
    }

    void DateFolderView::slotSelectionChanged(Album* selectedAlbum)
    {
        if (!d->active)
        {
            qCDebug(DIGIKAM_GENERAL_LOG) << "Not active, returning without action";
            return;
        }

        d->monthview->setActive(false);

        DAlbum* const dalbum = dynamic_cast<DAlbum*> (selectedAlbum);       // cppcheck-suppress constVariablePointer

        if (!dalbum)
        {
            return;
        }

        if (dalbum->range() == DAlbum::Month)
        {
            QDate date = dalbum->date();
            d->monthview->setActive(true);
            d->monthview->setYearMonth(date.year(), date.month());
        }

        if (d->active)
        {
            AlbumManager::instance()->setCurrentAlbums(QList<Album*>() << dalbum);
        }
    }

    void DateFolderView::slotAllAlbumsLoaded()
    {
        if (d->active)
        {
            QList<Album*> albums({d->dateTreeView->currentAlbum()});

            if (AlbumManager::instance()->currentAlbums() != albums)
            {
                AlbumManager::instance()->setCurrentAlbums(albums);
                slotSelectionChanged(d->dateTreeView->currentAlbum());
            }
        }

        // Workaround for bug 447874

        d->dateTreeView->setSortingEnabled(true);
    }

    void DateFolderView::setConfigGroup(const KConfigGroup& group)
    {
        StateSavingObject::setConfigGroup(group);
        d->dateTreeView->setConfigGroup(group);
    }

    void DateFolderView::doLoadState()
    {
        d->dateTreeView->loadState();
    }

    void DateFolderView::doSaveState()
    {
        d->dateTreeView->saveState();
    }

    void DateFolderView::gotoDate(const QDate& dt)
    {
        qCDebug(DIGIKAM_GENERAL_LOG) << "Going to date " << dt;

        QModelIndex dateIndex = d->dateTreeView->dalbumModel()->monthIndexForDate(dt);

        if (!dateIndex.isValid())
        {
            qCDebug(DIGIKAM_GENERAL_LOG) << "Cannot find an album for date " << dt;

            return;
        }

        DAlbum* const dateAlbum = d->dateTreeView->dalbumModel()->dalbumForIndex(dateIndex);    // cppcheck-suppress constVariablePointer

        if (!dateAlbum)
        {
            qCWarning(DIGIKAM_GENERAL_LOG) << "Could not retrieve an album for index " << dateIndex;

            return;
        }

        qCDebug(DIGIKAM_GENERAL_LOG) << "Got date album " << dateAlbum;

        d->dateTreeView->setCurrentAlbums(QList<Album*>() << dateAlbum);
    }

    void DateFolderView::changeAlbumFromHistory(DAlbum* const album)<--- Either there is a missing override/final keyword, or the parameter 'album' can be declared as pointer to const
    {
        d->dateTreeView->setCurrentAlbums(QList<Album*>() << album);
    }

    AlbumPointer<DAlbum> DateFolderView::currentAlbum() const
    {
        return AlbumPointer<DAlbum>(d->dateTreeView->currentAlbum());
    }

    } // namespace Digikam

    #include "moc_datefolderview.cpp"