summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjasplin <qt-info@nokia.com>2009-06-24 06:51:26 (GMT)
committerjasplin <qt-info@nokia.com>2009-06-24 06:55:57 (GMT)
commit84b5bd06dcc7c51d5b13f340aafd9797e1722c2e (patch)
tree1ceb11cf6b16da1f98270023e5448942014d3f22
parentaca09d2b5038ed193d198f4097b17051f5f94116 (diff)
downloadQt-84b5bd06dcc7c51d5b13f340aafd9797e1722c2e.zip
Qt-84b5bd06dcc7c51d5b13f340aafd9797e1722c2e.tar.gz
Qt-84b5bd06dcc7c51d5b13f340aafd9797e1722c2e.tar.bz2
Fixed sizeHint update bug in QSpinBox.
QSpinBox failed to recalculate its cached size hint when setting the range, prefix, or suffix. Reviewed-by: janarve Task-number: 255051
-rw-r--r--src/gui/widgets/qabstractspinbox.cpp4
-rw-r--r--src/gui/widgets/qspinbox.cpp6
-rw-r--r--tests/auto/qspinbox/tst_qspinbox.cpp79
3 files changed, 89 insertions, 0 deletions
diff --git a/src/gui/widgets/qabstractspinbox.cpp b/src/gui/widgets/qabstractspinbox.cpp
index e7f7c78..25acd6e 100644
--- a/src/gui/widgets/qabstractspinbox.cpp
+++ b/src/gui/widgets/qabstractspinbox.cpp
@@ -1696,6 +1696,8 @@ void QAbstractSpinBoxPrivate::updateEdit()
void QAbstractSpinBoxPrivate::setRange(const QVariant &min, const QVariant &max)
{
+ Q_Q(QAbstractSpinBox);
+
clearCache();
minimum = min;
maximum = (variantCompare(min, max) < 0 ? max : min);
@@ -1707,6 +1709,8 @@ void QAbstractSpinBoxPrivate::setRange(const QVariant &min, const QVariant &max)
} else if (value == minimum && !specialValueText.isEmpty()) {
updateEdit();
}
+
+ q->updateGeometry();
}
/*!
diff --git a/src/gui/widgets/qspinbox.cpp b/src/gui/widgets/qspinbox.cpp
index 1c2ae0d..e069a21 100644
--- a/src/gui/widgets/qspinbox.cpp
+++ b/src/gui/widgets/qspinbox.cpp
@@ -284,6 +284,9 @@ void QSpinBox::setPrefix(const QString &prefix)
d->prefix = prefix;
d->updateEdit();
+
+ d->cachedSizeHint = QSize();
+ updateGeometry();
}
/*!
@@ -318,6 +321,9 @@ void QSpinBox::setSuffix(const QString &suffix)
d->suffix = suffix;
d->updateEdit();
+
+ d->cachedSizeHint = QSize();
+ updateGeometry();
}
/*!
diff --git a/tests/auto/qspinbox/tst_qspinbox.cpp b/tests/auto/qspinbox/tst_qspinbox.cpp
index d161c85..ec1dced 100644
--- a/tests/auto/qspinbox/tst_qspinbox.cpp
+++ b/tests/auto/qspinbox/tst_qspinbox.cpp
@@ -65,6 +65,7 @@
#include <QDoubleSpinBox>
#include <QVBoxLayout>
#include <QKeySequence>
+#include <QStackedWidget>
#include <QDebug>
#include "../../shared/util.h"
@@ -142,6 +143,9 @@ private slots:
void specialValue();
void textFromValue();
+
+ void sizeHint();
+
public slots:
void valueChangedHelper(const QString &);
void valueChangedHelper(int);
@@ -956,5 +960,80 @@ void tst_QSpinBox::textFromValue()
QCOMPARE(spinBox.textFromValue(INT_MIN), QString::number(INT_MIN));
}
+class sizeHint_Tester
+{
+ QSize createStackedWidget(bool delaySpinBoxOperation)
+ {
+ QWidget *widget = new QWidget;
+ QHBoxLayout *layout = new QHBoxLayout(widget);
+ QSpinBox *spinBox = new QSpinBox;
+ if (!delaySpinBoxOperation)
+ spinBoxOperation(spinBox);
+ layout->addWidget(spinBox);
+ layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum));
+ QStackedWidget *stackedWidget = new QStackedWidget;
+ stackedWidget->addWidget(widget);
+ if (delaySpinBoxOperation)
+ spinBoxOperation(spinBox);
+
+ stackedWidget->resize(500, 30);
+ stackedWidget->show();
+ QTest::qWait(100);
+
+ return spinBox->size();
+ }
+ virtual void spinBoxOperation(QSpinBox *) = 0;
+public:
+ QSize size1;
+ QSize size2;
+ void exec()
+ {
+ size1 = createStackedWidget(true);
+ size2 = createStackedWidget(false);
+ }
+ sizeHint_Tester() : size1(1, 0), size2(2, 0) {}
+ virtual ~sizeHint_Tester() {}
+};
+
+class sizeHint_setRangeTester : public sizeHint_Tester
+{
+ void spinBoxOperation(QSpinBox *spinBox)
+ {
+ spinBox->setRange(0, 1234567890);
+ spinBox->setValue(spinBox->maximum());
+ }
+};
+
+class sizeHint_setPrefixTester : public sizeHint_Tester
+{
+ void spinBoxOperation(QSpinBox *spinBox)
+ {
+ spinBox->setPrefix("abcdefghij");
+ }
+};
+
+class sizeHint_setSuffixTester : public sizeHint_Tester
+{
+ void spinBoxOperation(QSpinBox *spinBox)
+ {
+ spinBox->setSuffix("abcdefghij");
+ }
+};
+
+void tst_QSpinBox::sizeHint()
+{
+ sizeHint_setRangeTester setRangeTester;
+ setRangeTester.exec();
+ QCOMPARE(setRangeTester.size1, setRangeTester.size2);
+
+ sizeHint_setPrefixTester setPrefixTester;
+ setPrefixTester.exec();
+ QCOMPARE(setPrefixTester.size1, setPrefixTester.size2);
+
+ sizeHint_setSuffixTester setSuffixTester;
+ setSuffixTester.exec();
+ QCOMPARE(setSuffixTester.size1, setSuffixTester.size2);
+}
+
QTEST_MAIN(tst_QSpinBox)
#include "tst_qspinbox.moc"