\bold Note: methods should only be called after the Component has completed.
*/
+/*!
+ \qmlmethod Item QtQuick2::GridView::itemAt(int x, int y)
+
+ Returns the visible item containing the point \a x, \a y in content
+ coordinates. If there is no item at the point specified, or the item is
+ not visible null is returned.
+
+ If the item is outside the visible area, null is returned, regardless of
+ whether an item will exist at that point when scrolled into view.
+
+ \bold Note: methods should only be called after the Component has completed.
+*/
+
QQuickGridViewAttached *QQuickGridView::qmlAttachedProperties(QObject *obj)
{
return new QQuickGridViewAttached(obj);
return -1;
}
+QQuickItem *QQuickItemView::itemAt(qreal x, qreal y) const
+{
+ Q_D(const QQuickItemView);
+ for (int i = 0; i < d->visibleItems.count(); ++i) {
+ const FxViewItem *item = d->visibleItems.at(i);
+ if (item->contains(x, y))
+ return item->item;
+ }
+
+ return 0;
+}
+
void QQuickItemViewPrivate::applyPendingChanges()
{
Q_Q(QQuickItemView);
Q_INVOKABLE void positionViewAtIndex(int index, int mode);
Q_INVOKABLE int indexAt(qreal x, qreal y) const;
+ Q_INVOKABLE QQuickItem *itemAt(qreal x, qreal y) const;
Q_INVOKABLE void positionViewAtBeginning();
Q_INVOKABLE void positionViewAtEnd();
\bold Note: methods should only be called after the Component has completed.
*/
+/*!
+ \qmlmethod Item QtQuick2::ListView::itemAt(int x, int y)
+
+ Returns the visible item containing the point \a x, \a y in content
+ coordinates. If there is no item at the point specified, or the item is
+ not visible null is returned.
+
+ If the item is outside the visible area, null is returned, regardless of
+ whether an item will exist at that point when scrolled into view.
+
+ \bold Note: methods should only be called after the Component has completed.
+*/
+
QQuickListViewAttached *QQuickListView::qmlAttachedProperties(QObject *obj)
{
return new QQuickListViewAttached(obj);
void header();
void header_data();
void resizeViewAndRepaint();
- void indexAt();
+ void indexAt_itemAt_data();
+ void indexAt_itemAt();
void onAdd();
void onAdd_data();
void onRemove();
delete canvas;
}
-void tst_QQuickGridView::indexAt()
+void tst_QQuickGridView::indexAt_itemAt_data()
{
+ QTest::addColumn<qreal>("x");
+ QTest::addColumn<qreal>("y");
+ QTest::addColumn<int>("index");
+
+ QTest::newRow("Item 0 - 0, 0") << 0. << 0. << 0;
+ QTest::newRow("Item 0 - 79, 59") << 79. << 59. << 0;
+ QTest::newRow("Item 1 - 80, 0") << 80. << 0. << 1;
+ QTest::newRow("Item 3 - 0, 60") << 0. << 60. << 3;
+ QTest::newRow("No Item - 240, 0") << 240. << 0. << -1;
+}
+
+void tst_QQuickGridView::indexAt_itemAt()
+{
+ QFETCH(qreal, x);
+ QFETCH(qreal, y);
+ QFETCH(int, index);
+
QQuickView *canvas = createView();
TestModel model;
QTRY_COMPARE(gridview->count(), model.count());
- QCOMPARE(gridview->indexAt(0, 0), 0);
- QCOMPARE(gridview->indexAt(79, 59), 0);
- QCOMPARE(gridview->indexAt(80, 0), 1);
- QCOMPARE(gridview->indexAt(0, 60), 3);
- QCOMPARE(gridview->indexAt(240, 0), -1);
+ QQuickItem *item = 0;
+ if (index >= 0) {
+ item = findItem<QQuickItem>(contentItem, "wrapper", index);
+ QVERIFY(item);
+ }
+ QCOMPARE(gridview->indexAt(x, y), index);
+ QVERIFY(gridview->itemAt(x, y) == item);
delete canvas;
}
void resizeDelegate();
void resizeFirstDelegate();
void QTBUG_16037();
- void indexAt();
+ void indexAt_itemAt_data();
+ void indexAt_itemAt();
void incrementalModel();
void onAdd();
void onAdd_data();
delete canvas;
}
-void tst_QQuickListView::indexAt()
+void tst_QQuickListView::indexAt_itemAt_data()
{
+ QTest::addColumn<qreal>("x");
+ QTest::addColumn<qreal>("y");
+ QTest::addColumn<int>("index");
+
+ QTest::newRow("Item 0 - 0, 0") << 0. << 0. << 0;
+ QTest::newRow("Item 0 - 0, 19") << 0. << 19. << 0;
+ QTest::newRow("Item 0 - 239, 19") << 239. << 19. << 0;
+ QTest::newRow("Item 1 - 0, 20") << 0. << 20. << 1;
+ QTest::newRow("No Item - 240, 20") << 240. << 20. << -1;
+}
+
+void tst_QQuickListView::indexAt_itemAt()
+{
+ QFETCH(qreal, x);
+ QFETCH(qreal, y);
+ QFETCH(int, index);
+
QQuickView *canvas = createView();
TestModel model;
QQuickItem *contentItem = listview->contentItem();
QTRY_VERIFY(contentItem != 0);
- QCOMPARE(listview->indexAt(0,0), 0);
- QCOMPARE(listview->indexAt(0,19), 0);
- QCOMPARE(listview->indexAt(239,19), 0);
- QCOMPARE(listview->indexAt(0,20), 1);
- QCOMPARE(listview->indexAt(240,20), -1);
+ QQuickItem *item = 0;
+ if (index >= 0) {
+ item = findItem<QQuickItem>(contentItem, "wrapper", index);
+ QVERIFY(item);
+ }
+ QCOMPARE(listview->indexAt(x,y), index);
+ QVERIFY(listview->itemAt(x,y) == item);
delete canvas;
delete testObject;