Libkdepim

kcheckcombobox.h
1/*
2 This file is part of libkdepim.
3
4 SPDX-FileCopyrightText: 2008 Thomas Thrainer <tom_t@gmx.at>
5 SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
8
9*/
10
11#pragma once
12
13#include "kdepim_export.h"
14
15#include <QComboBox>
16#include <QModelIndex>
17
18namespace KPIM
19{
20/**
21 * A combobox that shows its items in such a way that they can be checked in the
22 * drop menu. It provides methods to set the default text when no items are selected
23 * and the separator that is used to show the items that are selected in the line
24 * edit.
25 */
26class KDEPIM_EXPORT KCheckComboBox : public QComboBox
27{
28 Q_OBJECT
29
30 Q_PROPERTY(QString separator READ separator WRITE setSeparator)
31 Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
32 Q_PROPERTY(bool squeezeText READ squeezeText WRITE setSqueezeText)
33 Q_PROPERTY(QStringList checkedItems READ checkedItems WRITE setCheckedItems)
34
35public:
36 /**
37 * Creates a new checkable combobox.
38 *
39 * @param parent The parent widget.
40 */
41 explicit KCheckComboBox(QWidget *parent = nullptr);
42
43 /**
44 * Destroys the time zone combobox.
45 */
46 ~KCheckComboBox() override;
47
48 /**
49 * Hides the popup list if it is currently shown.
50 */
51 void hidePopup() override;
52
53 /**
54 * Returns the default text that is shown when no items are selected.
55 */
56 [[nodiscard]] QString defaultText() const;
57
58 /**
59 * Sets the default text that is shown when no items are selected.
60 *
61 * @param text The new default text
62 */
63 void setDefaultText(const QString &text);
64
65 /**
66 * Returns whether the default text is always shown, even if there are
67 * no checked items.
68 */
69 [[nodiscard]] bool alwaysShowDefaultText() const;
70
71 /**
72 * Sets if the default text should always be shown even if there are
73 * no checked items.
74 *
75 * Default is false.
76 */
77 void setAlwaysShowDefaultText(bool always);
78
79 /**
80 * Returns whether or not the text will be squeezed to fit in the combo's line
81 * edit. This property is false by default.
82 *
83 * @see KSqueezedTextLabel
84 */
85 [[nodiscard]] bool squeezeText() const;
86
87 /**
88 * Sets whether or not the text must be squeezed.
89 *
90 * @param squeeze The new squeeze status
91 */
92 void setSqueezeText(bool squeeze);
93
94 /**
95 * Return whether or not the item at @param index is enabled, i.e. if the
96 * user can (un)check the item.
97 */
98 [[nodiscard]] bool itemEnabled(int index);
99
100 /**
101 * Set the item at @param index to @param enabled, i.e. if the
102 * user can (un)check the item.
103 */
104 void setItemEnabled(int index, bool enabled = true);
105
106 /**
107 * Returns the check state of item at given index.
108 *
109 * @param index The index for which to return the check state.
110 */
111 [[nodiscard]] Qt::CheckState itemCheckState(int index) const;
112
113 /**
114 * Changes the check state of the given index to the given state.
115 *
116 * @param index The index of which the state needs to be changed
117 * @param state The new state
118 */
119 void setItemCheckState(int index, Qt::CheckState state);
120
121 /**
122 * Returns the current separator used to separate the selected items in the
123 * line edit of the combo box.
124 */
125 [[nodiscard]] QString separator() const;
126
127 /**
128 * Sets the separator used to separate items in the line edit.
129 *
130 * @param separator The new separator
131 */
132 void setSeparator(const QString &separator);
133
134 /**
135 * Returns The currently selected items.
136 * @param role The role the returned values belong to.
137 */
138 [[nodiscard]] QStringList checkedItems(int role = Qt::DisplayRole) const;
139
140public Q_SLOTS:
141 /**
142 * Sets the currently selected items. Items that are not found in the model
143 * are silently ignored.
144 *
145 * @param items The items that will be set to checked.
146 * @param role The role @p items belong to.
147 */
148 void setCheckedItems(const QStringList &items, int role = Qt::DisplayRole);
149
150Q_SIGNALS:
151 /**
152 * Signal to notify listeners that the current selections has changed.
153 *
154 * @param items The new selection.
155 */
157
158protected:
159 bool eventFilter(QObject *receiver, QEvent *event) override;
160 void keyPressEvent(QKeyEvent *event) override;
161 void resizeEvent(QResizeEvent *event) override;
162#ifndef QT_NO_WHEELEVENT
163 void wheelEvent(QWheelEvent *event) override;
164#endif
165
166private:
167 //@cond PRIVATE
168 class KCheckComboBoxPrivate;
169 std::unique_ptr<KCheckComboBoxPrivate> const d;
170 //@endcond
171};
172}
A combobox that shows its items in such a way that they can be checked in the drop menu.
~KCheckComboBox() override
Destroys the time zone combobox.
void checkedItemsChanged(const QStringList &items)
Signal to notify listeners that the current selections has changed.
Class KCheckComboBox::KCheckComboBoxPrivate.
CheckState
DisplayRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.