QComboBox: deprecate currentIndexChanged(const QString&)
Task-number: QTBUG-81845 Change-Id: Ia0ff5321423a5d3d4853bd425dd7236926f16047 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
e541a3f099
commit
11dc7b35c8
@ -959,6 +959,8 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const
|
||||
changes either through user interaction or programmatically. The
|
||||
item's \a index is passed or -1 if the combobox becomes empty or the
|
||||
currentIndex was reset.
|
||||
|
||||
\obsolete Use currentIndexChanged(int index, const QString &text) instead
|
||||
*/
|
||||
|
||||
/*!
|
||||
@ -968,6 +970,18 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const
|
||||
This signal is sent whenever the currentIndex in the combobox
|
||||
changes either through user interaction or programmatically. The
|
||||
item's \a text is passed.
|
||||
|
||||
\obsolete Use currentIndexChanged(int index, const QString &text) instead
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QComboBox::currentIndexChanged(int index, const QString &text)
|
||||
\since 5.15
|
||||
|
||||
This signal is sent whenever the currentIndex in the combobox
|
||||
changes either through user interaction or programmatically. The
|
||||
item's \a index is passed or -1 if the combobox becomes empty or
|
||||
the currentIndex was reset. The item's \a text is also passed.
|
||||
*/
|
||||
|
||||
/*!
|
||||
@ -1452,13 +1466,14 @@ void QComboBoxPrivate::_q_emitCurrentIndexChanged(const QModelIndex &index)
|
||||
{
|
||||
Q_Q(QComboBox);
|
||||
const QString text = itemText(index);
|
||||
emit q->currentIndexChanged(index.row());
|
||||
#if QT_DEPRECATED_SINCE(5, 13)
|
||||
#if QT_DEPRECATED_SINCE(5, 15)
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
emit q->currentIndexChanged(index.row());
|
||||
emit q->currentIndexChanged(text);
|
||||
QT_WARNING_POP
|
||||
#endif
|
||||
emit q->currentIndexChanged(index.row(), text);
|
||||
// signal lineEdit.textChanged already connected to signal currentTextChanged, so don't emit double here
|
||||
if (!lineEdit)
|
||||
emit q->currentTextChanged(text);
|
||||
|
@ -230,8 +230,13 @@ Q_SIGNALS:
|
||||
void textActivated(const QString &);
|
||||
void highlighted(int index);
|
||||
void textHighlighted(const QString &);
|
||||
#if QT_DEPRECATED_SINCE(5, 15)
|
||||
QT_DEPRECATED_VERSION_X_5_15("Use currentIndexChanged(int, const QString &) instead")
|
||||
void currentIndexChanged(int index);
|
||||
QT_DEPRECATED_VERSION_X_5_15("Use currentIndexChanged(int, const QString &) instead")
|
||||
void currentIndexChanged(const QString &);
|
||||
#endif
|
||||
void currentIndexChanged(int index, const QString &text);
|
||||
void currentTextChanged(const QString &);
|
||||
#if QT_DEPRECATED_SINCE(5, 15)
|
||||
QT_DEPRECATED_VERSION_X(5, 15, "Use textActivated() instead")
|
||||
|
@ -1208,8 +1208,7 @@ void tst_QComboBox::currentIndex()
|
||||
QVERIFY(testWidget->currentText().isEmpty());
|
||||
|
||||
// spy on currentIndexChanged
|
||||
QSignalSpy indexChangedInt(testWidget, SIGNAL(currentIndexChanged(int)));
|
||||
QSignalSpy indexChangedString(testWidget, SIGNAL(currentIndexChanged(QString)));
|
||||
QSignalSpy indexChangedSpy(testWidget, SIGNAL(currentIndexChanged(int, QString)));
|
||||
|
||||
// stuff items into it
|
||||
foreach(QString text, initialItems) {
|
||||
@ -1233,16 +1232,12 @@ void tst_QComboBox::currentIndex()
|
||||
QCOMPARE(testWidget->currentText(), expectedCurrentText);
|
||||
|
||||
// check that signal count is correct
|
||||
QCOMPARE(indexChangedInt.count(), expectedSignalCount);
|
||||
QCOMPARE(indexChangedString.count(), expectedSignalCount);
|
||||
QCOMPARE(indexChangedSpy.count(), expectedSignalCount);
|
||||
|
||||
// compare with last sent signal values
|
||||
if (indexChangedInt.count())
|
||||
QCOMPARE(indexChangedInt.at(indexChangedInt.count() - 1).at(0).toInt(),
|
||||
testWidget->currentIndex());
|
||||
if (indexChangedString.count())
|
||||
QCOMPARE(indexChangedString.at(indexChangedString.count() - 1).at(0).toString(),
|
||||
testWidget->currentText());
|
||||
if (indexChangedSpy.count())
|
||||
QCOMPARE(indexChangedSpy.at(indexChangedSpy.count() - 1).at(0).toInt(),
|
||||
testWidget->currentIndex());
|
||||
|
||||
if (edit) {
|
||||
testWidget->setCurrentIndex(-1);
|
||||
@ -2341,7 +2336,8 @@ public:
|
||||
{
|
||||
QStringList list;
|
||||
list << "one" << "two";
|
||||
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
|
||||
connect(this, SIGNAL(currentIndexChanged(int, QString)),
|
||||
this, SLOT(onCurrentIndexChanged(int)));
|
||||
addItems(list);
|
||||
}
|
||||
public slots:
|
||||
@ -2767,7 +2763,7 @@ void tst_QComboBox::resetModel()
|
||||
};
|
||||
QComboBox cb;
|
||||
StringListModel model({"1", "2"});
|
||||
QSignalSpy spy(&cb, QOverload<int>::of(&QComboBox::currentIndexChanged));
|
||||
QSignalSpy spy(&cb, QOverload<int, const QString &>::of(&QComboBox::currentIndexChanged));
|
||||
QCOMPARE(spy.count(), 0);
|
||||
QCOMPARE(cb.currentIndex(), -1); //no selection
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user