Only emit messageChanged() if the message has actually changed

This fixes QStatusBar so it is back to the original behavior of only
emitting the signal when the message has changed. The intention of the
code that caused this to break in the first place is kept intact.

Change-Id: I2f57c2abec01246ed924626ad954ac9ff9889855
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
Andy Shaw 2013-09-17 20:07:37 +02:00 committed by The Qt Project
parent 4684f2179b
commit 89c01c3242
2 changed files with 30 additions and 2 deletions

View File

@ -551,8 +551,6 @@ void QStatusBar::showMessage(const QString &message, int timeout)
{
Q_D(QStatusBar);
d->tempItem = message;
if (timeout > 0) {
if (!d->timer) {
d->timer = new QTimer(this);
@ -563,6 +561,9 @@ void QStatusBar::showMessage(const QString &message, int timeout)
delete d->timer;
d->timer = 0;
}
if (d->tempItem == message)
return;
d->tempItem = message;
hideOrShow();
}

View File

@ -74,6 +74,7 @@ private slots:
void task194017_hiddenWidget();
void QTBUG4334_hiddenOnMaximizedWindow();
void QTBUG25492_msgtimeout();
void messageChangedSignal();
private:
QStatusBar *testWidget;
@ -95,6 +96,8 @@ void tst_QStatusBar::init()
QWidget *item1 = new QWidget(testWidget);
testWidget->addWidget(item1);
// currentMessage needs to be null as the code relies on this
currentMessage = QString();
}
void tst_QStatusBar::cleanup()
@ -316,6 +319,30 @@ void tst_QStatusBar::QTBUG25492_msgtimeout()
QCOMPARE(testWidget->currentMessage(), currentMessage);
}
void tst_QStatusBar::messageChangedSignal()
{
QVERIFY(testWidget->currentMessage().isNull());
QVERIFY(currentMessage.isNull());
testWidget->show();
QSignalSpy spy(testWidget, SIGNAL(messageChanged(QString)));
testWidget->showMessage("Ready", 0);
QCOMPARE(testWidget->currentMessage(), QString("Ready"));
QCOMPARE(testWidget->currentMessage(), currentMessage);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.takeFirst().at(0).toString(), currentMessage);
testWidget->clearMessage();
QCOMPARE(testWidget->currentMessage(), QString());
QCOMPARE(testWidget->currentMessage(), currentMessage);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.takeFirst().at(0).toString(), currentMessage);
testWidget->showMessage("Ready", 0);
testWidget->showMessage("Ready", 0);
QCOMPARE(testWidget->currentMessage(), QString("Ready"));
QCOMPARE(testWidget->currentMessage(), currentMessage);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.takeFirst().at(0).toString(), currentMessage);
}
QTEST_MAIN(tst_QStatusBar)
#include "tst_qstatusbar.moc"