diff options
Diffstat (limited to 'src/quick/items')
-rw-r--r-- | src/quick/items/qquickitemsmodule.cpp | 3 | ||||
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 75 | ||||
-rw-r--r-- | src/quick/items/qquicktableview_p.h | 10 | ||||
-rw-r--r-- | src/quick/items/qquicktableview_p_p.h | 8 |
4 files changed, 96 insertions, 0 deletions
diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index cd5cca5ac9..a6dce33f45 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -475,6 +475,9 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterUncreatableType<QQuickItemView, 13>(uri, 2, 13, itemViewName, itemViewMessage); qmlRegisterType<QQuickPathView, 13>(uri, 2, 13, "PathView"); qmlRegisterType<QQuickGridView, 13>(uri, 2, 13, "GridView"); +#if QT_CONFIG(quick_tableview) + qmlRegisterType<QQuickTableView, 14>(uri, 2, 14, "TableView"); +#endif } static void initResources() diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index 1dca5bea4a..fc7516ec66 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -1855,9 +1855,14 @@ void QQuickTableViewPrivate::syncWithPendingChanges() // such assignments into effect until we're in a state that allows it. Q_Q(QQuickTableView); viewportRect = QRectF(q->contentX(), q->contentY(), q->width(), q->height()); + + // Sync rebuild options first, in case we schedule a rebuild from one of the + // other sync calls above. If so, we need to start a new rebuild from the top. syncRebuildOptions(); + syncModel(); syncDelegate(); + syncSyncView(); } void QQuickTableViewPrivate::syncRebuildOptions() @@ -1922,6 +1927,41 @@ void QQuickTableViewPrivate::syncModel() connectToModel(); } +void QQuickTableViewPrivate::syncSyncView() +{ + Q_Q(QQuickTableView); + + if (assignedSyncView != syncView) { + if (syncView) + syncView->d_func()->syncChildren.removeOne(q); + + if (assignedSyncView) { + QQuickTableView *view = assignedSyncView; + + while (view) { + if (view == q) { + if (!layoutWarningIssued) { + layoutWarningIssued = true; + qmlWarning(q) << "TableView: recursive syncView connection detected!"; + } + syncView = nullptr; + return; + } + view = view->d_func()->syncView; + } + + assignedSyncView->d_func()->syncChildren.append(q); + scheduledRebuildOptions |= RebuildOption::ViewportOnly; + q->polish(); + } + + syncView = assignedSyncView; + } + + syncHorizontally = syncView && assignedSyncDirection & Qt::Horizontal; + syncVertically = syncView && assignedSyncDirection & Qt::Vertical; +} + void QQuickTableViewPrivate::connectToModel() { Q_TABLEVIEW_ASSERT(model, ""); @@ -2214,6 +2254,41 @@ void QQuickTableView::setContentHeight(qreal height) QQuickFlickable::setContentHeight(height); } +QQuickTableView *QQuickTableView::syncView() const +{ + return d_func()->assignedSyncView; +} + +void QQuickTableView::setSyncView(QQuickTableView *view) +{ + Q_D(QQuickTableView); + if (d->assignedSyncView == view) + return; + + d->assignedSyncView = view; + d->scheduleRebuildTable(QQuickTableViewPrivate::RebuildOption::ViewportOnly); + + emit syncViewChanged(); +} + +Qt::Orientations QQuickTableView::syncDirection() const +{ + return d_func()->assignedSyncDirection; +} + +void QQuickTableView::setSyncDirection(Qt::Orientations direction) +{ + Q_D(QQuickTableView); + if (d->assignedSyncDirection == direction) + return; + + d->assignedSyncDirection = direction; + if (d->assignedSyncView) + d->scheduleRebuildTable(QQuickTableViewPrivate::RebuildOption::ViewportOnly); + + emit syncDirectionChanged(); +} + void QQuickTableView::forceLayout() { d_func()->forceLayout(); diff --git a/src/quick/items/qquicktableview_p.h b/src/quick/items/qquicktableview_p.h index f32c71b983..3d46221574 100644 --- a/src/quick/items/qquicktableview_p.h +++ b/src/quick/items/qquicktableview_p.h @@ -79,6 +79,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickTableView : public QQuickFlickable Q_PROPERTY(bool reuseItems READ reuseItems WRITE setReuseItems NOTIFY reuseItemsChanged) Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged) Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged) + Q_PROPERTY(QQuickTableView *syncView READ syncView WRITE setSyncView NOTIFY syncViewChanged REVISION 14) + Q_PROPERTY(Qt::Orientations syncDirection READ syncDirection WRITE setSyncDirection NOTIFY syncDirectionChanged REVISION 14) public: QQuickTableView(QQuickItem *parent = nullptr); @@ -110,6 +112,12 @@ public: void setContentWidth(qreal width); void setContentHeight(qreal height); + QQuickTableView *syncView() const; + void setSyncView(QQuickTableView *view); + + Qt::Orientations syncDirection() const; + void setSyncDirection(Qt::Orientations direction); + Q_INVOKABLE void forceLayout(); static QQuickTableViewAttached *qmlAttachedProperties(QObject *); @@ -124,6 +132,8 @@ Q_SIGNALS: void modelChanged(); void delegateChanged(); void reuseItemsChanged(); + Q_REVISION(14) void syncViewChanged(); + Q_REVISION(14) void syncDirectionChanged(); protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; diff --git a/src/quick/items/qquicktableview_p_p.h b/src/quick/items/qquicktableview_p_p.h index 6bbfd4e2d6..c018356efa 100644 --- a/src/quick/items/qquicktableview_p_p.h +++ b/src/quick/items/qquicktableview_p_p.h @@ -249,6 +249,8 @@ public: bool blockItemCreatedCallback = false; bool layoutWarningIssued = false; bool polishing = false; + bool syncVertically = false; + bool syncHorizontally = false; QJSValue rowHeightProvider; QJSValue columnWidthProvider; @@ -271,6 +273,11 @@ public: QSizeF averageEdgeSize; + QPointer<QQuickTableView> assignedSyncView; + QPointer<QQuickTableView> syncView; + QList<QPointer<QQuickTableView> > syncChildren; + Qt::Orientations assignedSyncDirection = Qt::Horizontal | Qt::Vertical; + const static QPoint kLeft; const static QPoint kRight; const static QPoint kUp; @@ -369,6 +376,7 @@ public: inline void syncDelegate(); inline void syncModel(); inline void syncRebuildOptions(); + inline void syncSyncView(); void connectToModel(); void disconnectFromModel(); |