diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-06-25 12:41:03 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-06-26 11:47:35 +0000 |
commit | 1e8d4097860e4c92dd49c0df03ce6f9b68eef961 (patch) | |
tree | 92893a59e749ae6617296c6f0875ea2f882807e6 /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | |
parent | eae4756f74d70de46d9345ece54345f597bc1929 (diff) |
QQuickTableView: use QHash instead of QList to store delegate items
Using a QList to store all loaded delegate items was a legacy solution
inherited from QQuickItemView. But we look-up items in the list based
on index all the time, so switching to use QHash instead should be more
optimal.
Change-Id: I1aa8d23b3ac208a9424982491faaa5dd42775280
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 46 |
1 files changed, 6 insertions, 40 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index 1de40aaae0..6714779fc8 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -75,8 +75,6 @@ public: tst_QQuickTableView(); QQuickTableViewAttached *getAttachedObject(const QObject *object) const; - FxTableItem *findFxTableItem(int row, int column, const QList<FxTableItem *> items) const; - FxTableItem *findLoadedBottomRightItem(const QList<FxTableItem *> items) const; private slots: void initTestCase() override; @@ -121,32 +119,6 @@ QQuickTableViewAttached *tst_QQuickTableView::getAttachedObject(const QObject *o return static_cast<QQuickTableViewAttached *>(attachedObject); } -FxTableItem *tst_QQuickTableView::findFxTableItem(int row, int column, const QList<FxTableItem *> items) const -{ - for (int i = 0; i < items.count(); ++i) { - FxTableItem *fxitem = items[i]; - auto attached = getAttachedObject(fxitem->item); - if (row == attached->row() && column == attached->column()) - return fxitem; - } - return nullptr; -} - -FxTableItem *tst_QQuickTableView::findLoadedBottomRightItem(const QList<FxTableItem *> items) const -{ - FxTableItem *bottomRightItem = nullptr; - int bottomRightIndex = 0; - - for (int i = items.count() - 1; i > 0; --i) { - FxTableItem *fxitem = items[i]; - if (fxitem->index > bottomRightIndex) { - bottomRightItem = fxitem; - bottomRightIndex = fxitem->index; - } - } - return bottomRightItem; -} - void tst_QQuickTableView::setAndGetModel_data() { QTest::addColumn<QVariant>("model"); @@ -418,15 +390,13 @@ void tst_QQuickTableView::checkTableMargins() WAIT_UNTIL_POLISHED; - auto const items = tableViewPrivate->loadedItems; - - auto const topLeftFxItem = findFxTableItem(0, 0, items); - auto const bottomRightFxItem = findFxTableItem(tableSize.height() - 1, tableSize.width() - 1, items); - QVERIFY(topLeftFxItem); - QVERIFY(bottomRightFxItem); + QCOMPARE(tableViewPrivate->loadedTable.size(), tableSize); + auto const topLeftFxItem = tableViewPrivate->loadedTableItem(QPoint(0, 0)); + auto const bottomRightFxItem = tableViewPrivate->loadedTableItem(tableViewPrivate->loadedTable.bottomRight()); auto const topLeftItem = topLeftFxItem->item; auto const bottomRightItem = bottomRightFxItem->item; + qreal leftSpace = topLeftItem->x(); qreal topSpace = topLeftItem->y(); qreal rightSpace = tableView->contentWidth() - (bottomRightItem->x() + bottomRightItem->width()); @@ -473,18 +443,14 @@ void tst_QQuickTableView::fillTableViewButNothingMore() WAIT_UNTIL_POLISHED; - auto const items = tableViewPrivate->loadedItems; - - auto const topLeftFxItem = findFxTableItem(0, 0, items); - QVERIFY(topLeftFxItem); + auto const topLeftFxItem = tableViewPrivate->loadedTableItem(QPoint(0, 0)); auto const topLeftItem = topLeftFxItem->item; // Check that the top-left item are at the corner of the view QCOMPARE(topLeftItem->x(), margins.left()); QCOMPARE(topLeftItem->y(), margins.top()); - auto const bottomRightFxItem = findLoadedBottomRightItem(items); - QVERIFY(bottomRightFxItem); + auto const bottomRightFxItem = tableViewPrivate->loadedTableItem(tableViewPrivate->loadedTable.bottomRight()); auto const bottomRightItem = bottomRightFxItem->item; auto bottomRightAttached = getAttachedObject(bottomRightItem); |