From 73d1476fb1397948a4d806bd921fce372bd8d63b Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 2 Dec 2019 17:54:48 +0100 Subject: Replace most use of QVariant::type and occurrences of QVariant::Type I made a clazy automated check that replaced the use of QVariant::Type by the equivalent in QMetaType. This has been deprecated since Qt 5.0, but many uses were not yet removed. In addition, there was some manual changes to fix the compilation errors. Adapted the Private API of QDateTimeParser and QMimeDataPrivate and adjust QDateTimeEdit and QSpinBox. QVariant(QVariant::Invalid) in qstylesheet made no sense. But note that in QVariant::save, we actually wanted to use the non-user type. In the SQL module, many changes were actually reverted because the API still expects QVarient::Type. Change-Id: I98c368490e4ee465ed3a3b63bda8b8eaa50ea67e Reviewed-by: Lars Knoll --- src/widgets/widgets/qcombobox.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/widgets/widgets/qcombobox.cpp') diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index d786c7ff83..9826cabe50 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(variant); break; - case QVariant::Color: { + case QMetaType::QColor: { static QPixmap pixmap(option.decorationSize); pixmap.fill(qvariant_cast(variant)); menuOption.icon = pixmap; @@ -1888,7 +1888,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(decoration)); else return qvariant_cast(decoration); -- cgit v1.2.3 From 089d54f06ff327f5212cb08fdbcb540066357dd5 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 19 Jan 2020 19:40:56 +0100 Subject: Sync behavior and documentation of QFoo::setItemDelegate() QComboBox::setItemDelegate() does delete the old delegate which is in constrast to all other setItemDelegate() functions which is quite confusing. Sync in by *not* deleting the delegate in QComboBox::setItemDelegate() and adjust the documentation to explicitly state that the ownership is *not* passed to the affected classes. [ChangeLog][QtWidgets][QComboBox] QComobBox::setItemDelegates no longer deletes the previous delegate set. Fixes: QTBUG-72483 Change-Id: I89c8e53903e7c9924a980c57b83ce40f5866e6ae Reviewed-by: Friedemann Kleint Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qcombobox.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/widgets/widgets/qcombobox.cpp') diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index d786c7ff83..785de35090 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -2096,6 +2096,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 +2113,6 @@ void QComboBox::setItemDelegate(QAbstractItemDelegate *delegate) qWarning("QComboBox::setItemDelegate: cannot set a 0 delegate"); return; } - delete view()->itemDelegate(); view()->setItemDelegate(delegate); } -- cgit v1.2.3 From aec4e05e9e8ad9109d7db15dd0fea477e4574c20 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 25 Jan 2020 20:12:12 +0100 Subject: Doc/QtWidgets: replace some 0 with \nullptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace some 'is 0' or 'are 0' where 0 referes to a nullptr with 'is \nullptr' and 'are \nullptr' Change-Id: I5ff46185b570bdfc7d20d18a47fd9174771ad8e5 Reviewed-by: André Hartmann Reviewed-by: Sze Howe Koh --- src/widgets/widgets/qcombobox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets/widgets/qcombobox.cpp') diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 9826cabe50..aa3788c404 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -2044,7 +2044,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. -- cgit v1.2.3 From b0c804f345a383d2813f4709632baa43a4275646 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 29 Dec 2019 13:24:34 +0100 Subject: QComboBox: unify behavior of setModel() and modelReset When a new model is set, a valid index is selected. When a model is reset, this is not the case which is slightly inconsistent. Fix it by using the same logic to find a valid index when the model is reset Fixes: QTBUG-80998 Change-Id: I6c167511e199a6664343cf1dc3bcd27c65389bfd Reviewed-by: Friedemann Kleint --- src/widgets/widgets/qcombobox.cpp | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'src/widgets/widgets/qcombobox.cpp') diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index aa3788c404..95c2bea3fe 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -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() @@ -2200,20 +2218,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(); } -- cgit v1.2.3