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
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2009-05-09
 * Description : A combo box for selecting albums
 *
 * SPDX-FileCopyrightText: 2008-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
 * SPDX-FileCopyrightText: 2010-2011 by Andi Clemens <andi dot clemens at gmail dot com>
 * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#ifndef DIGIKAM_ALBUM_SELECT_COMBO_BOX_H
#define DIGIKAM_ALBUM_SELECT_COMBO_BOX_H

// Local includes

#include "comboboxutilities.h"

class QSortFilterProxyModel;

namespace Digikam
{

class AlbumFilterModel;
class AbstractCheckableAlbumModel;

class AlbumSelectComboBox : public TreeViewLineEditComboBox
{
    Q_OBJECT

public:

    explicit AlbumSelectComboBox(QWidget* const parent = nullptr);
    ~AlbumSelectComboBox()                              override;

    /**
     * Once after creation, call one of these three methods.
     * Use the first one if you want a standard combo box for PAlbums and
     *  the second one for tags, while the third allows you to provide
     *  custom source and filter models.
     *  The first two also set a default noSelectionText. Customize afterwards if required.
     */
    void setDefaultAlbumModel();
    void setDefaultTagModel();
    void setAlbumModels(AbstractCheckableAlbumModel* model,
                        AlbumFilterModel* filterModel = nullptr);

    /**
     * Enable checkboxes next to the items. Default: true
     */
    void setCheckable(bool checkable);
    bool isCheckable() const;

    /**
     * Enable closing when an item was activated (clicked). Default: false.
     */
    void setCloseOnActivate(bool close);

    /**
     * If the box is checkable, enable showing a resume a la "3 Albums checked"
     * in the combo box text. Default: True
     */
    void setShowCheckStateSummary(bool show);

    /**
     * If all subalbums shall be selected when parent will be selected
     */
    void setRecursive(bool recursive);

    /**
     * Sets the text that is used to describe the state when no album is selected.
     * This may be something like "Any album" or "No tag selected".
     * Depends on the default line edit implementation of TreeViewLineEditComboBox.
     */
    void setNoSelectionText(const QString& text);

    /**
     * Enable or disable the text used to describe the status when all album is selected.
     */
    void setAllSelectedText(bool all);

    /**
     * Returns the source model. Retrieve selection information from here.
     */
    AbstractCheckableAlbumModel* model() const;

    /**
     * Return the filter model in use.
     */
    QSortFilterProxyModel* filterModel() const;

public Q_SLOTS:

    void hidePopup()                                    override;

    /**
     * Updates the text describing the selection ("3 Albums selected").
     * Can be overridden to customize the default text.
     */
    virtual void updateText();

protected:

    void installView(QAbstractItemView* view = nullptr) override;

private:

    class Private;
    Private* const d = nullptr;
};

// ------------------------------------------------------------------------------------

class AbstractAlbumTreeView;
class AlbumModel;
class AlbumTreeView;
class CheckableAlbumFilterModel;
class TagPropertiesFilterModel;
class TagModel;
class TagTreeView;

class AbstractAlbumTreeViewSelectComboBox : public AlbumSelectComboBox
{
    Q_OBJECT

public:

    /**
     * Abstract class.
     * This is an AlbumSelectComboBox which installs an AlbumTreeView,
     * not a plain QTreeView, as view.
     */

    explicit AbstractAlbumTreeViewSelectComboBox(QWidget* const parent = nullptr);

    /**
     * Set a tree view created by you instead of creating a default view
     * (in the subclasses).
     * Only takes effect before calling setModel.
     */
    void setTreeView(AbstractAlbumTreeView* const treeView);

    /**
     * Enables a context menu which contains options to
     * check or uncheck groups of albums, given you have a checkable model.
     * Call this method after setModel().
     */
    void addCheckUncheckContextMenuActions();

protected:

    void installView(QAbstractItemView* view = nullptr) override;
    void sendViewportEventToView(QEvent* e)             override;

protected:

    AbstractAlbumTreeView* m_treeView = nullptr;
};

// ------------------------------------------------------------------------------------

class AlbumTreeViewSelectComboBox : public AbstractAlbumTreeViewSelectComboBox
{
    Q_OBJECT

public:

    explicit AlbumTreeViewSelectComboBox(QWidget* const parent = nullptr);

    void setDefaultModel();
    void setAlbumModels(AlbumModel* model,
                        CheckableAlbumFilterModel* filterModel = nullptr);
    AlbumTreeView* view() const;<--- Derived function 'AlbumTreeViewSelectComboBox::view'
};

// ------------------------------------------------------------------------------------

class TagTreeViewSelectComboBox : public AbstractAlbumTreeViewSelectComboBox
{
    Q_OBJECT

public:

    explicit TagTreeViewSelectComboBox(QWidget* const parent = nullptr);

    void setDefaultModel();
    void setAlbumModels(TagModel* model,
                        TagPropertiesFilterModel* filteredModel = nullptr,
                        CheckableAlbumFilterModel* filterModel = nullptr);
    TagTreeView* view() const;<--- Derived function 'TagTreeViewSelectComboBox::view'
};

} // namespace Digikam

#endif // DIGIKAM_ALBUM_SELECT_COMBO_BOX_H