1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKCOMBOBOX_P_H
5#define QQUICKCOMBOBOX_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qloggingcategory.h>
19#include <QtQmlModels/private/qtqmlmodels-config_p.h>
20#include <QtQuickTemplates2/private/qquickcontrol_p.h>
21
22QT_REQUIRE_CONFIG(qml_delegate_model);
23
24QT_BEGIN_NAMESPACE
25
26Q_DECLARE_LOGGING_CATEGORY(lcItemManagement)
27
28class QValidator;
29class QQuickPopup;
30class QQmlInstanceModel;
31class QQuickComboBoxPrivate;
32class QQmlComponent;
33
34class Q_QUICKTEMPLATES2_EXPORT QQuickComboBox : public QQuickControl
35{
36 Q_OBJECT
37 Q_PROPERTY(int count READ count NOTIFY countChanged FINAL)
38 Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged FINAL)
39 Q_PROPERTY(QQmlInstanceModel *delegateModel READ delegateModel NOTIFY delegateModelChanged FINAL)
40 Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL)
41 Q_PROPERTY(int highlightedIndex READ highlightedIndex NOTIFY highlightedIndexChanged FINAL)
42 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL)
43 Q_PROPERTY(QString currentText READ currentText NOTIFY currentTextChanged FINAL)
44 Q_PROPERTY(QString displayText READ displayText WRITE setDisplayText RESET resetDisplayText NOTIFY displayTextChanged FINAL)
45 Q_PROPERTY(QString textRole READ textRole WRITE setTextRole NOTIFY textRoleChanged FINAL)
46 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL)
47 Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL)
48 Q_PROPERTY(QQuickPopup *popup READ popup WRITE setPopup NOTIFY popupChanged FINAL)
49 // 2.1 (Qt 5.8)
50 Q_PROPERTY(bool flat READ isFlat WRITE setFlat NOTIFY flatChanged FINAL REVISION(2, 1))
51 // 2.2 (Qt 5.9)
52 Q_PROPERTY(bool down READ isDown WRITE setDown RESET resetDown NOTIFY downChanged FINAL REVISION(2, 2))
53 Q_PROPERTY(bool editable READ isEditable WRITE setEditable NOTIFY editableChanged FINAL REVISION(2, 2))
54 Q_PROPERTY(QString editText READ editText WRITE setEditText RESET resetEditText NOTIFY editTextChanged FINAL REVISION(2, 2))
55#if QT_CONFIG(validator)
56 Q_PROPERTY(QValidator *validator READ validator WRITE setValidator NOTIFY validatorChanged FINAL REVISION(2, 2))
57#endif
58 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged FINAL REVISION(2, 2))
59 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged FINAL REVISION(2, 2))
60 Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged FINAL REVISION(2, 2))
61 // 2.5 (Qt 5.12)
62 Q_PROPERTY(qreal implicitIndicatorWidth READ implicitIndicatorWidth NOTIFY implicitIndicatorWidthChanged FINAL REVISION(2, 5))
63 Q_PROPERTY(qreal implicitIndicatorHeight READ implicitIndicatorHeight NOTIFY implicitIndicatorHeightChanged FINAL REVISION(2, 5))
64 Q_CLASSINFO("DeferredPropertyNames", "background,contentItem,indicator,popup")
65 // 2.14 (Qt 5.14)
66 Q_PROPERTY(QVariant currentValue READ currentValue WRITE setCurrentValue NOTIFY currentValueChanged FINAL REVISION(2, 14))
67 Q_PROPERTY(QString valueRole READ valueRole WRITE setValueRole NOTIFY valueRoleChanged FINAL REVISION(2, 14))
68 // 2.15 (Qt 5.15)
69 Q_PROPERTY(bool selectTextByMouse READ selectTextByMouse WRITE setSelectTextByMouse NOTIFY selectTextByMouseChanged FINAL REVISION(2, 15))
70 // 6.0 (Qt 6.0)
71 Q_PROPERTY(ImplicitContentWidthPolicy implicitContentWidthPolicy READ implicitContentWidthPolicy
72 WRITE setImplicitContentWidthPolicy NOTIFY implicitContentWidthPolicyChanged FINAL REVISION(6, 0))
73 QML_NAMED_ELEMENT(ComboBox)
74 QML_ADDED_IN_VERSION(2, 0)
75
76public:
77 explicit QQuickComboBox(QQuickItem *parent = nullptr);
78 ~QQuickComboBox();
79
80 int count() const;
81
82 QVariant model() const;
83 void setModel(const QVariant &model);
84 QQmlInstanceModel *delegateModel() const;
85
86 bool isPressed() const;
87 void setPressed(bool pressed);
88
89 int highlightedIndex() const;
90
91 int currentIndex() const;
92 void setCurrentIndex(int index);
93
94 QString currentText() const;
95
96 QString displayText() const;
97 void setDisplayText(const QString &text);
98 void resetDisplayText();
99
100 QString textRole() const;
101 void setTextRole(const QString &role);
102
103 QString valueRole() const;
104 void setValueRole(const QString &role);
105
106 QQmlComponent *delegate() const;
107 void setDelegate(QQmlComponent *delegate);
108
109 QQuickItem *indicator() const;
110 void setIndicator(QQuickItem *indicator);
111
112 QQuickPopup *popup() const;
113 void setPopup(QQuickPopup *popup);
114
115 Q_INVOKABLE QString textAt(int index) const;
116 Q_INVOKABLE int find(const QString &text, Qt::MatchFlags flags = Qt::MatchExactly) const;
117
118 // 2.1 (Qt 5.8)
119 bool isFlat() const;
120 void setFlat(bool flat);
121
122 // 2.2 (Qt 5.9)
123 bool isDown() const;
124 void setDown(bool down);
125 void resetDown();
126
127 bool isEditable() const;
128 void setEditable(bool editable);
129
130 QString editText() const;
131 void setEditText(const QString &text);
132 void resetEditText();
133
134#if QT_CONFIG(validator)
135 QValidator *validator() const;
136 void setValidator(QValidator *validator);
137#endif
138
139 Qt::InputMethodHints inputMethodHints() const;
140 void setInputMethodHints(Qt::InputMethodHints hints);
141
142 bool isInputMethodComposing() const;
143 bool hasAcceptableInput() const;
144
145 // 2.5 (Qt 5.12)
146 qreal implicitIndicatorWidth() const;
147 qreal implicitIndicatorHeight() const;
148
149 // 2.14 (Qt 5.14)
150 QVariant currentValue() const;
151 Q_REVISION(6, 10) void setCurrentValue(const QVariant &value);
152 Q_REVISION(2, 14) Q_INVOKABLE QVariant valueAt(int index) const;
153 Q_REVISION(2, 14) Q_INVOKABLE int indexOfValue(const QVariant &value) const;
154
155 // 2.15 (Qt 5.15)
156 bool selectTextByMouse() const;
157 void setSelectTextByMouse(bool canSelect);
158
159 // 6.0 (Qt 6.0)
160 enum ImplicitContentWidthPolicy {
161 ContentItemImplicitWidth,
162 WidestText,
163 WidestTextWhenCompleted
164 };
165 Q_ENUM(ImplicitContentWidthPolicy)
166
167 ImplicitContentWidthPolicy implicitContentWidthPolicy() const;
168 void setImplicitContentWidthPolicy(ImplicitContentWidthPolicy policy);
169
170public Q_SLOTS:
171 void incrementCurrentIndex();
172 void decrementCurrentIndex();
173 Q_REVISION(2, 2) void selectAll();
174
175Q_SIGNALS:
176 void activated(int index);
177 void highlighted(int index);
178 void countChanged();
179 void modelChanged();
180 void delegateModelChanged();
181 void pressedChanged();
182 void highlightedIndexChanged();
183 void currentIndexChanged();
184 void currentTextChanged();
185 void displayTextChanged();
186 void textRoleChanged();
187 void delegateChanged();
188 void indicatorChanged();
189 void popupChanged();
190 // 2.1 (Qt 5.8)
191 Q_REVISION(2, 1) void flatChanged();
192 // 2.2 (Qt 5.9)
193 Q_REVISION(2, 2) void accepted();
194 Q_REVISION(2, 2) void downChanged();
195 Q_REVISION(2, 2) void editableChanged();
196 Q_REVISION(2, 2) void editTextChanged();
197#if QT_CONFIG(validator)
198 Q_REVISION(2, 2) void validatorChanged();
199#endif
200 Q_REVISION(2, 2) void inputMethodHintsChanged();
201 Q_REVISION(2, 2) void inputMethodComposingChanged();
202 Q_REVISION(2, 2) void acceptableInputChanged();
203 // 2.5 (Qt 5.12)
204 Q_REVISION(2, 5) void implicitIndicatorWidthChanged();
205 Q_REVISION(2, 5) void implicitIndicatorHeightChanged();
206 // 2.14 (Qt 5.14)
207 Q_REVISION(2, 14) void valueRoleChanged();
208 Q_REVISION(2, 14) void currentValueChanged();
209 // 2.15 (Qt 5.15)
210 Q_REVISION(2, 15) void selectTextByMouseChanged();
211 // 6.0 (Qt 6.0)
212 Q_REVISION(6, 0) void implicitContentWidthPolicyChanged();
213
214protected:
215 bool eventFilter(QObject *object, QEvent *event) override;
216 void focusInEvent(QFocusEvent *event) override;
217 void focusOutEvent(QFocusEvent *event) override;
218#if QT_CONFIG(im)
219 void inputMethodEvent(QInputMethodEvent *event) override;
220#endif
221 void keyPressEvent(QKeyEvent *event) override;
222 void keyReleaseEvent(QKeyEvent *event) override;
223#if QT_CONFIG(wheelevent)
224 void wheelEvent(QWheelEvent *event) override;
225#endif
226 bool event(QEvent *e) override;
227
228 void componentComplete() override;
229 void itemChange(ItemChange change, const ItemChangeData &value) override;
230 void fontChange(const QFont &newFont, const QFont &oldFont) override;
231 void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override;
232 void localeChange(const QLocale &newLocale, const QLocale &oldLocale) override;
233
234 QFont defaultFont() const override;
235
236#if QT_CONFIG(accessibility)
237 QAccessible::Role accessibleRole() const override;
238 void accessibilityActiveChanged(bool active) override;
239#endif
240
241private:
242 Q_DISABLE_COPY(QQuickComboBox)
243 Q_DECLARE_PRIVATE(QQuickComboBox)
244};
245
246QT_END_NAMESPACE
247
248#endif // QQUICKCOMBOBOX_P_H
249

source code of qtdeclarative/src/quicktemplates/qquickcombobox_p.h