Debian Codegraph @

core/libs/album/widgets/albumselectcombobox.h

raw
1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2009-05-09
7 * Description : A combo box for selecting albums
8 *
9 * SPDX-FileCopyrightText: 2008-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10 * SPDX-FileCopyrightText: 2010-2011 by Andi Clemens <andi dot clemens at gmail dot com>
11 * SPDX-FileCopyrightText: 2012-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
12 *
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 *
15 * ============================================================ */
16
17 #pragma once
18
19 // Local includes
20
21 #include "comboboxutilities.h"
22
23 class QSortFilterProxyModel;
24
25 namespace Digikam
26 {
27
28 class AlbumFilterModel;
29 class AbstractCheckableAlbumModel;
30
31 class AlbumSelectComboBox : public TreeViewLineEditComboBox
32 {
33 Q_OBJECT
34
35 public:
36
37 explicit AlbumSelectComboBox(QWidget* const parent = nullptr);
38 ~AlbumSelectComboBox() override;
39
40 /**
41 * Once after creation, call one of these three methods.
42 * Use the first one if you want a standard combo box for PAlbums and
43 * the second one for tags, while the third allows you to provide
44 * custom source and filter models.
45 * The first two also set a default noSelectionText. Customize afterwards if required.
46 */
47 void setDefaultAlbumModel();
48 void setDefaultTagModel();
49 void setAlbumModels(AbstractCheckableAlbumModel* model,
50 AlbumFilterModel* filterModel = nullptr);
51
52 /**
53 * Enable checkboxes next to the items. Default: true
54 */
55 void setCheckable(bool checkable);
56 bool isCheckable() const;
57
58 /**
59 * Enable closing when an item was activated (clicked). Default: false.
60 */
61 void setCloseOnActivate(bool close);
62
63 /**
64 * If the box is checkable, enable showing a resume a la "3 Albums checked"
65 * in the combo box text. Default: True
66 */
67 void setShowCheckStateSummary(bool show);
68
69 /**
70 * If all subalbums shall be selected when parent will be selected
71 */
72 void setRecursive(bool recursive);
73
74 /**
75 * Sets the text that is used to describe the state when no album is selected.
76 * This may be something like "Any album" or "No tag selected".
77 * Depends on the default line edit implementation of TreeViewLineEditComboBox.
78 */
79 void setNoSelectionText(const QString& text);
80
81 /**
82 * Enable or disable the text used to describe the status when all album is selected.
83 */
84 void setAllSelectedText(bool all);
85
86 /**
87 * Returns the source model. Retrieve selection information from here.
88 */
89 AbstractCheckableAlbumModel* model() const;
90
91 /**
92 * Return the filter model in use.
93 */
94 QSortFilterProxyModel* filterModel() const;
95
96 public Q_SLOTS:
97
98 void hidePopup() override;
99
100 /**
101 * Updates the text describing the selection ("3 Albums selected").
102 * Can be overridden to customize the default text.
103 */
104 virtual void updateText();
105
106 protected:
107
108 void installView(QAbstractItemView* view = nullptr) override;
109
110 private:
111
112 class Private;
113 Private* const d = nullptr;
114 };
115
116 // ------------------------------------------------------------------------------------
117
118 class AbstractAlbumTreeView;
119 class AlbumModel;
120 class AlbumTreeView;
121 class CheckableAlbumFilterModel;
122 class TagPropertiesFilterModel;
123 class TagModel;
124 class TagTreeView;
125
126 class AbstractAlbumTreeViewSelectComboBox : public AlbumSelectComboBox
127 {
128 Q_OBJECT
129
130 public:
131
132 /**
133 * @brief Abstract class.
134 * This is an AlbumSelectComboBox which installs an AlbumTreeView,
135 * not a plain QTreeView, as view.
136 */
137
138 explicit AbstractAlbumTreeViewSelectComboBox(QWidget* const parent = nullptr);
139
140 /**
141 * @brief Set a tree view created by you instead of creating a default view
142 * (in the subclasses).
143 * Only takes effect before calling setModel.
144 */
145 void setTreeView(AbstractAlbumTreeView* const treeView);
146
147 /**
148 * @brief Enables a context menu which contains options to
149 * check or uncheck groups of albums, given you have a checkable model.
150 * Call this method after setModel().
151 */
152 void addCheckUncheckContextMenuActions();
153
154 protected:
155
156 void installView(QAbstractItemView* view = nullptr) override;
157 void sendViewportEventToView(QEvent* e) override;
158
159 protected:
160
161 AbstractAlbumTreeView* m_treeView = nullptr;
162 };
163
164 // ------------------------------------------------------------------------------------
165
166 class AlbumTreeViewSelectComboBox : public AbstractAlbumTreeViewSelectComboBox
167 {
168 Q_OBJECT
169
170 public:
171
172 explicit AlbumTreeViewSelectComboBox(QWidget* const parent = nullptr);
173
174 void setDefaultModel();
175 void setAlbumModels(AlbumModel* model,
176 CheckableAlbumFilterModel* filterModel = nullptr);
177 AlbumTreeView* treeView() const;
178
179 private:
180
181 /**
182 * @brief Disabled TreeViewComboBox::view(). Use treeView() method instead.
183 * @see treeView().
184 */
185 using TreeViewComboBox::view;
186 };
187
188 // ------------------------------------------------------------------------------------
189
190 class TagTreeViewSelectComboBox : public AbstractAlbumTreeViewSelectComboBox
191 {
192 Q_OBJECT
193
194 public:
195
196 explicit TagTreeViewSelectComboBox(QWidget* const parent = nullptr);
197
198 void setDefaultModel();
199 virtual void setAlbumModels(TagModel* model,
200 TagPropertiesFilterModel* filteredModel = nullptr,
201 CheckableAlbumFilterModel* filterModel = nullptr);
202 TagTreeView* treeView() const;
203
204 private:
205
206 /**
207 * @brief Disabled TreeViewComboBox::view(). Use treeView() method instead.
208 * @see treeView().
209 */
210 using TreeViewComboBox::view;
211 };
212
213 } // namespace Digikam