diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-01-29 16:57:12 +0100 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-01-29 16:57:27 +0100 |
commit | a1dbdcbd6e818118f5fc28cdd39e47a02380adbd (patch) | |
tree | 0d813d9d72baeb1b5f7be048e775896c73f134f5 /src/widgets/widgets/qcombobox.cpp | |
parent | 67ea445f09db9feea4e863faa12c45fb007f53a4 (diff) | |
parent | 4cbadf699838406d14366ce61deec03cf45113f7 (diff) |
Merge remote-tracking branch 'origin/dev' into wip/cmake
Conflicts:
src/corelib/Qt5CoreConfigExtras.cmake.in
src/corelib/Qt5CoreMacros.cmake
src/dbus/Qt5DBusConfigExtras.cmake.in
src/widgets/Qt5WidgetsConfigExtras.cmake.in
Change-Id: Ib782f3b177c38b2cce83beebe15be9c0baa578f7
Diffstat (limited to 'src/widgets/widgets/qcombobox.cpp')
-rw-r--r-- | src/widgets/widgets/qcombobox.cpp | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index d786c7ff83..9789004473 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -144,11 +144,11 @@ QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewIt menuOption.menuItemType = QStyleOptionMenuItem::Normal; QVariant variant = index.model()->data(index, Qt::DecorationRole); - switch (variant.type()) { - case QVariant::Icon: + switch (variant.userType()) { + case QMetaType::QIcon: menuOption.icon = qvariant_cast<QIcon>(variant); break; - case QVariant::Color: { + case QMetaType::QColor: { static QPixmap pixmap(option.decorationSize); pixmap.fill(qvariant_cast<QColor>(variant)); menuOption.icon = pixmap; @@ -293,8 +293,7 @@ void QComboBoxPrivate::_q_modelReset() lineEdit->setText(QString()); updateLineEditGeometry(); } - if (currentIndex.row() != indexBeforeChange) - _q_emitCurrentIndexChanged(currentIndex); + trySetValidIndex(); modelChanged(); q->update(); } @@ -304,6 +303,25 @@ void QComboBoxPrivate::_q_modelDestroyed() model = QAbstractItemModelPrivate::staticEmptyModel(); } +void QComboBoxPrivate::trySetValidIndex() +{ + Q_Q(QComboBox); + bool currentReset = false; + + const int rowCount = q->count(); + for (int pos = 0; pos < rowCount; ++pos) { + const QModelIndex idx(model->index(pos, modelColumn, root)); + if (idx.flags() & Qt::ItemIsEnabled) { + setCurrentIndex(idx); + currentReset = true; + break; + } + } + + if (!currentReset) + setCurrentIndex(QModelIndex()); +} + QRect QComboBoxPrivate::popupGeometry(int screen) const { return QStylePrivate::useFullScreenForPopup() @@ -1888,7 +1906,7 @@ void QComboBoxPrivate::updateDelegate(bool force) QIcon QComboBoxPrivate::itemIcon(const QModelIndex &index) const { QVariant decoration = model->data(index, Qt::DecorationRole); - if (decoration.type() == QVariant::Pixmap) + if (decoration.userType() == QMetaType::QPixmap) return QIcon(qvariant_cast<QPixmap>(decoration)); else return qvariant_cast<QIcon>(decoration); @@ -2044,7 +2062,7 @@ const QValidator *QComboBox::validator() const \since 4.2 Sets the \a completer to use instead of the current completer. - If \a completer is 0, auto completion is disabled. + If \a completer is \nullptr, auto completion is disabled. By default, for an editable combo box, a QCompleter that performs case insensitive inline completion is automatically created. @@ -2096,6 +2114,9 @@ QAbstractItemDelegate *QComboBox::itemDelegate() const Sets the item \a delegate for the popup list view. The combobox takes ownership of the delegate. + Any existing delegate will be removed, but not deleted. QComboBox + does not take ownership of \a delegate. + \warning You should not share the same instance of a delegate between comboboxes, widget mappers or views. Doing so can cause incorrect or unintuitive editing behavior since each view connected to a given delegate may receive the @@ -2110,7 +2131,6 @@ void QComboBox::setItemDelegate(QAbstractItemDelegate *delegate) qWarning("QComboBox::setItemDelegate: cannot set a 0 delegate"); return; } - delete view()->itemDelegate(); view()->setItemDelegate(delegate); } @@ -2200,20 +2220,7 @@ void QComboBox::setModel(QAbstractItemModel *model) setRootModelIndex(QModelIndex()); - bool currentReset = false; - - const int rowCount = count(); - for (int pos=0; pos < rowCount; pos++) { - if (d->model->index(pos, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled) { - setCurrentIndex(pos); - currentReset = true; - break; - } - } - - if (!currentReset) - setCurrentIndex(-1); - + d->trySetValidIndex(); d->modelChanged(); } |