QComboBox: Remove deprecated auto-completion properties

The replacement is to set, and configure, a QCompleter directly via
setCompleter. With the removal of the separate properties in QComboBox,
the configuration of the completer is not maintained if the line edit
is replaced. A QCompleter is created and set implicitly when the line
edit is set, unless the line edit came with a completer. This is what
the auto test verifies as well.

Change-Id: I9a4c73db5e39a2558aad346c0904be6deb4f1cd2
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Volker Hilsheimer 2020-04-17 11:51:14 +02:00
parent 55b470e411
commit d39fefc0eb
4 changed files with 26 additions and 165 deletions

View File

@ -92,7 +92,6 @@ QT_BEGIN_NAMESPACE
QComboBoxPrivate::QComboBoxPrivate()
: QWidgetPrivate(),
shownOnce(false),
autoCompletion(true),
duplicatesEnabled(false),
frame(true),
inserting(false)
@ -1518,105 +1517,6 @@ int QComboBox::maxCount() const
return d->maxCount;
}
#if QT_CONFIG(completer)
#if QT_DEPRECATED_SINCE(5, 13)
/*!
\property QComboBox::autoCompletion
\brief whether the combobox provides auto-completion for editable items
\since 4.1
\obsolete
Use setCompleter() instead.
By default, this property is \c true.
\sa editable
*/
/*!
\obsolete
Use completer() instead.
*/
bool QComboBox::autoCompletion() const
{
Q_D(const QComboBox);
return d->autoCompletion;
}
/*!
\obsolete
Use setCompleter() instead.
*/
void QComboBox::setAutoCompletion(bool enable)
{
Q_D(QComboBox);
#ifdef QT_KEYPAD_NAVIGATION
if (Q_UNLIKELY(QApplicationPrivate::keypadNavigationEnabled() && !enable && isEditable()))
qWarning("QComboBox::setAutoCompletion: auto completion is mandatory when combo box editable");
#endif
d->autoCompletion = enable;
if (!d->lineEdit)
return;
if (enable) {
if (d->lineEdit->completer())
return;
d->completer = new QCompleter(d->model, d->lineEdit);
connect(d->completer, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated(QModelIndex)));
d->completer->setCaseSensitivity(d->autoCompletionCaseSensitivity);
d->completer->setCompletionMode(QCompleter::InlineCompletion);
d->completer->setCompletionColumn(d->modelColumn);
d->lineEdit->setCompleter(d->completer);
d->completer->setWidget(this);
} else {
d->lineEdit->setCompleter(nullptr);
}
}
/*!
\property QComboBox::autoCompletionCaseSensitivity
\brief whether string comparisons are case-sensitive or case-insensitive for auto-completion
\obsolete
By default, this property is Qt::CaseInsensitive.
Use setCompleter() instead. Case sensitivity of the auto completion can be
changed using QCompleter::setCaseSensitivity().
\sa autoCompletion
*/
/*!
\obsolete
Use setCompleter() and QCompleter::setCaseSensitivity() instead.
*/
Qt::CaseSensitivity QComboBox::autoCompletionCaseSensitivity() const
{
Q_D(const QComboBox);
return d->autoCompletionCaseSensitivity;
}
/*!
\obsolete
Use setCompleter() and QCompleter::setCaseSensitivity() instead.
*/
void QComboBox::setAutoCompletionCaseSensitivity(Qt::CaseSensitivity sensitivity)
{
Q_D(QComboBox);
d->autoCompletionCaseSensitivity = sensitivity;
if (d->lineEdit && d->lineEdit->completer())
d->lineEdit->completer()->setCaseSensitivity(sensitivity);
}
#endif // QT_DEPRECATED_SINCE(5, 13)
#endif // QT_CONFIG(completer)
/*!
\property QComboBox::duplicatesEnabled
\brief whether the user can enter duplicate items into the combobox
@ -1902,6 +1802,9 @@ void QComboBox::setEditable(bool editable)
Sets the line \a edit to use instead of the current line edit widget.
The combo box takes ownership of the line edit.
\note Since the combobox's line edit owns the QCompleter, any previous
call to setCompleter() will no longer have any effect.
*/
void QComboBox::setLineEdit(QLineEdit *edit)
{
@ -1935,27 +1838,24 @@ void QComboBox::setLineEdit(QLineEdit *edit)
d->updateFocusPolicy();
d->lineEdit->setFocusProxy(this);
d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
#if QT_DEPRECATED_SINCE(5, 13)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
#if QT_CONFIG(completer)
setAutoCompletion(d->autoCompletion);
// create a default completer
if (!d->lineEdit->completer()) {
QCompleter *completer = new QCompleter(d->model, d->lineEdit);
completer->setCaseSensitivity(Qt::CaseInsensitive);
completer->setCompletionMode(QCompleter::InlineCompletion);
completer->setCompletionColumn(d->modelColumn);
#ifdef QT_KEYPAD_NAVIGATION
if (QApplicationPrivate::keypadNavigationEnabled()) {
// Editable combo boxes will have a completer that is set to UnfilteredPopupCompletion.
// This means that when the user enters edit mode they are immediately presented with a
// list of possible completions.
setAutoCompletion(true);
if (d->completer) {
d->completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
connect(d->completer, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated()));
}
if (QApplicationPrivate::keypadNavigationEnabled())
completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
#endif
// sets up connections
setCompleter(completer);
}
#endif
#endif
QT_WARNING_POP
#endif
setAttribute(Qt::WA_InputMethodEnabled);
d->updateLayoutDirection();
@ -2019,7 +1919,8 @@ const QValidator *QComboBox::validator() const
By default, for an editable combo box, a QCompleter that
performs case insensitive inline completion is automatically created.
\note The completer is removed when the \l editable property becomes \c false.
\note The completer is removed when the \l editable property becomes \c false,
or when the line edit is replaced by a call to setLineEdit().
Setting a completer on a QComboBox that is not editable will be ignored.
*/
void QComboBox::setCompleter(QCompleter *c)
@ -2104,7 +2005,10 @@ QAbstractItemModel *QComboBox::model() const
Sets the model to be \a model. \a model must not be \nullptr.
If you want to clear the contents of a model, call clear().
\sa clear()
\note If the combobox is editable, then the \a model will also be
set on the completer of the line edit.
\sa clear() setCompleter()
*/
void QComboBox::setModel(QAbstractItemModel *model)
{
@ -2119,8 +2023,7 @@ void QComboBox::setModel(QAbstractItemModel *model)
return;
#if QT_CONFIG(completer)
if (d->lineEdit && d->lineEdit->completer()
&& d->lineEdit->completer() == d->completer)
if (d->lineEdit && d->lineEdit->completer())
d->lineEdit->completer()->setModel(model);
#endif
if (d->model) {
@ -3579,6 +3482,9 @@ void QComboBox::setFrame(bool enable)
default value).
By default, this property has a value of 0.
\note In an editable combobox, the visible column will also become
the \l{QCompleter::completionColumn}{completion column}.
*/
int QComboBox::modelColumn() const
{
@ -3594,8 +3500,7 @@ void QComboBox::setModelColumn(int visibleColumn)
if (lv)
lv->setModelColumn(visibleColumn);
#if QT_CONFIG(completer)
if (d->lineEdit && d->lineEdit->completer()
&& d->lineEdit->completer() == d->completer)
if (d->lineEdit && d->lineEdit->completer())
d->lineEdit->completer()->setCompletionColumn(visibleColumn);
#endif
setCurrentIndex(currentIndex()); //update the text to the text of the new column;

View File

@ -72,14 +72,6 @@ class Q_WIDGETS_EXPORT QComboBox : public QWidget
Q_PROPERTY(int minimumContentsLength READ minimumContentsLength WRITE setMinimumContentsLength)
Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
#if QT_CONFIG(completer)
#if QT_DEPRECATED_SINCE(5, 13)
Q_PROPERTY(bool autoCompletion READ autoCompletion WRITE setAutoCompletion DESIGNABLE false)
Q_PROPERTY(Qt::CaseSensitivity autoCompletionCaseSensitivity READ autoCompletionCaseSensitivity WRITE setAutoCompletionCaseSensitivity DESIGNABLE false)
#endif
#endif // QT_CONFIG(completer)
Q_PROPERTY(bool duplicatesEnabled READ duplicatesEnabled WRITE setDuplicatesEnabled)
Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
Q_PROPERTY(int modelColumn READ modelColumn WRITE setModelColumn)
@ -95,19 +87,6 @@ public:
void setMaxCount(int max);
int maxCount() const;
#if QT_CONFIG(completer)
#if QT_DEPRECATED_SINCE(5, 13)
QT_DEPRECATED_X("Use completer() instead.")
bool autoCompletion() const;
QT_DEPRECATED_X("Use setCompleter() instead.")
void setAutoCompletion(bool enable);
QT_DEPRECATED_X("Use completer()->caseSensitivity() instead.")
Qt::CaseSensitivity autoCompletionCaseSensitivity() const;
QT_DEPRECATED_X("Use completer()->setCaseSensitivity() instead.")
void setAutoCompletionCaseSensitivity(Qt::CaseSensitivity sensitivity);
#endif
#endif
bool duplicatesEnabled() const;
void setDuplicatesEnabled(bool enable);

View File

@ -409,9 +409,6 @@ public:
QComboBoxPrivateContainer *container = nullptr;
#ifdef Q_OS_MAC
QPlatformMenu *m_platformMenu = nullptr;
#endif
#if QT_CONFIG(completer)
QPointer<QCompleter> completer;
#endif
QPersistentModelIndex currentIndex;
QPersistentModelIndex root;
@ -424,7 +421,6 @@ public:
QComboBox::SizeAdjustPolicy sizeAdjustPolicy = QComboBox::AdjustToContentsOnFirstShow;
QStyle::StateFlag arrowState = QStyle::State_None;
QStyle::SubControl hoverControl = QStyle::SC_None;
Qt::CaseSensitivity autoCompletionCaseSensitivity = Qt::CaseInsensitive;
int minimumContentsLength = 0;
int indexBeforeChange = -1;
int maxVisibleItems = 10;
@ -432,7 +428,6 @@ public:
int modelColumn = 0;
int placeholderIndex = -1;
bool shownOnce : 1;
bool autoCompletion : 1;
bool duplicatesEnabled : 1;
bool frame : 1;
bool inserting : 1;

View File

@ -263,15 +263,6 @@ void tst_QComboBox::getSetCheck()
obj1.setCompleter(&completer);
QVERIFY(obj1.completer() == nullptr); // no QLineEdit is set
#if QT_DEPRECATED_SINCE(5, 13)
// bool QComboBox::autoCompletion()
// void QComboBox::setAutoCompletion(bool)
obj1.setAutoCompletion(false);
QCOMPARE(false, obj1.autoCompletion());
obj1.setAutoCompletion(true);
QCOMPARE(true, obj1.autoCompletion());
#endif
// bool QComboBox::duplicatesEnabled()
// void QComboBox::setDuplicatesEnabled(bool)
obj1.setDuplicatesEnabled(false);
@ -805,9 +796,6 @@ void tst_QComboBox::virtualAutocompletion()
QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
QComboBox *testWidget = topLevel.comboBox();
testWidget->clear();
#if QT_DEPRECATED_SINCE(5, 13)
testWidget->setAutoCompletion(true);
#endif
testWidget->addItem("Foo");
testWidget->addItem("Bar");
testWidget->addItem("Boat");
@ -870,9 +858,6 @@ void tst_QComboBox::autoCompletionCaseSensitivity()
QCOMPARE(qApp->focusWidget(), (QWidget *)testWidget);
testWidget->clear();
#if QT_DEPRECATED_SINCE(5, 13)
testWidget->setAutoCompletion(true);
#endif
testWidget->addItem("Cow");
testWidget->addItem("irrelevant1");
testWidget->addItem("aww");
@ -3093,9 +3078,6 @@ void tst_QComboBox::task_QTBUG_31146_popupCompletion()
QComboBox comboBox;
comboBox.setEditable(true);
#if QT_DEPRECATED_SINCE(5, 13)
comboBox.setAutoCompletion(true);
#endif
comboBox.setInsertPolicy(QComboBox::NoInsert);
comboBox.completer()->setCaseSensitivity(Qt::CaseInsensitive);
comboBox.completer()->setCompletionMode(QCompleter::PopupCompletion);