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
qcombobox_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QCOMBOBOX_P_H
6#define QCOMBOBOX_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 <QtWidgets/private/qtwidgetsglobal_p.h>
20#include "QtWidgets/qcombobox.h"
21
22#include "QtWidgets/qabstractslider.h"
23#include "QtWidgets/qstyleditemdelegate.h"
24#include "QtWidgets/qlistview.h"
25#include "QtWidgets/qstyle.h"
26#include "QtCore/qtimer.h"
27#include "private/qwidget_p.h"
28#include "QtCore/qpointer.h"
29
30#include <array>
31#include <limits>
32
34
35QT_BEGIN_NAMESPACE
36
37class QLineEdit;
38class QPainter;
39class QPlatformMenu;
40class QStyleOptionComboBox;
41class QStyleOptionMenuItem;
42class QStyleOptionViewItem;
43
45{
47public:
48 explicit QComboBoxListView(QComboBox *cmb = nullptr);
50
51protected:
52 void resizeEvent(QResizeEvent *event) override;
53 void initViewItemOption(QStyleOptionViewItem *option) const override;
54 void paintEvent(QPaintEvent *e) override;
55
56private:
57 QComboBox *combo;
58};
59
60class Q_AUTOTEST_EXPORT QComboBoxPrivateScroller : public QWidget
61{
62 Q_OBJECT
63
64public:
65 explicit QComboBoxPrivateScroller(QAbstractSlider::SliderAction action, QWidget *parent);
66 ~QComboBoxPrivateScroller() override;
67
68 QSize sizeHint() const override;
69
70protected:
71 void stopTimer();
72 void startTimer();
73
74 void enterEvent(QEnterEvent *) override;
75 void leaveEvent(QEvent *) override;
76 void timerEvent(QTimerEvent *e) override;
77 void hideEvent(QHideEvent *) override;
78 void mouseMoveEvent(QMouseEvent *e) override;
79 void paintEvent(QPaintEvent *) override;
80
81Q_SIGNALS:
82 void doScroll(int action);
83
84private:
85 QAbstractSlider::SliderAction sliderAction;
86 QBasicTimer timer;
87 bool fast = false;
88};
89
90class Q_WIDGETS_EXPORT QComboBoxPrivateContainer : public QFrame
91{
92 Q_OBJECT
93
94public:
95 QComboBoxPrivateContainer(QAbstractItemView *itemView, QComboBox *parent);
96 ~QComboBoxPrivateContainer();
97 QAbstractItemView *itemView() const;
98 void setItemView(QAbstractItemView *itemView);
99 int spacing() const;
100 int topMargin() const;
101 int bottomMargin() const { return topMargin(); }
102 void updateTopBottomMargin();
103 void updateStyleSettings();
104
105 QTimer blockMouseReleaseTimer;
106 QBasicTimer adjustSizeTimer;
107 QPoint initialClickPosition;
108
109public Q_SLOTS:
110 void scrollItemView(int action);
111 void hideScrollers();
112 void updateScrollers();
113 void viewDestroyed();
114
115protected:
116 void changeEvent(QEvent *e) override;
117 bool eventFilter(QObject *o, QEvent *e) override;
118 void mousePressEvent(QMouseEvent *e) override;
119 void mouseReleaseEvent(QMouseEvent *e) override;
120 void showEvent(QShowEvent *e) override;
121 void hideEvent(QHideEvent *e) override;
122 void timerEvent(QTimerEvent *timerEvent) override;
123 void resizeEvent(QResizeEvent *e) override;
124 void paintEvent(QPaintEvent *e) override;
125 QStyleOptionComboBox comboStyleOption() const;
126
127Q_SIGNALS:
128 void itemSelected(const QModelIndex &);
129 void resetButton();
130
131private:
132 QComboBox *combo;
133 QAbstractItemView *view = nullptr;
134 QComboBoxPrivateScroller *top = nullptr;
135 QComboBoxPrivateScroller *bottom = nullptr;
136 QElapsedTimer popupTimer;
137 bool maybeIgnoreMouseButtonRelease = false;
138
139 friend class QComboBox;
140 friend class QComboBoxPrivate;
141};
142
143class Q_AUTOTEST_EXPORT QComboMenuDelegate : public QAbstractItemDelegate
144{
145 Q_OBJECT
146public:
147 explicit QComboMenuDelegate(QObject *parent, QComboBox *cmb);
148 ~QComboMenuDelegate() override;
149
150protected:
151 void paint(QPainter *painter,
152 const QStyleOptionViewItem &option,
153 const QModelIndex &index) const override;
154 QSize sizeHint(const QStyleOptionViewItem &option,
155 const QModelIndex &index) const override;
156 bool editorEvent(QEvent *event, QAbstractItemModel *model,
157 const QStyleOptionViewItem &option, const QModelIndex &index) override;
158
159private:
160 QStyleOptionMenuItem getStyleOption(const QStyleOptionViewItem &option,
161 const QModelIndex &index) const;
162 QComboBox *mCombo;
163 int pressedIndex;
164};
165
166class Q_AUTOTEST_EXPORT QComboBoxDelegate : public QStyledItemDelegate
167{
168 Q_OBJECT
169public:
170 explicit QComboBoxDelegate(QObject *parent, QComboBox *cmb);
171 ~QComboBoxDelegate() override;
172
173 static bool isSeparator(const QModelIndex &index);
174 static void setSeparator(QAbstractItemModel *model, const QModelIndex &index);
175
176protected:
177 void paint(QPainter *painter,
178 const QStyleOptionViewItem &option,
179 const QModelIndex &index) const override;
180
181 QSize sizeHint(const QStyleOptionViewItem &option,
182 const QModelIndex &index) const override;
183private:
184 QComboBox *mCombo;
185};
186
187class Q_AUTOTEST_EXPORT QComboBoxPrivate : public QWidgetPrivate
188{
189 Q_DECLARE_PUBLIC(QComboBox)
190public:
191 QComboBoxPrivate();
192 ~QComboBoxPrivate();
193 void init();
194 QComboBoxPrivateContainer* viewContainer();
195 void updateLineEditGeometry();
196 Qt::MatchFlags matchFlags() const;
197 void editingFinished();
198 void returnPressed();
199 void complete();
200 void itemSelected(const QModelIndex &item);
201 bool contains(const QString &text, int role);
202 void emitActivated(const QModelIndex &index);
203 void emitHighlighted(const QModelIndex &index);
204 void emitCurrentIndexChanged(const QModelIndex &index);
205 void modelDestroyed();
206 void modelReset();
207 void updateMicroFocus() { q_func()->updateMicroFocus(); } // PMF connect doesn't handle default args
208#if QT_CONFIG(completer)
209 void completerActivated(const QModelIndex &index);
210#endif
211 void resetButton();
212 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
213 void updateIndexBeforeChange();
214 void rowsInserted(const QModelIndex &parent, int start, int end);
215 void rowsRemoved(const QModelIndex &parent, int start, int end);
216 void updateArrow(QStyle::StateFlag state);
217 bool updateHoverControl(const QPoint &pos);
218 void trySetValidIndex();
219 QRect popupGeometry(const QPoint &globalPos) const;
220 QStyle::SubControl newHoverControl(const QPoint &pos);
221 int computeWidthHint() const;
222 QSize recomputeSizeHint(QSize &sh) const;
223 void adjustComboBoxSize();
224 QString itemText(const QModelIndex &index) const;
225 QIcon itemIcon(const QModelIndex &index) const;
226 int itemRole() const;
227 void updateLayoutDirection();
228 void setCurrentIndex(const QModelIndex &index);
229 void updateDelegate(bool force = false);
230 void initViewItemOption(QStyleOptionViewItem *option) const;
231 void keyboardSearchString(const QString &text);
232 void modelChanged();
233 void updateViewContainerPaletteAndOpacity();
234 void updateFocusPolicy();
235 void showPopupFromMouseEvent(QMouseEvent *e);
236 void doHidePopup();
237 void updateCurrentText(const QString &text);
238 void connectModel();
239 void disconnectModel();
240
241#ifdef Q_OS_MAC
242 void cleanupNativePopup();
243 bool showNativePopup();
244 struct IndexSetter {
245 int index;
246 QComboBox *cb;
247
248 void operator()(void)
249 {
250 cb->setCurrentIndex(index);
251 cb->d_func()->emitActivated(cb->d_func()->currentIndex);
252 }
253 };
254#endif
255
256 std::array<QMetaObject::Connection, 8> modelConnections;
257 QAbstractItemModel *model = nullptr;
258 QLineEdit *lineEdit = nullptr;
259 QPointer<QComboBoxPrivateContainer> container;
260#ifdef Q_OS_MAC
261 QPlatformMenu *m_platformMenu = nullptr;
262#endif
263 QPersistentModelIndex currentIndex;
264 QPersistentModelIndex root;
265 QString placeholderText;
266 QString currentText;
267 QRect hoverRect;
268 QSize iconSize;
269 mutable QSize minimumSizeHint;
270 mutable QSize sizeHint;
271 QComboBox::InsertPolicy insertPolicy = QComboBox::InsertAtBottom;
272 QComboBox::SizeAdjustPolicy sizeAdjustPolicy = QComboBox::AdjustToContentsOnFirstShow;
273 QStyle::StateFlag arrowState = QStyle::State_None;
274 QStyle::SubControl hoverControl = QStyle::SC_None;
275 QComboBox::LabelDrawingMode labelDrawingMode = QComboBox::LabelDrawingMode::UseStyle;
276 int minimumContentsLength = 0;
277 int indexBeforeChange = -1;
278 int maxVisibleItems = 10;
279 int maxCount = (std::numeric_limits<int>::max)();
280 int modelColumn = 0;
281 int placeholderIndex = -1;
282 bool shownOnce : 1;
283 bool duplicatesEnabled : 1;
284 bool frame : 1;
285 bool inserting : 1;
286 bool hidingPopup : 1;
287};
288
289QT_END_NAMESPACE
290
291#endif // QCOMBOBOX_P_H
void resizeEvent(QResizeEvent *event) override
Definition qcombobox.cpp:83
void initViewItemOption(QStyleOptionViewItem *option) const override
Definition qcombobox.cpp:89
void paintEvent(QPaintEvent *e) override
Definition qcombobox.cpp:97
~QComboBoxListView() override
\inmodule QtWidgets
Definition qcombobox_p.h:91
friend class QPainter
Combined button and popup list for selecting options.
QT_REQUIRE_CONFIG(combobox)
#define qApp