summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2010-06-16 08:05:44 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2010-06-16 08:50:23 (GMT)
commit183abff6ffcb020b8f0c4041cc82bba0d3b03863 (patch)
tree7492fe295fdc966b72ba27f3c68ef5d7716e2801 /tests
parent17fbbdd3a081a66e1d2b26db7935111c49cea75e (diff)
downloadQt-183abff6ffcb020b8f0c4041cc82bba0d3b03863.zip
Qt-183abff6ffcb020b8f0c4041cc82bba0d3b03863.tar.gz
Qt-183abff6ffcb020b8f0c4041cc82bba0d3b03863.tar.bz2
Fixed problem with wrong size hints when items were removed.
The reason was that the row/column count was not updated after an item was removed. (Note that qgraphicslinearlayout already did this, so we just follow the same pattern, except that the code for QGraphicsGridLayout is a bit more complex... Task-number: QTBUG-10314 Reviewed-by: Alexis Menard
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp86
1 files changed, 64 insertions, 22 deletions
diff --git a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
index 8127f84..b9a5c66 100644
--- a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
+++ b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
@@ -741,31 +741,73 @@ void tst_QGraphicsGridLayout::setColumnFixedWidth()
// public qreal columnSpacing(int column) const
void tst_QGraphicsGridLayout::columnSpacing()
{
- QGraphicsScene scene;
- QGraphicsView view(&scene);
- QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
- QGraphicsGridLayout *layout = new QGraphicsGridLayout();
- scene.addItem(widget);
- widget->setLayout(layout);
- populateLayout(layout, 3, 2);
- layout->setContentsMargins(0, 0, 0, 0);
- layout->setSpacing(0);
- QCOMPARE(layout->columnSpacing(0), 0.0);
+ {
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+ QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
+ QGraphicsGridLayout *layout = new QGraphicsGridLayout();
+ scene.addItem(widget);
+ widget->setLayout(layout);
+ populateLayout(layout, 3, 2);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
+ QCOMPARE(layout->columnSpacing(0), 0.0);
+
+ layout->setColumnSpacing(0, 20);
+ view.show();
+ widget->show();
+ widget->resize(widget->effectiveSizeHint(Qt::PreferredSize));
+ QApplication::processEvents();
- layout->setColumnSpacing(0, 20);
- view.show();
- widget->show();
- widget->resize(widget->effectiveSizeHint(Qt::PreferredSize));
- QApplication::processEvents();
+ QCOMPARE(layout->itemAt(0,0)->geometry().left(), 0.0);
+ QCOMPARE(layout->itemAt(0,0)->geometry().right(), 25.0);
+ QCOMPARE(layout->itemAt(0,1)->geometry().left(), 45.0);
+ QCOMPARE(layout->itemAt(0,1)->geometry().right(), 70.0);
+ QCOMPARE(layout->itemAt(0,2)->geometry().left(), 70.0);
+ QCOMPARE(layout->itemAt(0,2)->geometry().right(), 95.0);
- QCOMPARE(layout->itemAt(0,0)->geometry().left(), 0.0);
- QCOMPARE(layout->itemAt(0,0)->geometry().right(), 25.0);
- QCOMPARE(layout->itemAt(0,1)->geometry().left(), 45.0);
- QCOMPARE(layout->itemAt(0,1)->geometry().right(), 70.0);
- QCOMPARE(layout->itemAt(0,2)->geometry().left(), 70.0);
- QCOMPARE(layout->itemAt(0,2)->geometry().right(), 95.0);
+ delete widget;
+ }
+
+ {
+ // don't include items and spacings that was previously part of the layout
+ // (horizontal)
+ QGraphicsGridLayout *layout = new QGraphicsGridLayout;
+ populateLayout(layout, 3, 1);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
+ layout->setColumnSpacing(0, 10);
+ layout->setColumnSpacing(1, 10);
+ layout->setColumnSpacing(2, 10);
+ layout->setColumnSpacing(3, 10);
+ QCOMPARE(layout->preferredSize(), QSizeF(95, 25));
+ layout->removeAt(2);
+ QCOMPARE(layout->preferredSize(), QSizeF(60, 25));
+ layout->removeAt(1);
+ QCOMPARE(layout->preferredSize(), QSizeF(25, 25));
+ delete layout;
+ }
+ {
+ // don't include items and spacings that was previously part of the layout
+ // (vertical)
+ QGraphicsGridLayout *layout = new QGraphicsGridLayout;
+ populateLayout(layout, 2, 2);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
+ layout->setColumnSpacing(0, 10);
+ layout->setColumnSpacing(1, 10);
+ layout->setRowSpacing(0, 10);
+ layout->setRowSpacing(1, 10);
+ QCOMPARE(layout->preferredSize(), QSizeF(60, 60));
+ layout->removeAt(3);
+ QCOMPARE(layout->preferredSize(), QSizeF(60, 60));
+ layout->removeAt(2);
+ QCOMPARE(layout->preferredSize(), QSizeF(60, 25));
+ layout->removeAt(1);
+ QCOMPARE(layout->preferredSize(), QSizeF(25, 25));
+ delete layout;
+ }
- delete widget;
}
// public int columnStretchFactor(int column) const