11#include <QtCore/qregularexpression.h>
12#include <QtCore/qabstractitemmodel.h>
13#include <QtCore/qglobal.h>
14#include <QtGui/qinputmethod.h>
15#include <QtGui/qguiapplication.h>
16#include <QtGui/private/qguiapplication_p.h>
17#include <QtGui/qpa/qplatformtheme.h>
18#include <QtQml/qjsvalue.h>
19#include <QtQml/qqmlcontext.h>
20#include <QtQml/private/qlazilyallocated_p.h>
21#include <private/qqmldelegatemodel_p.h>
22#include <QtQuick/private/qquickaccessibleattached_p.h>
23#include <QtQuick/private/qquickevents_p_p.h>
24#include <QtQuick/private/qquicktextinput_p.h>
25#include <QtQuick/private/qquicktextinput_p_p.h>
26#if QT_CONFIG(quick_itemview)
27#include <QtQuick/private/qquickitemview_p.h>
32Q_LOGGING_CATEGORY(lcCalculateWidestTextWidth,
"qt.quick.controls.combobox.calculatewidesttextwidth")
191 if (
model.
metaType() == QMetaType::fromType<QVariantList>()) {
193 if (
object.metaType() == QMetaType::fromType<QVariantMap>()) {
195 if (
data.size() == 1)
293 QQuickDeferredPointer<QQuickPopup>
popup;
303#if QT_CONFIG(validator)
349#if QT_CONFIG(quick_itemview)
357#if QT_CONFIG(quick_itemview)
372 emit q->popupChanged();
399#if QT_CONFIG(quick_itemview)
443 q->setCurrentIndex(-1);
444 emit q->countChanged();
464 input->setText(completed);
470 q->setEditText(
text);
480 q->maybeSetAccessibleName(
text);
481 emit q->currentTextChanged();
485 emit q->displayTextChanged();
487 if (!
extra.isAllocated() || !
extra->accepting)
499 emit q->currentValueChanged();
517 if (!textInputContentItem)
520 const bool newValue = textInputContentItem->hasAcceptableInput();
524 emit q->acceptableInputChanged();
539 q->setCurrentIndex(idx);
548 extra.value().accepting =
true;
555 extra.value().accepting =
false;
563 const int itemCount =
q->
count();
564 for (
int idx = 0; idx < itemCount; ++idx) {
587 emit q->currentIndexChanged();
599 if (
extra.isAllocated())
600 extra->allowComplete =
false;
602 if (highlightedIndex < q->
count() - 1)
605 if (currentIndex < q->
count() - 1)
608 if (
extra.isAllocated())
609 extra->allowComplete =
true;
614 if (
extra.isAllocated())
615 extra->allowComplete =
false;
623 if (
extra.isAllocated())
624 extra->allowComplete =
true;
639 emit q->highlightedIndexChanged();
669 for (
int i = 0; (
wrap &&
i < 2) || (!
wrap &&
i < 1); ++
i) {
670 for (
int idx = from; idx < to; ++idx) {
679 if (
rx.match(
t).hasMatch())
686 if (
rx.match(
t).hasMatch())
691 if (
t.startsWith(
text, cs))
695 if (
t.endsWith(
text, cs))
699 if (
t.compare(
text, cs) == 0)
704 if (
t.contains(
text, cs))
732 dataModel->setModel(
model);
734 if (
q->isComponentComplete())
735 dataModel->componentComplete();
747 emit q->delegateModelChanged();
765 q->setPressed(
q->contains(point));
774 q->setPressed(
false);
784 q->setPressed(
false);
819 if (!
popup || complete)
830 emit q->implicitIndicatorWidthChanged();
836 if (!force && hints ==
q->inputMethodHints())
839 extra.value().inputMethodHints = hints;
840 emit q->inputMethodHintsChanged();
848 emit q->implicitIndicatorHeightChanged();
857 emit q->indicatorChanged();
885 const int count =
q->count();
889 auto textInput = qobject_cast<QQuickTextInput*>(
contentItem);
893 qCDebug(lcCalculateWidestTextWidth) <<
"calculating widest text from" <<
count <<
"items...";
902 const qreal textImplicitWidth = textInputPrivate->calculateImplicitWidthForText(
text);
903 widest =
qMax(widest, textImplicitWidth);
906 qCDebug(lcCalculateWidestTextWidth) <<
"... widest text is" << widest;
934 qCDebug(lcItemManagement) <<
"hiding old popup" <<
popup;
937 popup->setParentItem(
nullptr);
938#if QT_CONFIG(accessibility)
940 QQuickAccessibleAttached *accessible = accessibleAttached(
popup);
942 accessible->setIgnored(
true);
963 d->removeImplicitSizeListener(
d->indicator);
982 return d->delegateModel ?
d->delegateModel->count() : 0;
1029 d->createDelegateModel();
1033 d->updateCurrentTextAndValue();
1037 d->maybeUpdateImplicitContentWidth();
1049 return d->delegateModel;
1078 setDown(
d->pressed ||
d->isPopupVisible());
1098 return d->highlightedIndex;
1113 return d->currentIndex;
1119 d->hasCurrentIndex =
true;
1120 d->setCurrentIndex(
index, NoActivate);
1134 return d->currentText;
1159 return d->displayText;
1165 d->hasDisplayText =
true;
1166 if (
d->displayText ==
text)
1169 d->displayText =
text;
1177 if (!
d->hasDisplayText)
1180 d->hasDisplayText =
false;
1181 d->updateCurrentText();
1204 if (
d->textRole == role)
1209 d->updateCurrentText();
1227 return d->valueRole;
1233 if (
d->valueRole == role)
1236 d->valueRole = role;
1238 d->updateCurrentValue();
1239 emit valueRoleChanged();
1296 d->executeIndicator();
1297 return d->indicator;
1308 if (!
d->indicator.isExecuting())
1309 d->cancelIndicator();
1314 d->removeImplicitSizeListener(
d->indicator);
1324 emit implicitIndicatorWidthChanged();
1326 emit implicitIndicatorHeightChanged();
1327 if (!
d->indicator.isExecuting())
1358 if (!
d->popup.isExecuting())
1368 popup->setClosePolicy(QQuickPopup::CloseOnEscape | QQuickPopup::CloseOnPressOutsideParent);
1374#if QT_CONFIG(quick_itemview)
1380 if (!
d->popup.isExecuting())
1407 if (
d->flat ==
flat)
1437 if (
d->down ==
down)
1450 setDown(
d->pressed ||
d->isPopupVisible());
1467 return d->extra.isAllocated() &&
d->extra->editable;
1476 if (
d->contentItem) {
1478 d->contentItem->installEventFilter(
this);
1483#if QT_CONFIG(cursor)
1487 d->contentItem->removeEventFilter(
this);
1492#if QT_CONFIG(cursor)
1493 d->contentItem->unsetCursor();
1500 emit editableChanged();
1514 return d->extra.isAllocated() ?
d->extra->editText :
QString();
1523 d->extra.value().editText =
text;
1524 emit editTextChanged();
1532#if QT_CONFIG(validator)
1565 return d->extra.isAllocated() ?
d->extra->validator :
nullptr;
1568void QQuickComboBox::setValidator(
QValidator *validator)
1571 if (validator == QQuickComboBox::validator())
1574 d->extra.value().validator = validator;
1575#if QT_CONFIG(validator)
1579 emit validatorChanged();
1603 d->setInputMethodHints(hints);
1620 return d->contentItem &&
d->contentItem->property(
"inputMethodComposing").toBool();
1638 return d->m_acceptableInput;
1660 return d->indicator->implicitWidth();
1682 return d->indicator->implicitHeight();
1699 return d->currentValue;
1714 if (!
d->isValidIndex(
index))
1718 return d->delegateModel->variantValue(
index, effectiveValueRole);
1733int QQuickComboBox::indexOfValue(
const QVariant &
value)
const
1735 for (
int i = 0;
i <
count(); ++
i) {
1737 if (
value == ourValue)
1755 return d->extra.isAllocated() ?
d->extra->selectTextByMouse :
false;
1764 d->extra.value().selectTextByMouse = canSelect;
1765 emit selectTextByMouseChanged();
1825 return d->implicitContentWidthPolicy;
1831 if (
policy ==
d->implicitContentWidthPolicy)
1834 d->implicitContentWidthPolicy =
policy;
1835 d->maybeUpdateImplicitContentWidth();
1836 emit implicitContentWidthPolicyChanged();
1853 if (!
d->isValidIndex(
index))
1856 return d->delegateModel->stringValue(
index,
d->effectiveTextRole());
1900 d->incrementCurrentIndex();
1914 d->decrementCurrentIndex();
1925void QQuickComboBox::selectAll()
1937 switch (
event->type()) {
1939 if (
d->isPopupVisible())
1940 d->hidePopup(
false);
1944 if (
d->filterKeyEvent(ke,
false))
1947 if (
d->extra.isAllocated())
1952 if (
qGuiApp->focusObject() !=
this && (!
d->popup || !
d->popup->hasActiveFocus())) {
1956 d->hidePopup(
false);
1962 if (indexForEditText > -1)
1968 if (
d->extra.isAllocated())
1987 d->contentItem->forceActiveFocus(
event->reason());
1995 if (
qGuiApp->focusObject() !=
d->contentItem && (!
d->popup || !
d->popup->hasActiveFocus())) {
1999 d->hidePopup(
false);
2008 QQuickControl::inputMethodEvent(
event);
2010 d->keySearch(
event->commitString());
2021 const auto key =
event->key();
2024 if (buttonPressKeys.contains(
key)) {
2025 if (!
event->isAutoRepeat())
2035 if (
d->isPopupVisible())
2040 if (
d->isPopupVisible())
2045 d->keyNavigating =
true;
2046 d->decrementCurrentIndex();
2050 d->keyNavigating =
true;
2051 d->incrementCurrentIndex();
2055 d->keyNavigating =
true;
2056 if (
d->isPopupVisible())
2057 d->setHighlightedIndex(0, Highlight);
2059 d->setCurrentIndex(0, Activate);
2063 d->keyNavigating =
true;
2064 if (
d->isPopupVisible())
2065 d->setHighlightedIndex(
count() - 1, Highlight);
2067 d->setCurrentIndex(
count() - 1, Activate);
2071 if (!
isEditable() && !
event->text().isEmpty())
2072 d->keySearch(
event->text());
2083 d->keyNavigating =
false;
2084 if (
event->isAutoRepeat())
2087 const auto key =
event->key();
2090 if (buttonPressKeys.contains(
key)) {
2092 d->togglePopup(
true);
2103 d->hidePopup(
d->isPopupVisible());
2109 if (
d->isPopupVisible()) {
2110 d->hidePopup(
false);
2120#if QT_CONFIG(wheelevent)
2121void QQuickComboBox::wheelEvent(QWheelEvent *
event)
2124 QQuickControl::wheelEvent(
event);
2125 if (
d->wheelEnabled && !
d->isPopupVisible()) {
2126 if (
event->angleDelta().y() > 0)
2127 d->decrementCurrentIndex();
2129 d->incrementCurrentIndex();
2138 d->updateCurrentTextAndValue();
2145 d->executeIndicator(
true);
2148 d->executePopup(
true);
2150 if (
d->delegateModel &&
d->ownModel)
2154 if (!
d->hasCurrentIndex &&
d->currentIndex == -1)
2157 d->updateCurrentTextAndValue();
2161 if (!
d->hasCalculatedWidestText)
2162 d->maybeUpdateImplicitContentWidth();
2171 d->hidePopup(
false);
2180 d->maybeUpdateImplicitContentWidth();
2187 oldItem->removeEventFilter(
this);
2188 if (
QQuickTextInput *oldInput = qobject_cast<QQuickTextInput *>(oldItem)) {
2196 newItem->installEventFilter(
this);
2197 if (
QQuickTextInput *newInput = qobject_cast<QQuickTextInput *>(newItem)) {
2203#if QT_CONFIG(cursor)
2208 d->updateAcceptableInput();
2214#if QT_CONFIG(validator)
2216 v->setLocale(newLocale);
2225#if QT_CONFIG(accessibility)
2226QAccessible::Role QQuickComboBox::accessibleRole()
const
2228 return QAccessible::ComboBox;
2231void QQuickComboBox::accessibilityActiveChanged(
bool active)
2234 QQuickControl::accessibilityActiveChanged(active);
2245#include "moc_qquickcombobox_p.cpp"
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
Type type() const
Returns the event type.
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
The QFocusEvent class contains event parameters for widget focus events.
void setParentItem(QGraphicsItem *parent)
Sets this item's parent item to newParent.
QGraphicsItem * parentItem() const
Returns a pointer to this item's parent item.
static QPlatformTheme * platformTheme()
static QInputMethod * inputMethod()
returns the input method.
The QJSValue class acts as a container for Qt/JavaScript data types.
The QKeyEvent class describes a key event.
static constexpr Policy Preferred
static constexpr Policy Fixed
T value(qsizetype i) const
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
static bool disconnect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot)
T findChild(QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
Returns the child of this object that can be cast into type T and that is called name,...
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
virtual bool eventFilter(QObject *watched, QEvent *event)
Filters events if this object has been installed as an event filter for the watched object.
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
The QPalette class contains color groups for each widget state.
\inmodule QtCore\reentrant
The QQmlComponent class encapsulates a QML component definition.
QVariant variantValue(int index, const QString &role) override
void createdItem(int index, QObject *object)
void modelUpdated(const QQmlChangeSet &changeSet, bool reset)
virtual int indexOf(QObject *object, QObject *objectContext) const =0
QString stringValue(int index, const QString &role)
QQuickComboBoxDelegateModel(QQuickComboBox *combo)
QVariant variantValue(int index, const QString &role) override
void itemDestroyed(QQuickItem *item) override
bool handleRelease(const QPointF &point, ulong timestamp) override
qreal calculateWidestTextWidth() const
QQmlInstanceModel * delegateModel
static void hideOldPopup(QQuickPopup *popup)
void setInputMethodHints(Qt::InputMethodHints hints, bool force=false)
void maybeUpdateImplicitContentWidth()
void setHighlightedIndex(int index, Highlighting highlight)
void createdItem(int index, QObject *object)
void updateHighlightedIndex()
QString effectiveTextRole() const
QLazilyAllocated< ExtraData > extra
virtual qreal getContentWidth() const override
void keySearch(const QString &text)
void handleUngrab() override
bool hasCalculatedWidestText
void updateCurrentValue()
int match(int start, const QString &text, Qt::MatchFlags flags) const
void setCurrentIndex(int index, Activation activate)
QQuickComboBox::ImplicitContentWidthPolicy implicitContentWidthPolicy
bool isPopupVisible() const
void updateCurrentTextAndValue()
QPalette defaultPalette() const override
void createDelegateModel()
QQuickDeferredPointer< QQuickPopup > popup
bool handleMove(const QPointF &point, ulong timestamp) override
void itemImplicitHeightChanged(QQuickItem *item) override
void togglePopup(bool accept)
void executePopup(bool complete=false)
void itemImplicitWidthChanged(QQuickItem *item) override
void popupVisibleChanged()
QQuickDeferredPointer< QQuickItem > indicator
void executeIndicator(bool complete=false)
void hidePopup(bool accept)
void updateAcceptableInput()
bool handlePress(const QPointF &point, ulong timestamp) override
void decrementCurrentIndex()
bool isValidIndex(int index) const
QString tryComplete(const QString &inputText)
void incrementCurrentIndex()
qreal implicitIndicatorWidth
void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override
QQmlInstanceModel * delegateModel
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setSelectTextByMouse(bool canSelect)
qreal implicitIndicatorHeight
void setValueRole(const QString &role)
void setDisplayText(const QString &text)
void setEditText(const QString &text)
QQuickComboBox(QQuickItem *parent=nullptr)
void setInputMethodHints(Qt::InputMethodHints hints)
void fontChange(const QFont &newFont, const QFont &oldFont) override
void setIndicator(QQuickItem *indicator)
bool event(QEvent *e) override
This virtual function receives events to an object and should return true if the event e was recogniz...
void setModel(const QVariant &model)
void focusInEvent(QFocusEvent *event) override
This event handler can be reimplemented in a subclass to receive focus-in events for an item.
void keyPressEvent(QKeyEvent *event) override
This event handler can be reimplemented in a subclass to receive key press events for an item.
void incrementCurrentIndex()
\qmlmethod void QtQuick.Controls::ComboBox::incrementCurrentIndex()
bool eventFilter(QObject *object, QEvent *event) override
Filters events if this object has been installed as an event filter for the watched object.
void setDelegate(QQmlComponent *delegate)
bool isPressed() const
\readonly \qmlproperty bool QtQuick.Controls::ComboBox::pressed
void setPopup(QQuickPopup *popup)
void focusOutEvent(QFocusEvent *event) override
This event handler can be reimplemented in a subclass to receive focus-out events for an item.
void setCurrentIndex(int index)
void setEditable(bool editable)
bool hasAcceptableInput() const
Q_INVOKABLE int find(const QString &text, Qt::MatchFlags flags=Qt::MatchExactly) const
\qmlmethod int QtQuick.Controls::ComboBox::find(string text, enumeration flags)
QFont defaultFont() const override
void keyReleaseEvent(QKeyEvent *event) override
This event handler can be reimplemented in a subclass to receive key release events for an item.
void displayTextChanged()
void setImplicitContentWidthPolicy(ImplicitContentWidthPolicy policy)
ImplicitContentWidthPolicy implicitContentWidthPolicy
void setTextRole(const QString &role)
void localeChange(const QLocale &newLocale, const QLocale &oldLocale) override
Q_INVOKABLE QString textAt(int index) const
\qmlmethod string QtQuick.Controls::ComboBox::textAt(int index)
Qt::InputMethodHints inputMethodHints
void setPressed(bool pressed)
ImplicitContentWidthPolicy
@ WidestTextWhenCompleted
@ ContentItemImplicitWidth
void decrementCurrentIndex()
\qmlmethod void QtQuick.Controls::ComboBox::decrementCurrentIndex()
void itemChange(ItemChange change, const ItemChangeData &value) override
Called when change occurs for this item.
bool isInputMethodComposing() const
void itemImplicitWidthChanged(QQuickItem *item) override
void updateImplicitContentSize()
virtual bool handlePress(const QPointF &point, ulong timestamp)
QQuickDeferredPointer< QQuickItem > contentItem
void updateImplicitContentWidth()
static void hideOldItem(QQuickItem *item)
virtual void handleUngrab()
virtual bool handleRelease(const QPointF &point, ulong timestamp)
virtual qreal getContentWidth() const
static void warnIfCustomizationNotSupported(QObject *control, QQuickItem *item, const QString &propertyName)
void itemDestroyed(QQuickItem *item) override
virtual bool handleMove(const QPointF &point, ulong timestamp)
void itemImplicitHeightChanged(QQuickItem *item) override
void focusInEvent(QFocusEvent *event) override
This event handler can be reimplemented in a subclass to receive focus-in events for an item.
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void maybeSetAccessibleName(const QString &name)
virtual void localeChange(const QLocale &newLocale, const QLocale &oldLocale)
void itemChange(ItemChange change, const ItemChangeData &value) override
Called when change occurs for this item.
bool setAccessibleProperty(const char *propertyName, const QVariant &value)
void focusOutEvent(QFocusEvent *event) override
This event handler can be reimplemented in a subclass to receive focus-out events for an item.
virtual void fontChange(const QFont &newFont, const QFont &oldFont)
quint32 componentComplete
static QQuickItemPrivate * get(QQuickItem *item)
Q_INVOKABLE void positionViewAtIndex(int index, int mode)
void setHighlightRangeMode(HighlightRangeMode mode)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
void setFlag(Flag flag, bool enabled=true)
Enables the specified flag for this item if enabled is true; if enabled is false, the flag is disable...
virtual void keyPressEvent(QKeyEvent *event)
This event handler can be reimplemented in a subclass to receive key press events for an item.
void setParentItem(QQuickItem *parent)
void setAcceptedMouseButtons(Qt::MouseButtons buttons)
Sets the mouse buttons accepted by this item to buttons.
QQuickItem * parentItem() const
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
virtual void keyReleaseEvent(QKeyEvent *event)
This event handler can be reimplemented in a subclass to receive key release events for an item.
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
void setFocusPolicy(Qt::FocusPolicy policy)
Sets the focus policy of this item to policy.
static QQuickTextInputPrivate * get(QQuickTextInput *t)
void inputMethodComposingChanged()
void acceptableInputChanged()
static QPalette palette(Scope scope)
static QFont font(Scope scope)
\inmodule QtCore \reentrant
static QString anchoredPattern(const QString &expression)
static QString wildcardToRegularExpression(const QString &str, WildcardConversionOptions options=DefaultWildcardConversion)
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QString mid(qsizetype position, qsizetype n=-1) const &
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
qsizetype size() const noexcept
Returns the number of characters in this string.
qsizetype count(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
The QValidator class provides validation of input text.
void setLocale(const QLocale &locale)
Sets the locale that will be used for the validator.
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has userType() \l QMetaType::QVariantList.
QMetaType metaType() const
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
constexpr const T & qMax(const T &a, const T &b)
GLsizei const GLfloat * v
[13]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLenum input
QQmlContext * qmlContext(const QObject *obj)
static QString popupName()
void quickCancelDeferred(QObject *object, const QString &property)
void quickCompleteDeferred(QObject *object, const QString &property, QQuickDeferredPointer< T > &delegate)
void quickBeginDeferred(QObject *object, const QString &property, QQuickDeferredPointer< T > &delegate)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
static qreal valueAt(const QQuickRangeSlider *slider, qreal position)
static QT_BEGIN_NAMESPACE QAsn1Element wrap(quint8 type, const QAsn1Element &child)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
static QString indicatorName()
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, JSToQVariantConversionBehavior conversionBehavior, V4ObjectSet *visitedObjects)
myObject disconnect()
[26]
item setCursor(Qt::IBeamCursor)
[1]