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)
301#if QT_CONFIG(validator)
347#if QT_CONFIG(quick_itemview)
355#if QT_CONFIG(quick_itemview)
390#if QT_CONFIG(quick_itemview)
434 q->setCurrentIndex(-1);
435 emit q->countChanged();
455 input->setText(completed);
461 q->setEditText(
text);
471 q->maybeSetAccessibleName(
text);
472 emit q->currentTextChanged();
476 emit q->displayTextChanged();
478 if (!
extra.isAllocated() || !
extra->accepting)
490 emit q->currentValueChanged();
508 if (!textInputContentItem)
515 emit q->acceptableInputChanged();
530 q->setCurrentIndex(idx);
539 extra.value().accepting =
true;
546 extra.value().accepting =
false;
554 const int itemCount =
q->count();
555 for (
int idx = 0; idx < itemCount; ++idx) {
578 emit q->currentIndexChanged();
590 if (
extra.isAllocated())
591 extra->allowComplete =
false;
593 if (highlightedIndex < q->
count() - 1)
596 if (currentIndex < q->
count() - 1)
599 if (
extra.isAllocated())
600 extra->allowComplete =
true;
605 if (
extra.isAllocated())
606 extra->allowComplete =
false;
614 if (
extra.isAllocated())
615 extra->allowComplete =
true;
630 emit q->highlightedIndexChanged();
660 for (
int i = 0; (
wrap &&
i < 2) || (!
wrap &&
i < 1); ++
i) {
661 for (
int idx = from; idx < to; ++idx) {
670 if (
rx.match(
t).hasMatch())
677 if (
rx.match(
t).hasMatch())
682 if (
t.startsWith(
text, cs))
686 if (
t.endsWith(
text, cs))
690 if (
t.compare(
text, cs) == 0)
695 if (
t.contains(
text, cs))
725 if (
q->isComponentComplete())
738 emit q->delegateModelChanged();
756 q->setPressed(
q->contains(point));
765 q->setPressed(
false);
775 q->setPressed(
false);
810 if (!
popup || complete)
821 emit q->implicitIndicatorWidthChanged();
827 if (!force && hints ==
q->inputMethodHints())
830 extra.value().inputMethodHints = hints;
831 emit q->inputMethodHintsChanged();
839 emit q->implicitIndicatorHeightChanged();
866 const int count =
q->count();
870 auto textInput = qobject_cast<QQuickTextInput*>(
contentItem);
874 qCDebug(lcCalculateWidestTextWidth) <<
"calculating widest text from" <<
count <<
"items...";
883 const qreal textImplicitWidth = textInputPrivate->calculateImplicitWidthForText(
text);
884 widest =
qMax(widest, textImplicitWidth);
887 qCDebug(lcCalculateWidestTextWidth) <<
"... widest text is" << widest;
915 qCDebug(lcItemManagement) <<
"hiding old popup" <<
popup;
918 popup->setParentItem(
nullptr);
919#if QT_CONFIG(accessibility)
921 QQuickAccessibleAttached *accessible = accessibleAttached(
popup);
923 accessible->setIgnored(
true);
943 d->removeImplicitSizeListener(
d->indicator);
962 return d->delegateModel ?
d->delegateModel->count() : 0;
1009 d->createDelegateModel();
1013 d->updateCurrentTextAndValue();
1017 d->maybeUpdateImplicitContentWidth();
1029 return d->delegateModel;
1058 setDown(
d->pressed ||
d->isPopupVisible());
1078 return d->highlightedIndex;
1093 return d->currentIndex;
1099 d->hasCurrentIndex =
true;
1100 d->setCurrentIndex(
index, NoActivate);
1114 return d->currentText;
1139 return d->displayText;
1145 d->hasDisplayText =
true;
1146 if (
d->displayText ==
text)
1149 d->displayText =
text;
1157 if (!
d->hasDisplayText)
1160 d->hasDisplayText =
false;
1161 d->updateCurrentText();
1184 if (
d->textRole == role)
1189 d->updateCurrentText();
1207 return d->valueRole;
1213 if (
d->valueRole == role)
1216 d->valueRole = role;
1218 d->updateCurrentValue();
1219 emit valueRoleChanged();
1276 d->executeIndicator();
1277 return d->indicator;
1288 if (!
d->indicator.isExecuting())
1289 d->cancelIndicator();
1294 d->removeImplicitSizeListener(
d->indicator);
1304 emit implicitIndicatorWidthChanged();
1306 emit implicitIndicatorHeightChanged();
1307 if (!
d->indicator.isExecuting())
1338 if (!
d->popup.isExecuting())
1347 popup->setClosePolicy(QQuickPopup::CloseOnEscape | QQuickPopup::CloseOnPressOutsideParent);
1350#if QT_CONFIG(quick_itemview)
1356 if (!
d->popup.isExecuting())
1383 if (
d->flat ==
flat)
1413 if (
d->down ==
down)
1426 setDown(
d->pressed ||
d->isPopupVisible());
1443 return d->extra.isAllocated() &&
d->extra->editable;
1452 if (
d->contentItem) {
1454 d->contentItem->installEventFilter(
this);
1459#if QT_CONFIG(cursor)
1463 d->contentItem->removeEventFilter(
this);
1468#if QT_CONFIG(cursor)
1469 d->contentItem->unsetCursor();
1476 emit editableChanged();
1490 return d->extra.isAllocated() ?
d->extra->editText :
QString();
1499 d->extra.value().editText =
text;
1500 emit editTextChanged();
1508#if QT_CONFIG(validator)
1541 return d->extra.isAllocated() ?
d->extra->validator :
nullptr;
1544void QQuickComboBox::setValidator(
QValidator *validator)
1547 if (validator == QQuickComboBox::validator())
1550 d->extra.value().validator = validator;
1551#if QT_CONFIG(validator)
1555 emit validatorChanged();
1579 d->setInputMethodHints(hints);
1596 return d->contentItem &&
d->contentItem->property(
"inputMethodComposing").toBool();
1614 return d->m_acceptableInput;
1636 return d->indicator->implicitWidth();
1658 return d->indicator->implicitHeight();
1675 return d->currentValue;
1690 if (!
d->isValidIndex(
index))
1694 return d->delegateModel->variantValue(
index, effectiveValueRole);
1709int QQuickComboBox::indexOfValue(
const QVariant &
value)
const
1711 for (
int i = 0;
i <
count(); ++
i) {
1713 if (
value == ourValue)
1731 return d->extra.isAllocated() ?
d->extra->selectTextByMouse :
false;
1740 d->extra.value().selectTextByMouse = canSelect;
1741 emit selectTextByMouseChanged();
1801 return d->implicitContentWidthPolicy;
1807 if (
policy ==
d->implicitContentWidthPolicy)
1810 d->implicitContentWidthPolicy =
policy;
1811 d->maybeUpdateImplicitContentWidth();
1812 emit implicitContentWidthPolicyChanged();
1829 if (!
d->isValidIndex(
index))
1832 return d->delegateModel->stringValue(
index,
d->effectiveTextRole());
1876 d->incrementCurrentIndex();
1890 d->decrementCurrentIndex();
1901void QQuickComboBox::selectAll()
1913 switch (
event->type()) {
1915 if (
d->isPopupVisible())
1916 d->hidePopup(
false);
1920 if (
d->filterKeyEvent(ke,
false))
1923 if (
d->extra.isAllocated())
1928 if (
qGuiApp->focusObject() !=
this && (!
d->popup || !
d->popup->hasActiveFocus())) {
1932 d->hidePopup(
false);
1938 if (indexForEditText > -1)
1944 if (
d->extra.isAllocated())
1963 d->contentItem->forceActiveFocus(
event->reason());
1971 if (
qGuiApp->focusObject() !=
d->contentItem && (!
d->popup || !
d->popup->hasActiveFocus())) {
1975 d->hidePopup(
false);
1984 QQuickControl::inputMethodEvent(
event);
1986 d->keySearch(
event->commitString());
1997 const auto key =
event->key();
2000 if (buttonPressKeys.contains(
key)) {
2001 if (!
event->isAutoRepeat())
2011 if (
d->isPopupVisible())
2016 if (
d->isPopupVisible())
2021 d->keyNavigating =
true;
2022 d->decrementCurrentIndex();
2026 d->keyNavigating =
true;
2027 d->incrementCurrentIndex();
2031 d->keyNavigating =
true;
2032 if (
d->isPopupVisible())
2033 d->setHighlightedIndex(0, Highlight);
2035 d->setCurrentIndex(0, Activate);
2039 d->keyNavigating =
true;
2040 if (
d->isPopupVisible())
2041 d->setHighlightedIndex(
count() - 1, Highlight);
2043 d->setCurrentIndex(
count() - 1, Activate);
2047 if (!
isEditable() && !
event->text().isEmpty())
2048 d->keySearch(
event->text());
2059 d->keyNavigating =
false;
2060 if (
event->isAutoRepeat())
2063 const auto key =
event->key();
2066 if (buttonPressKeys.contains(
key)) {
2068 d->togglePopup(
true);
2079 d->hidePopup(
d->isPopupVisible());
2085 if (
d->isPopupVisible()) {
2086 d->hidePopup(
false);
2096#if QT_CONFIG(wheelevent)
2097void QQuickComboBox::wheelEvent(QWheelEvent *
event)
2100 QQuickControl::wheelEvent(
event);
2101 if (
d->wheelEnabled && !
d->isPopupVisible()) {
2102 if (
event->angleDelta().y() > 0)
2103 d->decrementCurrentIndex();
2105 d->incrementCurrentIndex();
2114 d->updateCurrentTextAndValue();
2121 d->executeIndicator(
true);
2124 d->executePopup(
true);
2126 if (
d->delegateModel &&
d->ownModel)
2130 if (!
d->hasCurrentIndex &&
d->currentIndex == -1)
2133 d->updateCurrentTextAndValue();
2137 if (!
d->hasCalculatedWidestText)
2138 d->maybeUpdateImplicitContentWidth();
2147 d->hidePopup(
false);
2156 d->maybeUpdateImplicitContentWidth();
2164 if (
QQuickTextInput *oldInput = qobject_cast<QQuickTextInput *>(oldItem)) {
2173 if (
QQuickTextInput *newInput = qobject_cast<QQuickTextInput *>(newItem)) {
2179#if QT_CONFIG(cursor)
2184 d->updateAcceptableInput();
2190#if QT_CONFIG(validator)
2192 v->setLocale(newLocale);
2201#if QT_CONFIG(accessibility)
2202QAccessible::Role QQuickComboBox::accessibleRole()
const
2204 return QAccessible::ComboBox;
2207void QQuickComboBox::accessibilityActiveChanged(
bool active)
2210 QQuickControl::accessibilityActiveChanged(active);
2221#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.
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.
int key() const
Returns the code of the key that was pressed or released.
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(const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
Returns the child of this object that can be cast into type T and that is called name,...
void installEventFilter(QObject *filterObj)
Installs an event filter filterObj on this object.
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 removeEventFilter(QObject *obj)
Removes an event filter object obj from this object.
The QPalette class contains color groups for each widget state.
\inmodule QtCore\reentrant
The QQmlComponent class encapsulates a QML component definition.
void setModel(const QVariant &)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setDelegate(QQmlComponent *)
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
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)
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 setFocusPolicy(Qt::FocusPolicy policy)
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.
static QQuickTextInputPrivate * get(QQuickTextInput *t)
void inputMethodComposingChanged()
bool hasAcceptableInput() const
\qmlproperty bool QtQuick::TextInput::acceptableInput \readonly
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.
qsizetype size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
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, bool createJSValueForObjectsAndSymbols, V4ObjectSet *visitedObjects)
myObject disconnect()
[26]
item setCursor(Qt::IBeamCursor)
[1]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent