aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktableview.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2022-10-05 12:12:26 +0200
committerPaul Wicking <paul.wicking@qt.io>2022-10-14 10:13:29 +0200
commit9cefe6d6d3c16b489557e6314b14f96176c8f950 (patch)
treebf03fac106dacfaa5914822e9da5295f96774610 /src/quick/items/qquicktableview.cpp
parentc52b7fdca8e5a6fd4a14e22d47f53d301af5c316 (diff)
QQuickTableView: forward sync view calls to setColumnWidth/RowHeight
When a TableView has a sync view, the sync view will always decide the size of the rows and the columns. As such, also forward any calls to setColumnWidth/RowHeight to the sync view, otherwise it will have no effect. This is needed to e.g allow the application to resize the columns in a TableView by setting the size on the HeaderView instead. The opposite solution would be to just ignore any such assignments when having a sync view, but this would need to be documented as well, so then we might as well just forward the calls. Task-number: QTBUG-106792 Change-Id: Iadcd8c75677a69ab19fa2455274d340b5a4ad340 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quick/items/qquicktableview.cpp')
-rw-r--r--src/quick/items/qquicktableview.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp
index ba4f0e605f..74e3c9ff8b 100644
--- a/src/quick/items/qquicktableview.cpp
+++ b/src/quick/items/qquicktableview.cpp
@@ -901,6 +901,8 @@
\note The sizes you set will not be cleared if you change the \l model.
To clear the sizes, you need to call \l clearColumnWidths() explicitly.
+ \include tableview.qdocinc explicit-column-size-and-syncview
+
\note For models with \e lots of columns, using \l setColumnWidth() to set the widths for
all the columns at start-up, can be suboptimal. This will consume start-up time and
memory (for storing all the widths). A more scalable approach is to use a
@@ -916,6 +918,8 @@
Clears all the column widths set with \l setColumnWidth().
+ \include tableview.qdocinc explicit-column-size-and-syncview
+
\sa setColumnWidth(), clearRowHeights(), {Row heights and column widths}
*/
@@ -930,6 +934,8 @@
A return value equal to \c -1 means that no explicit width has been set
for the column.
+ \include tableview.qdocinc explicit-column-size-and-syncview
+
\sa setColumnWidth(), columnWidth(), {Row heights and column widths}
*/
@@ -967,6 +973,8 @@
\note The sizes you set will not be cleared if you change the \l model.
To clear the sizes, you need to call \l clearRowHeights() explicitly.
+ \include tableview.qdocinc explicit-row-size-and-syncview
+
\note For models with \e lots of rows, using \l setRowHeight() to set the heights for
all the rows at start-up, can be suboptimal. This will consume start-up time and
memory (for storing all the heights). A more scalable approach is to use a
@@ -982,6 +990,8 @@
Clears all the row heights set with \l setRowHeight().
+ \include tableview.qdocinc explicit-row-size-and-syncview
+
\sa setRowHeight(), clearColumnWidths(), {Row heights and column widths}
*/
@@ -996,6 +1006,8 @@
A return value equal to \c -1 means that no explicit height has been set
for the row.
+ \include tableview.qdocinc explicit-row-size-and-syncview
+
\sa setRowHeight(), rowHeight(), {Row heights and column widths}
*/
@@ -5028,6 +5040,11 @@ void QQuickTableView::setColumnWidth(int column, qreal size)
return;
}
+ if (d->syncHorizontally) {
+ d->syncView->setColumnWidth(column, size);
+ return;
+ }
+
if (qFuzzyCompare(explicitColumnWidth(column), size))
return;
@@ -5036,6 +5053,9 @@ void QQuickTableView::setColumnWidth(int column, qreal size)
else
d->explicitColumnWidths.insert(column, size);
+ if (d->loadedItems.isEmpty())
+ return;
+
const bool allColumnsLoaded = d->atTableEnd(Qt::LeftEdge) && d->atTableEnd(Qt::RightEdge);
if (column >= leftColumn() || column <= rightColumn() || allColumnsLoaded)
d->forceLayout(false);
@@ -5045,6 +5065,11 @@ void QQuickTableView::clearColumnWidths()
{
Q_D(QQuickTableView);
+ if (d->syncHorizontally) {
+ d->syncView->clearColumnWidths();
+ return;
+ }
+
if (d->explicitColumnWidths.isEmpty())
return;
@@ -5055,6 +5080,10 @@ void QQuickTableView::clearColumnWidths()
qreal QQuickTableView::explicitColumnWidth(int column) const
{
Q_D(const QQuickTableView);
+
+ if (d->syncHorizontally)
+ return d->syncView->explicitColumnWidth(column);
+
const auto it = d->explicitColumnWidths.constFind(column);
if (it != d->explicitColumnWidths.constEnd())
return *it;
@@ -5069,6 +5098,11 @@ void QQuickTableView::setRowHeight(int row, qreal size)
return;
}
+ if (d->syncVertically) {
+ d->syncView->setRowHeight(row, size);
+ return;
+ }
+
if (qFuzzyCompare(explicitRowHeight(row), size))
return;
@@ -5077,6 +5111,9 @@ void QQuickTableView::setRowHeight(int row, qreal size)
else
d->explicitRowHeights.insert(row, size);
+ if (d->loadedItems.isEmpty())
+ return;
+
const bool allRowsLoaded = d->atTableEnd(Qt::TopEdge) && d->atTableEnd(Qt::BottomEdge);
if (row >= topRow() || row <= bottomRow() || allRowsLoaded)
d->forceLayout(false);
@@ -5086,6 +5123,11 @@ void QQuickTableView::clearRowHeights()
{
Q_D(QQuickTableView);
+ if (d->syncVertically) {
+ d->syncView->clearRowHeights();
+ return;
+ }
+
if (d->explicitRowHeights.isEmpty())
return;
@@ -5096,6 +5138,10 @@ void QQuickTableView::clearRowHeights()
qreal QQuickTableView::explicitRowHeight(int row) const
{
Q_D(const QQuickTableView);
+
+ if (d->syncVertically)
+ return d->syncView->explicitRowHeight(row);
+
const auto it = d->explicitRowHeights.constFind(row);
if (it != d->explicitRowHeights.constEnd())
return *it;