diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-04-19 13:44:55 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-04-25 13:05:57 +0000 |
commit | 4615ffda64f567774264b4b510d9125d2d711718 (patch) | |
tree | c41fe22e6a389d20f2554e8ef38e6b3a22efe7c5 /src | |
parent | e3ec871eac7ca45fdcdd7f07850f14c56ca8c7ec (diff) |
TableView: implement getAttachedObject() for convenience
This function will come in handy in later patches as well.
Change-Id: Id4d6437dcd74f5e69e43d1e56c4c5aa4f2cee462
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index b3679af801..77d6592917 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -261,6 +261,7 @@ protected: protected: inline QQmlDelegateModel *wrapperModel() const { return qobject_cast<QQmlDelegateModel*>(model); } + QQuickTableViewAttached *getAttachedObject(const QObject *object) const; int modelIndexAtCell(const QPoint &cell); QPoint cellAtModelIndex(int modelIndex); @@ -397,6 +398,12 @@ void QQuickTableViewPrivate::dumpTable() const qWarning() << "Window capture saved to:" << filename; } +QQuickTableViewAttached *QQuickTableViewPrivate::getAttachedObject(const QObject *object) const +{ + QObject *attachedObject = qmlAttachedPropertiesObject<QQuickTableView>(object); + return static_cast<QQuickTableViewAttached *>(attachedObject); +} + int QQuickTableViewPrivate::modelIndexAtCell(const QPoint &cell) { int availableRows = tableSize.height(); @@ -1357,23 +1364,20 @@ void QQuickTableViewPrivate::itemCreatedCallback(int modelIndex, QObject*) void QQuickTableViewPrivate::initItemCallback(int modelIndex, QObject *object) { Q_UNUSED(modelIndex); - QQuickItem *item = qmlobject_cast<QQuickItem *>(object); - if (!item) + auto attached = getAttachedObject(object); + if (!attached) return; - QObject *attachedObject = qmlAttachedPropertiesObject<QQuickTableView>(item); - if (QQuickTableViewAttached *attached = static_cast<QQuickTableViewAttached *>(attachedObject)) { - attached->setTableView(q_func()); - // Even though row and column is injected directly into the context of a delegate item - // from QQmlDelegateModel and its model classes, they will only return which row and - // column an item represents in the model. This might be different from which - // cell an item ends up in in the Table, if a different rows/columns has been set - // on it (which is typically the case for list models). For those cases, Table.row - // and Table.column can be helpful. - QPoint cell = cellAtModelIndex(modelIndex); - attached->setColumn(cell.x()); - attached->setRow(cell.y()); - } + // Even though row and column is injected directly into the context of a delegate item + // from QQmlDelegateModel and its model classes, they will only return which row and + // column an item represents in the model. This might be different from which + // cell an item ends up in in the Table, if a different rows/columns has been set + // on it (which is typically the case for list models). For those cases, Table.row + // and Table.column can be helpful. + QPoint cell = cellAtModelIndex(modelIndex); + attached->setTableView(q_func()); + attached->setColumn(cell.x()); + attached->setRow(cell.y()); } void QQuickTableViewPrivate::modelUpdated(const QQmlChangeSet &changeSet, bool reset) |