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

# Cppcheck report - digiKam-nl-search-more-criteria-rev-e2466e0973: ../../core/app/filters/filtersidebarwidget_tags.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
    /* ============================================================
     *
     * This file is a part of digiKam project
     * https://www.digikam.org
     *
     * Date        : 2000-12-05
     * Description : filters view for the right sidebar
     *
     * SPDX-FileCopyrightText: 2009-2010 by Johannes Wienke <languitar at semipol dot de>
     * SPDX-FileCopyrightText: 2010-2011 by Andi Clemens <andi dot clemens at gmail dot com>
     * SPDX-FileCopyrightText: 2011-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
     * SPDX-FileCopyrightText:      2011 by Michael G. Hansen <mike at mghansen dot de>
     * SPDX-FileCopyrightText:      2014 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
     *
     * SPDX-License-Identifier: GPL-2.0-or-later
     *
     * ============================================================ */

    #include "filtersidebarwidget_p.h"

    namespace Digikam
    {

    void FilterSideBarWidget::populateTagsView()
    {
        QWidget* const box3   = new QWidget(d->tabWidget);
        d->tagFilterView      = new TagFilterView(box3, d->tagFilterModel);
        d->tagFilterView->setObjectName(QLatin1String("ItemIconViewTagFilterView"));

        d->tagFilterSearchBar = new SearchTextBarDb(box3, QLatin1String("ItemIconViewTagFilterSearchBar"));
        d->tagFilterSearchBar->setModel(d->tagFilterView->filteredModel(),
                                        AbstractAlbumModel::AlbumIdRole, AbstractAlbumModel::AlbumTitleRole);
        d->tagFilterSearchBar->setFilterModel(d->tagFilterView->albumFilterModel());

        const QString notTaggedTitle = i18n("Images Without Tags");
        d->withoutTagCheckBox        = new QCheckBox(notTaggedTitle, box3);
        d->withoutTagCheckBox->setWhatsThis(i18n("Show images without a tag."));

        d->tagOptionsBtn = new QToolButton(box3);
        d->tagOptionsBtn->setToolTip(i18n("Tags Matching Condition"));
        d->tagOptionsBtn->setIcon(QIcon::fromTheme(QLatin1String("configure")));
        d->tagOptionsBtn->setPopupMode(QToolButton::InstantPopup);
        d->tagOptionsBtn->setWhatsThis(i18n("Defines in which way the selected tags are combined "
                                            "to filter the images. This also includes the '%1' check box.",
                                            notTaggedTitle));

        d->tagOptionsMenu                = new QMenu(d->tagOptionsBtn);
        QActionGroup* const tagCondGroup = new QActionGroup(d->tagOptionsMenu);
        tagCondGroup->setExclusive(true);
        d->tagOrCondAction  = d->tagOptionsMenu->addAction(i18n("OR"));
        d->tagOrCondAction->setActionGroup(tagCondGroup);
        d->tagOrCondAction->setCheckable(true);
        d->tagAndCondAction = d->tagOptionsMenu->addAction(i18n("AND"));
        d->tagAndCondAction->setActionGroup(tagCondGroup);
        d->tagAndCondAction->setCheckable(true);
        d->tagOptionsBtn->setMenu(d->tagOptionsMenu);

        QGridLayout* const lay3 = new QGridLayout(box3);
        lay3->addWidget(d->tagFilterView,      0, 0, 1, 3);
        lay3->addWidget(d->tagFilterSearchBar, 1, 0, 1, 3);
        lay3->addWidget(d->withoutTagCheckBox, 2, 0, 1, 1);
        lay3->addWidget(d->tagOptionsBtn,      2, 2, 1, 1);
        lay3->setRowStretch(0, 100);
        lay3->setColumnStretch(1, 10);
        lay3->setContentsMargins(QMargins());
        lay3->setSpacing(0);

        d->tabWidget->insertTab(Private::TagsTab, box3, i18nc("@title", "Tags"));

        // ---

        connect(d->tagFilterView, SIGNAL(checkedTagsChanged(QList<TAlbum*>,QList<TAlbum*>)),
                this, SLOT(slotCheckedTagsChanged(QList<TAlbum*>,QList<TAlbum*>)));

        connect(d->withoutTagCheckBox, SIGNAL(stateChanged(int)),
                this, SLOT(slotWithoutTagChanged(int)));

        connect(d->tagOptionsMenu, SIGNAL(aboutToShow()),
                this, SLOT(slotTagOptionsMenu()));

        connect(d->tagOptionsMenu, SIGNAL(triggered(QAction*)),
                this, SLOT(slotTagOptionsTriggered(QAction*)));
    }

    void FilterSideBarWidget::slotTagOptionsMenu()
    {
        d->tagOrCondAction->setChecked(false);
        d->tagAndCondAction->setChecked(false);

        switch (d->tagMatchCond)
        {
            case ItemFilterSettings::OrCondition:
            {
                d->tagOrCondAction->setChecked(true);
                break;
            }

            case ItemFilterSettings::AndCondition:
            {
                d->tagAndCondAction->setChecked(true);
                break;
            }
        }
    }

    void FilterSideBarWidget::slotTagOptionsTriggered(QAction* action)<--- Either there is a missing override/final keyword, or the parameter 'action' can be declared as pointer to const
    {
        if (action)
        {
            if      (action == d->tagOrCondAction)
            {
                d->tagMatchCond = ItemFilterSettings::OrCondition;
            }
            else if (action == d->tagAndCondAction)
            {
                d->tagMatchCond = ItemFilterSettings::AndCondition;
            }
        }

        checkFilterChanges();
    }

    void FilterSideBarWidget::slotCheckedTagsChanged(const QList<TAlbum*>& includedTags,
                                                     const QList<TAlbum*>& excludedTags)
    {
        Q_UNUSED(includedTags);
        Q_UNUSED(excludedTags);

        checkFilterChanges();
    }

    void FilterSideBarWidget::slotWithoutTagChanged(int newState)
    {
        Q_UNUSED(newState);

        checkFilterChanges();
    }

    } // namespace Digikam