Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickcombobox_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKCOMBOBOX_P_H
6#define QQUICKCOMBOBOX_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/qloggingcategory.h>
20#include <QtQmlModels/private/qtqmlmodels-config_p.h>
21#include <QtQuickTemplates2/private/qquickcontrol_p.h>
22#include <QtQuick/private/qquicktext_p.h>
23
25
27
29
30class QValidator;
31class QQuickPopup;
32class QQmlInstanceModel;
34class QQmlComponent;
35
36class Q_QUICKTEMPLATES2_EXPORT QQuickComboBox : public QQuickControl
37{
38 Q_OBJECT
39 Q_PROPERTY(int count READ count NOTIFY countChanged FINAL)
40 Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged FINAL)
41 Q_PROPERTY(QQmlInstanceModel *delegateModel READ delegateModel NOTIFY delegateModelChanged FINAL)
42 Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL)
43 Q_PROPERTY(int highlightedIndex READ highlightedIndex NOTIFY highlightedIndexChanged FINAL)
44 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL)
45 Q_PROPERTY(QString currentText READ currentText NOTIFY currentTextChanged FINAL)
46 Q_PROPERTY(QString displayText READ displayText WRITE setDisplayText RESET resetDisplayText NOTIFY displayTextChanged FINAL)
47 Q_PROPERTY(QString textRole READ textRole WRITE setTextRole NOTIFY textRoleChanged FINAL)
48 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL)
49 Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL)
50 Q_PROPERTY(QQuickPopup *popup READ popup WRITE setPopup NOTIFY popupChanged FINAL)
51 // 2.1 (Qt 5.8)
52 Q_PROPERTY(bool flat READ isFlat WRITE setFlat NOTIFY flatChanged FINAL REVISION(2, 1))
53 // 2.2 (Qt 5.9)
54 Q_PROPERTY(bool down READ isDown WRITE setDown RESET resetDown NOTIFY downChanged FINAL REVISION(2, 2))
55 Q_PROPERTY(bool editable READ isEditable WRITE setEditable NOTIFY editableChanged FINAL REVISION(2, 2))
56 Q_PROPERTY(QString editText READ editText WRITE setEditText RESET resetEditText NOTIFY editTextChanged FINAL REVISION(2, 2))
57#if QT_CONFIG(validator)
58 Q_PROPERTY(QValidator *validator READ validator WRITE setValidator NOTIFY validatorChanged FINAL REVISION(2, 2))
59#endif
60 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged FINAL REVISION(2, 2))
61 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged FINAL REVISION(2, 2))
62 Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged FINAL REVISION(2, 2))
63 // 2.5 (Qt 5.12)
64 Q_PROPERTY(qreal implicitIndicatorWidth READ implicitIndicatorWidth NOTIFY implicitIndicatorWidthChanged FINAL REVISION(2, 5))
65 Q_PROPERTY(qreal implicitIndicatorHeight READ implicitIndicatorHeight NOTIFY implicitIndicatorHeightChanged FINAL REVISION(2, 5))
66 Q_CLASSINFO("DeferredPropertyNames", "background,contentItem,indicator,popup")
67 // 2.14 (Qt 5.14)
68 Q_PROPERTY(QVariant currentValue READ currentValue WRITE setCurrentValue NOTIFY currentValueChanged FINAL REVISION(2, 14))
69 Q_PROPERTY(QString valueRole READ valueRole WRITE setValueRole NOTIFY valueRoleChanged FINAL REVISION(2, 14))
70 // 2.15 (Qt 5.15)
71 Q_PROPERTY(bool selectTextByMouse READ selectTextByMouse WRITE setSelectTextByMouse NOTIFY selectTextByMouseChanged FINAL REVISION(2, 15))
72 // 6.0 (Qt 6.0)
73 Q_PROPERTY(ImplicitContentWidthPolicy implicitContentWidthPolicy READ implicitContentWidthPolicy
74 WRITE setImplicitContentWidthPolicy NOTIFY implicitContentWidthPolicyChanged FINAL REVISION(6, 0))
75 // 6.12 (Qt 6.12)
76 Q_PROPERTY(bool highlightOnHover READ highlightOnHover WRITE setHighlightOnHover NOTIFY highlightOnHoverChanged REVISION(6, 12))
77 // 6.13 (Qt 6.13)
78 Q_PROPERTY(QQuickText::TextFormat textFormat READ textFormat WRITE setTextFormat RESET resetTextFormat NOTIFY textFormatChanged REVISION(6, 13))
79 QML_NAMED_ELEMENT(ComboBox)
80 QML_ADDED_IN_VERSION(2, 0)
81
82public:
83 explicit QQuickComboBox(QQuickItem *parent = nullptr);
84 ~QQuickComboBox();
85
86 int count() const;
87
88 QVariant model() const;
89 void setModel(const QVariant &model);
90 QQmlInstanceModel *delegateModel() const;
91
92 bool isPressed() const;
93 void setPressed(bool pressed);
94
95 int highlightedIndex() const;
96
97 int currentIndex() const;
98 void setCurrentIndex(int index);
99
100 QString currentText() const;
101
102 QString displayText() const;
103 void setDisplayText(const QString &text);
104 void resetDisplayText();
105
106 QString textRole() const;
107 void setTextRole(const QString &role);
108
109 QString valueRole() const;
110 void setValueRole(const QString &role);
111
112 QQuickText::TextFormat textFormat() const;
113 void setTextFormat(QQuickText::TextFormat textFormat);
114 void resetTextFormat();
115
116 QQmlComponent *delegate() const;
117 void setDelegate(QQmlComponent *delegate);
118
119 QQuickItem *indicator() const;
120 void setIndicator(QQuickItem *indicator);
121
122 QQuickPopup *popup() const;
123 void setPopup(QQuickPopup *popup);
124
125 Q_INVOKABLE QString textAt(int index) const;
126 Q_INVOKABLE int find(const QString &text, Qt::MatchFlags flags = Qt::MatchExactly) const;
127
128 // 2.1 (Qt 5.8)
129 bool isFlat() const;
130 void setFlat(bool flat);
131
132 // 2.2 (Qt 5.9)
133 bool isDown() const;
134 void setDown(bool down);
135 void resetDown();
136
137 bool isEditable() const;
138 void setEditable(bool editable);
139
140 QString editText() const;
141 void setEditText(const QString &text);
142 void resetEditText();
143
144#if QT_CONFIG(validator)
145 QValidator *validator() const;
146 void setValidator(QValidator *validator);
147#endif
148
149 Qt::InputMethodHints inputMethodHints() const;
150 void setInputMethodHints(Qt::InputMethodHints hints);
151
152 bool isInputMethodComposing() const;
153 bool hasAcceptableInput() const;
154
155 // 2.5 (Qt 5.12)
156 qreal implicitIndicatorWidth() const;
157 qreal implicitIndicatorHeight() const;
158
159 // 2.14 (Qt 5.14)
160 QVariant currentValue() const;
161 Q_REVISION(6, 10) void setCurrentValue(const QVariant &value);
162 Q_REVISION(2, 14) Q_INVOKABLE QVariant valueAt(int index) const;
163 Q_REVISION(2, 14) Q_INVOKABLE int indexOfValue(const QVariant &value) const;
164
165 // 2.15 (Qt 5.15)
166 bool selectTextByMouse() const;
167 void setSelectTextByMouse(bool canSelect);
168
169 // 6.0 (Qt 6.0)
170 enum ImplicitContentWidthPolicy {
171 ContentItemImplicitWidth,
172 WidestText,
173 WidestTextWhenCompleted
174 };
175 Q_ENUM(ImplicitContentWidthPolicy)
176
177 ImplicitContentWidthPolicy implicitContentWidthPolicy() const;
178 void setImplicitContentWidthPolicy(ImplicitContentWidthPolicy policy);
179
180 // 6.12
181 bool highlightOnHover() const;
182 void setHighlightOnHover(bool value);
183
184public Q_SLOTS:
185 void incrementCurrentIndex();
186 void decrementCurrentIndex();
187 Q_REVISION(2, 2) void selectAll();
188
189Q_SIGNALS:
190 void activated(int index);
191 void highlighted(int index);
192 void countChanged();
193 void modelChanged();
194 void delegateModelChanged();
195 void pressedChanged();
196 void highlightedIndexChanged();
197 void currentIndexChanged();
198 void currentTextChanged();
199 void displayTextChanged();
200 void textRoleChanged();
201 void delegateChanged();
202 void indicatorChanged();
203 void popupChanged();
204 // 2.1 (Qt 5.8)
205 Q_REVISION(2, 1) void flatChanged();
206 // 2.2 (Qt 5.9)
207 Q_REVISION(2, 2) void accepted();
208 Q_REVISION(2, 2) void downChanged();
209 Q_REVISION(2, 2) void editableChanged();
210 Q_REVISION(2, 2) void editTextChanged();
211#if QT_CONFIG(validator)
212 Q_REVISION(2, 2) void validatorChanged();
213#endif
214 Q_REVISION(2, 2) void inputMethodHintsChanged();
215 Q_REVISION(2, 2) void inputMethodComposingChanged();
216 Q_REVISION(2, 2) void acceptableInputChanged();
217 // 2.5 (Qt 5.12)
218 Q_REVISION(2, 5) void implicitIndicatorWidthChanged();
219 Q_REVISION(2, 5) void implicitIndicatorHeightChanged();
220 // 2.14 (Qt 5.14)
221 Q_REVISION(2, 14) void valueRoleChanged();
222 Q_REVISION(2, 14) void currentValueChanged();
223 // 2.15 (Qt 5.15)
224 Q_REVISION(2, 15) void selectTextByMouseChanged();
225 // 6.0 (Qt 6.0)
226 Q_REVISION(6, 0) void implicitContentWidthPolicyChanged();
227 // 6.12 (Qt 6.12)
228 Q_REVISION(6, 12) void highlightOnHoverChanged();
229 // 6.13 (Qt 6.13)
230 Q_REVISION(6, 13) void textFormatChanged();
231
232protected:
233 bool eventFilter(QObject *object, QEvent *event) override;
234 void focusInEvent(QFocusEvent *event) override;
235 void focusOutEvent(QFocusEvent *event) override;
236#if QT_CONFIG(im)
237 void inputMethodEvent(QInputMethodEvent *event) override;
238#endif
239 void keyPressEvent(QKeyEvent *event) override;
240 void keyReleaseEvent(QKeyEvent *event) override;
241#if QT_CONFIG(wheelevent)
242 void wheelEvent(QWheelEvent *event) override;
243#endif
244 bool event(QEvent *e) override;
245
246 void componentComplete() override;
247 void itemChange(ItemChange change, const ItemChangeData &value) override;
248 void fontChange(const QFont &newFont, const QFont &oldFont) override;
249 void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override;
250 void localeChange(const QLocale &newLocale, const QLocale &oldLocale) override;
251
252 QFont defaultFont() const override;
253
254#if QT_CONFIG(accessibility)
255 QAccessible::Role accessibleRole() const override;
256 void accessibilityActiveChanged(bool active) override;
257#endif
258
259private:
260 Q_DISABLE_COPY(QQuickComboBox)
261 Q_DECLARE_PRIVATE(QQuickComboBox)
262};
263
264QT_END_NAMESPACE
265
266#endif // QQUICKCOMBOBOX_P_H
QQuickComboBoxDelegateModel(QQuickComboBox *combo)
QVariant variantValue(int index, const QString &role) override
void itemDestroyed(QQuickItem *item) override
bool handleRelease(const QPointF &point, ulong timestamp) override
CurrentElementCriteria currentElementCriteria
QQuickDeferredPointer< QQuickPopup > popup
qreal calculateWidestTextWidth() const
static void hideOldPopup(QQuickPopup *popup)
void setInputMethodHints(Qt::InputMethodHints hints, bool force=false)
void setHighlightedIndex(int index, Highlighting highlight)
void createdItem(int index, QObject *object)
QString effectiveTextRole() const
virtual qreal getContentWidth() const override
void keySearch(const QString &text)
std::optional< QQuickText::TextFormat > textFormat
void handleUngrab() override
int match(int start, const QString &text, Qt::MatchFlags flags) const
QPalette defaultPalette() const override
bool handleMove(const QPointF &point, ulong timestamp) override
QQmlInstanceModel * delegateModel
void itemImplicitHeightChanged(QQuickItem *item) override
void togglePopup(bool accept)
void executePopup(bool complete=false)
void itemImplicitWidthChanged(QQuickItem *item) override
void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles)
void executeIndicator(bool complete=false)
QQuickDeferredPointer< QQuickItem > indicator
void hidePopup(bool accept)
void setCurrentIndex(int index)
QLazilyAllocated< ExtraData > extra
std::optional< QPointer< QObject > > qobjectModelGuard
bool handlePress(const QPointF &point, ulong timestamp) override
void setCurrentItemAtIndex(int, Activation activate)
bool isValidIndex(int index) const
QString tryComplete(const QString &inputText)
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcQIORing)
QT_REQUIRE_CONFIG(qml_delegate_model)
static QString popupName()
Qt::InputMethodHints inputMethodHints