| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquicktableview.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2018 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qquicktableview_p.h" | - | ||||||||||||||||||
| 41 | #include "qquicktableview_p_p.h" | - | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | #include <QtCore/qtimer.h> | - | ||||||||||||||||||
| 44 | #include <QtQml/private/qqmldelegatemodel_p.h> | - | ||||||||||||||||||
| 45 | #include <QtQml/private/qqmldelegatemodel_p_p.h> | - | ||||||||||||||||||
| 46 | #include <QtQml/private/qqmlincubator_p.h> | - | ||||||||||||||||||
| 47 | #include <QtQml/private/qqmlchangeset_p.h> | - | ||||||||||||||||||
| 48 | #include <QtQml/qqmlinfo.h> | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | #include <QtQuick/private/qquickflickable_p_p.h> | - | ||||||||||||||||||
| 51 | #include <QtQuick/private/qquickitemviewfxitem_p_p.h> | - | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | Q_LOGGING_CATEGORY(lcTableViewDelegateLifecycle, "qt.quick.tableview.lifecycle") executed 306 times by 1 test: return category;Executed by:
| 306 | ||||||||||||||||||
| 56 | - | |||||||||||||||||||
| 57 | #define Q_TABLEVIEW_UNREACHABLE(output) { dumpTable(); qWarning() << "output:" << output; Q_UNREACHABLE(); } | - | ||||||||||||||||||
| 58 | #define Q_TABLEVIEW_ASSERT(cond, output) Q_ASSERT(cond || [&](){ dumpTable(); qWarning() << "output:" << output; return false;}()) | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | static const Qt::Edge allTableEdges[] = { Qt::LeftEdge, Qt::RightEdge, Qt::TopEdge, Qt::BottomEdge }; | - | ||||||||||||||||||
| 61 | static const int kBufferTimerInterval = 300; | - | ||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | static QLine rectangleEdge(const QRect &rect, Qt::Edge tableEdge) | - | ||||||||||||||||||
| 64 | { | - | ||||||||||||||||||
| 65 | switch (tableEdge) { | - | ||||||||||||||||||
| 66 | case Qt::LeftEdge: never executed: case Qt::LeftEdge: | 0 | ||||||||||||||||||
| 67 | return QLine(rect.topLeft(), rect.bottomLeft()); never executed: return QLine(rect.topLeft(), rect.bottomLeft()); | 0 | ||||||||||||||||||
| 68 | case Qt::RightEdge: never executed: case Qt::RightEdge: | 0 | ||||||||||||||||||
| 69 | return QLine(rect.topRight(), rect.bottomRight()); never executed: return QLine(rect.topRight(), rect.bottomRight()); | 0 | ||||||||||||||||||
| 70 | case Qt::TopEdge: never executed: case Qt::TopEdge: | 0 | ||||||||||||||||||
| 71 | return QLine(rect.topLeft(), rect.topRight()); never executed: return QLine(rect.topLeft(), rect.topRight()); | 0 | ||||||||||||||||||
| 72 | case Qt::BottomEdge: never executed: case Qt::BottomEdge: | 0 | ||||||||||||||||||
| 73 | return QLine(rect.bottomLeft(), rect.bottomRight()); never executed: return QLine(rect.bottomLeft(), rect.bottomRight()); | 0 | ||||||||||||||||||
| 74 | } | - | ||||||||||||||||||
| 75 | return QLine(); never executed: return QLine(); | 0 | ||||||||||||||||||
| 76 | } | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | static QRect expandedRect(const QRect &rect, Qt::Edge edge, int increment) | - | ||||||||||||||||||
| 79 | { | - | ||||||||||||||||||
| 80 | switch (edge) { | - | ||||||||||||||||||
| 81 | case Qt::LeftEdge: never executed: case Qt::LeftEdge: | 0 | ||||||||||||||||||
| 82 | return rect.adjusted(-increment, 0, 0, 0); never executed: return rect.adjusted(-increment, 0, 0, 0); | 0 | ||||||||||||||||||
| 83 | case Qt::RightEdge: never executed: case Qt::RightEdge: | 0 | ||||||||||||||||||
| 84 | return rect.adjusted(0, 0, increment, 0); never executed: return rect.adjusted(0, 0, increment, 0); | 0 | ||||||||||||||||||
| 85 | case Qt::TopEdge: never executed: case Qt::TopEdge: | 0 | ||||||||||||||||||
| 86 | return rect.adjusted(0, -increment, 0, 0); never executed: return rect.adjusted(0, -increment, 0, 0); | 0 | ||||||||||||||||||
| 87 | case Qt::BottomEdge: never executed: case Qt::BottomEdge: | 0 | ||||||||||||||||||
| 88 | return rect.adjusted(0, 0, 0, increment); never executed: return rect.adjusted(0, 0, 0, increment); | 0 | ||||||||||||||||||
| 89 | } | - | ||||||||||||||||||
| 90 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||||||||
| 91 | } | - | ||||||||||||||||||
| 92 | - | |||||||||||||||||||
| 93 | const QPoint QQuickTableViewPrivate::kLeft = QPoint(-1, 0); | - | ||||||||||||||||||
| 94 | const QPoint QQuickTableViewPrivate::kRight = QPoint(1, 0); | - | ||||||||||||||||||
| 95 | const QPoint QQuickTableViewPrivate::kUp = QPoint(0, -1); | - | ||||||||||||||||||
| 96 | const QPoint QQuickTableViewPrivate::kDown = QPoint(0, 1); | - | ||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | QQuickTableViewPrivate::QQuickTableViewPrivate() | - | ||||||||||||||||||
| 99 | : QQuickFlickablePrivate() | - | ||||||||||||||||||
| 100 | { | - | ||||||||||||||||||
| 101 | cacheBufferDelayTimer.setSingleShot(true); | - | ||||||||||||||||||
| 102 | QObject::connect(&cacheBufferDelayTimer, &QTimer::timeout, [=]{ loadBuffer(); }); never executed: end of block | 0 | ||||||||||||||||||
| 103 | } executed 102 times by 1 test: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | QQuickTableViewPrivate::~QQuickTableViewPrivate() | - | ||||||||||||||||||
| 106 | { | - | ||||||||||||||||||
| 107 | clear(); | - | ||||||||||||||||||
| 108 | } executed 102 times by 1 test: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 109 | - | |||||||||||||||||||
| 110 | QString QQuickTableViewPrivate::tableLayoutToString() const | - | ||||||||||||||||||
| 111 | { | - | ||||||||||||||||||
| 112 | return QString(QLatin1String("table cells: (%1,%2) -> (%3,%4), item count: %5, table rect: %6,%7 x %8,%9")) never executed: return QString(QLatin1String("table cells: (%1,%2) -> (%3,%4), item count: %5, table rect: %6,%7 x %8,%9")) .arg(loadedTable.topLeft().x()).arg(loadedTable.topLeft().y()) .arg(loadedTable.bottomRight().x()).arg(loadedTable.bottomRight().y()) .arg(loadedItems.count()) .arg(loadedTableOuterRect.x()) .arg(loadedTableOuterRect.y()) .arg(loadedTableOuterRect.width()) .arg(loadedTableOuterRect.height()); | 0 | ||||||||||||||||||
| 113 | .arg(loadedTable.topLeft().x()).arg(loadedTable.topLeft().y()) never executed: return QString(QLatin1String("table cells: (%1,%2) -> (%3,%4), item count: %5, table rect: %6,%7 x %8,%9")) .arg(loadedTable.topLeft().x()).arg(loadedTable.topLeft().y()) .arg(loadedTable.bottomRight().x()).arg(loadedTable.bottomRight().y()) .arg(loadedItems.count()) .arg(loadedTableOuterRect.x()) .arg(loadedTableOuterRect.y()) .arg(loadedTableOuterRect.width()) .arg(loadedTableOuterRect.height()); | 0 | ||||||||||||||||||
| 114 | .arg(loadedTable.bottomRight().x()).arg(loadedTable.bottomRight().y()) never executed: return QString(QLatin1String("table cells: (%1,%2) -> (%3,%4), item count: %5, table rect: %6,%7 x %8,%9")) .arg(loadedTable.topLeft().x()).arg(loadedTable.topLeft().y()) .arg(loadedTable.bottomRight().x()).arg(loadedTable.bottomRight().y()) .arg(loadedItems.count()) .arg(loadedTableOuterRect.x()) .arg(loadedTableOuterRect.y()) .arg(loadedTableOuterRect.width()) .arg(loadedTableOuterRect.height()); | 0 | ||||||||||||||||||
| 115 | .arg(loadedItems.count()) never executed: return QString(QLatin1String("table cells: (%1,%2) -> (%3,%4), item count: %5, table rect: %6,%7 x %8,%9")) .arg(loadedTable.topLeft().x()).arg(loadedTable.topLeft().y()) .arg(loadedTable.bottomRight().x()).arg(loadedTable.bottomRight().y()) .arg(loadedItems.count()) .arg(loadedTableOuterRect.x()) .arg(loadedTableOuterRect.y()) .arg(loadedTableOuterRect.width()) .arg(loadedTableOuterRect.height()); | 0 | ||||||||||||||||||
| 116 | .arg(loadedTableOuterRect.x()) never executed: return QString(QLatin1String("table cells: (%1,%2) -> (%3,%4), item count: %5, table rect: %6,%7 x %8,%9")) .arg(loadedTable.topLeft().x()).arg(loadedTable.topLeft().y()) .arg(loadedTable.bottomRight().x()).arg(loadedTable.bottomRight().y()) .arg(loadedItems.count()) .arg(loadedTableOuterRect.x()) .arg(loadedTableOuterRect.y()) .arg(loadedTableOuterRect.width()) .arg(loadedTableOuterRect.height()); | 0 | ||||||||||||||||||
| 117 | .arg(loadedTableOuterRect.y()) never executed: return QString(QLatin1String("table cells: (%1,%2) -> (%3,%4), item count: %5, table rect: %6,%7 x %8,%9")) .arg(loadedTable.topLeft().x()).arg(loadedTable.topLeft().y()) .arg(loadedTable.bottomRight().x()).arg(loadedTable.bottomRight().y()) .arg(loadedItems.count()) .arg(loadedTableOuterRect.x()) .arg(loadedTableOuterRect.y()) .arg(loadedTableOuterRect.width()) .arg(loadedTableOuterRect.height()); | 0 | ||||||||||||||||||
| 118 | .arg(loadedTableOuterRect.width()) never executed: return QString(QLatin1String("table cells: (%1,%2) -> (%3,%4), item count: %5, table rect: %6,%7 x %8,%9")) .arg(loadedTable.topLeft().x()).arg(loadedTable.topLeft().y()) .arg(loadedTable.bottomRight().x()).arg(loadedTable.bottomRight().y()) .arg(loadedItems.count()) .arg(loadedTableOuterRect.x()) .arg(loadedTableOuterRect.y()) .arg(loadedTableOuterRect.width()) .arg(loadedTableOuterRect.height()); | 0 | ||||||||||||||||||
| 119 | .arg(loadedTableOuterRect.height()); never executed: return QString(QLatin1String("table cells: (%1,%2) -> (%3,%4), item count: %5, table rect: %6,%7 x %8,%9")) .arg(loadedTable.topLeft().x()).arg(loadedTable.topLeft().y()) .arg(loadedTable.bottomRight().x()).arg(loadedTable.bottomRight().y()) .arg(loadedItems.count()) .arg(loadedTableOuterRect.x()) .arg(loadedTableOuterRect.y()) .arg(loadedTableOuterRect.width()) .arg(loadedTableOuterRect.height()); | 0 | ||||||||||||||||||
| 120 | } | - | ||||||||||||||||||
| 121 | - | |||||||||||||||||||
| 122 | void QQuickTableViewPrivate::dumpTable() const | - | ||||||||||||||||||
| 123 | { | - | ||||||||||||||||||
| 124 | auto listCopy = loadedItems.values(); | - | ||||||||||||||||||
| 125 | std::stable_sort(listCopy.begin(), listCopy.end(), | - | ||||||||||||||||||
| 126 | [](const FxTableItem *lhs, const FxTableItem *rhs) | - | ||||||||||||||||||
| 127 | { return lhs->index < rhs->index; }); never executed: return lhs->index < rhs->index; | 0 | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | qWarning() << QStringLiteral("******* TABLE DUMP *******"); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 130 | for (int i = 0; i < listCopy.count(); ++i)
| 0 | ||||||||||||||||||
| 131 | qWarning() << static_cast<FxTableItem *>(listCopy.at(i))->cell; never executed: QMessageLogger(__FILE__, 131, __PRETTY_FUNCTION__).warning() << static_cast<FxTableItem *>(listCopy.at(i))->cell; | 0 | ||||||||||||||||||
| 132 | qWarning() << tableLayoutToString(); | - | ||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | QString filename = QStringLiteral("QQuickTableView_dumptable_capture.png"); | - | ||||||||||||||||||
| 135 | if (q_func()->window()->grabWindow().save(filename))
| 0 | ||||||||||||||||||
| 136 | qWarning() << "Window capture saved to:" << filename; never executed: QMessageLogger(__FILE__, 136, __PRETTY_FUNCTION__).warning() << "Window capture saved to:" << filename; | 0 | ||||||||||||||||||
| 137 | } never executed: end of block | 0 | ||||||||||||||||||
| 138 | - | |||||||||||||||||||
| 139 | QQuickTableViewAttached *QQuickTableViewPrivate::getAttachedObject(const QObject *object) const | - | ||||||||||||||||||
| 140 | { | - | ||||||||||||||||||
| 141 | QObject *attachedObject = qmlAttachedPropertiesObject<QQuickTableView>(object); | - | ||||||||||||||||||
| 142 | return static_cast<QQuickTableViewAttached *>(attachedObject); never executed: return static_cast<QQuickTableViewAttached *>(attachedObject); | 0 | ||||||||||||||||||
| 143 | } | - | ||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | int QQuickTableViewPrivate::modelIndexAtCell(const QPoint &cell) const | - | ||||||||||||||||||
| 146 | { | - | ||||||||||||||||||
| 147 | int availableRows = tableSize.height(); | - | ||||||||||||||||||
| 148 | int modelIndex = cell.y() + (cell.x() * availableRows); | - | ||||||||||||||||||
| 149 | Q_TABLEVIEW_ASSERT(modelIndex < model->count(), modelIndex << cell); never executed: return false; | 0 | ||||||||||||||||||
| 150 | return modelIndex; never executed: return modelIndex; | 0 | ||||||||||||||||||
| 151 | } | - | ||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | QPoint QQuickTableViewPrivate::cellAtModelIndex(int modelIndex) const | - | ||||||||||||||||||
| 154 | { | - | ||||||||||||||||||
| 155 | int availableRows = tableSize.height(); | - | ||||||||||||||||||
| 156 | Q_TABLEVIEW_ASSERT(availableRows > 0, availableRows); never executed: return false; | 0 | ||||||||||||||||||
| 157 | int column = int(modelIndex / availableRows); | - | ||||||||||||||||||
| 158 | int row = modelIndex % availableRows; | - | ||||||||||||||||||
| 159 | return QPoint(column, row); never executed: return QPoint(column, row); | 0 | ||||||||||||||||||
| 160 | } | - | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | void QQuickTableViewPrivate::updateContentWidth() | - | ||||||||||||||||||
| 163 | { | - | ||||||||||||||||||
| 164 | Q_Q(QQuickTableView); | - | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | const qreal thresholdBeforeAdjust = 0.1; | - | ||||||||||||||||||
| 167 | int currentRightColumn = loadedTable.right(); | - | ||||||||||||||||||
| 168 | - | |||||||||||||||||||
| 169 | if (currentRightColumn > contentSizeBenchMarkPoint.x()) {
| 0-204 | ||||||||||||||||||
| 170 | contentSizeBenchMarkPoint.setX(currentRightColumn); | - | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | qreal currentWidth = loadedTableOuterRect.right(); | - | ||||||||||||||||||
| 173 | qreal averageCellSize = currentWidth / (currentRightColumn + 1); | - | ||||||||||||||||||
| 174 | qreal averageSize = averageCellSize + cellSpacing.width(); | - | ||||||||||||||||||
| 175 | qreal estimatedWith = (tableSize.width() * averageSize) - cellSpacing.width(); | - | ||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | // loadedTableOuterRect has already been adjusted for left margin | - | ||||||||||||||||||
| 178 | currentWidth += tableMargins.right(); | - | ||||||||||||||||||
| 179 | estimatedWith += tableMargins.right(); | - | ||||||||||||||||||
| 180 | - | |||||||||||||||||||
| 181 | if (currentRightColumn >= tableSize.width() - 1) {
| 0 | ||||||||||||||||||
| 182 | // We are at the last column, and can set the exact width | - | ||||||||||||||||||
| 183 | if (currentWidth != q->implicitWidth())
| 0 | ||||||||||||||||||
| 184 | q->setContentWidth(currentWidth); never executed: q->setContentWidth(currentWidth); | 0 | ||||||||||||||||||
| 185 | } else if (currentWidth >= q->implicitWidth()) { never executed: end of block
| 0 | ||||||||||||||||||
| 186 | // We are at the estimated width, but there are still more columns | - | ||||||||||||||||||
| 187 | q->setContentWidth(estimatedWith); | - | ||||||||||||||||||
| 188 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 189 | // Only set a new width if the new estimate is substantially different | - | ||||||||||||||||||
| 190 | qreal diff = 1 - (estimatedWith / q->implicitWidth()); | - | ||||||||||||||||||
| 191 | if (qAbs(diff) > thresholdBeforeAdjust)
| 0 | ||||||||||||||||||
| 192 | q->setContentWidth(estimatedWith); never executed: q->setContentWidth(estimatedWith); | 0 | ||||||||||||||||||
| 193 | } never executed: end of block | 0 | ||||||||||||||||||
| 194 | } | - | ||||||||||||||||||
| 195 | } executed 204 times by 1 test: end of blockExecuted by:
| 204 | ||||||||||||||||||
| 196 | - | |||||||||||||||||||
| 197 | void QQuickTableViewPrivate::updateContentHeight() | - | ||||||||||||||||||
| 198 | { | - | ||||||||||||||||||
| 199 | Q_Q(QQuickTableView); | - | ||||||||||||||||||
| 200 | - | |||||||||||||||||||
| 201 | const qreal thresholdBeforeAdjust = 0.1; | - | ||||||||||||||||||
| 202 | int currentBottomRow = loadedTable.bottom(); | - | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | if (currentBottomRow > contentSizeBenchMarkPoint.y()) {
| 0-204 | ||||||||||||||||||
| 205 | contentSizeBenchMarkPoint.setY(currentBottomRow); | - | ||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | qreal currentHeight = loadedTableOuterRect.bottom(); | - | ||||||||||||||||||
| 208 | qreal averageCellSize = currentHeight / (currentBottomRow + 1); | - | ||||||||||||||||||
| 209 | qreal averageSize = averageCellSize + cellSpacing.height(); | - | ||||||||||||||||||
| 210 | qreal estimatedHeight = (tableSize.height() * averageSize) - cellSpacing.height(); | - | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | // loadedTableOuterRect has already been adjusted for top margin | - | ||||||||||||||||||
| 213 | currentHeight += tableMargins.bottom(); | - | ||||||||||||||||||
| 214 | estimatedHeight += tableMargins.bottom(); | - | ||||||||||||||||||
| 215 | - | |||||||||||||||||||
| 216 | if (currentBottomRow >= tableSize.height() - 1) {
| 0 | ||||||||||||||||||
| 217 | // We are at the last row, and can set the exact height | - | ||||||||||||||||||
| 218 | if (currentHeight != q->implicitHeight())
| 0 | ||||||||||||||||||
| 219 | q->setContentHeight(currentHeight); never executed: q->setContentHeight(currentHeight); | 0 | ||||||||||||||||||
| 220 | } else if (currentHeight >= q->implicitHeight()) { never executed: end of block
| 0 | ||||||||||||||||||
| 221 | // We are at the estimated height, but there are still more rows | - | ||||||||||||||||||
| 222 | q->setContentHeight(estimatedHeight); | - | ||||||||||||||||||
| 223 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 224 | // Only set a new height if the new estimate is substantially different | - | ||||||||||||||||||
| 225 | qreal diff = 1 - (estimatedHeight / q->implicitHeight()); | - | ||||||||||||||||||
| 226 | if (qAbs(diff) > thresholdBeforeAdjust)
| 0 | ||||||||||||||||||
| 227 | q->setContentHeight(estimatedHeight); never executed: q->setContentHeight(estimatedHeight); | 0 | ||||||||||||||||||
| 228 | } never executed: end of block | 0 | ||||||||||||||||||
| 229 | } | - | ||||||||||||||||||
| 230 | } executed 204 times by 1 test: end of blockExecuted by:
| 204 | ||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | void QQuickTableViewPrivate::enforceFirstRowColumnAtOrigo() | - | ||||||||||||||||||
| 233 | { | - | ||||||||||||||||||
| 234 | // Gaps before the first row/column can happen if rows/columns | - | ||||||||||||||||||
| 235 | // changes size while flicking e.g because of spacing changes or | - | ||||||||||||||||||
| 236 | // changes to a column maxWidth/row maxHeight. Check for this, and | - | ||||||||||||||||||
| 237 | // move the whole table rect accordingly. | - | ||||||||||||||||||
| 238 | bool layoutNeeded = false; | - | ||||||||||||||||||
| 239 | const qreal flickMargin = 50; | - | ||||||||||||||||||
| 240 | - | |||||||||||||||||||
| 241 | if (loadedTable.x() == 0 && loadedTableOuterRect.x() != tableMargins.left()) {
| 0 | ||||||||||||||||||
| 242 | // The table is at the beginning, but not at the edge of the | - | ||||||||||||||||||
| 243 | // content view. So move the table to origo. | - | ||||||||||||||||||
| 244 | loadedTableOuterRect.moveLeft(tableMargins.left()); | - | ||||||||||||||||||
| 245 | layoutNeeded = true; | - | ||||||||||||||||||
| 246 | } else if (loadedTableOuterRect.x() < 0) { never executed: end of block
| 0 | ||||||||||||||||||
| 247 | // The table is outside the beginning of the content view. Move | - | ||||||||||||||||||
| 248 | // the whole table inside, and make some room for flicking. | - | ||||||||||||||||||
| 249 | loadedTableOuterRect.moveLeft(tableMargins.left() + loadedTable.x() == 0 ? 0 : flickMargin); | - | ||||||||||||||||||
| 250 | layoutNeeded = true; | - | ||||||||||||||||||
| 251 | } never executed: end of block | 0 | ||||||||||||||||||
| 252 | - | |||||||||||||||||||
| 253 | if (loadedTable.y() == 0 && loadedTableOuterRect.y() != tableMargins.top()) {
| 0 | ||||||||||||||||||
| 254 | loadedTableOuterRect.moveTop(tableMargins.top()); | - | ||||||||||||||||||
| 255 | layoutNeeded = true; | - | ||||||||||||||||||
| 256 | } else if (loadedTableOuterRect.y() < 0) { never executed: end of block
| 0 | ||||||||||||||||||
| 257 | loadedTableOuterRect.moveTop(tableMargins.top() + loadedTable.y() == 0 ? 0 : flickMargin); | - | ||||||||||||||||||
| 258 | layoutNeeded = true; | - | ||||||||||||||||||
| 259 | } never executed: end of block | 0 | ||||||||||||||||||
| 260 | - | |||||||||||||||||||
| 261 | if (layoutNeeded)
| 0 | ||||||||||||||||||
| 262 | relayoutTableItems(); never executed: relayoutTableItems(); | 0 | ||||||||||||||||||
| 263 | } never executed: end of block | 0 | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | void QQuickTableViewPrivate::syncLoadedTableRectFromLoadedTable() | - | ||||||||||||||||||
| 266 | { | - | ||||||||||||||||||
| 267 | QRectF topLeftRect = loadedTableItem(loadedTable.topLeft())->geometry(); | - | ||||||||||||||||||
| 268 | QRectF bottomRightRect = loadedTableItem(loadedTable.bottomRight())->geometry(); | - | ||||||||||||||||||
| 269 | loadedTableOuterRect = topLeftRect.united(bottomRightRect); | - | ||||||||||||||||||
| 270 | loadedTableInnerRect = QRectF(topLeftRect.bottomRight(), bottomRightRect.topLeft()); | - | ||||||||||||||||||
| 271 | } never executed: end of block | 0 | ||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | void QQuickTableViewPrivate::syncLoadedTableFromLoadRequest() | - | ||||||||||||||||||
| 274 | { | - | ||||||||||||||||||
| 275 | switch (loadRequest.edge()) { | - | ||||||||||||||||||
| 276 | case Qt::LeftEdge: never executed: case Qt::LeftEdge: | 0 | ||||||||||||||||||
| 277 | case Qt::TopEdge: never executed: case Qt::TopEdge: | 0 | ||||||||||||||||||
| 278 | loadedTable.setTopLeft(loadRequest.firstCell()); | - | ||||||||||||||||||
| 279 | break; never executed: break; | 0 | ||||||||||||||||||
| 280 | case Qt::RightEdge: never executed: case Qt::RightEdge: | 0 | ||||||||||||||||||
| 281 | case Qt::BottomEdge: never executed: case Qt::BottomEdge: | 0 | ||||||||||||||||||
| 282 | loadedTable.setBottomRight(loadRequest.lastCell()); | - | ||||||||||||||||||
| 283 | break; never executed: break; | 0 | ||||||||||||||||||
| 284 | default: never executed: default: | 0 | ||||||||||||||||||
| 285 | loadedTable = QRect(loadRequest.firstCell(), loadRequest.lastCell()); | - | ||||||||||||||||||
| 286 | } never executed: end of block | 0 | ||||||||||||||||||
| 287 | } | - | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | FxTableItem *QQuickTableViewPrivate::itemNextTo(const FxTableItem *fxTableItem, const QPoint &direction) const | - | ||||||||||||||||||
| 290 | { | - | ||||||||||||||||||
| 291 | return loadedTableItem(fxTableItem->cell + direction); never executed: return loadedTableItem(fxTableItem->cell + direction); | 0 | ||||||||||||||||||
| 292 | } | - | ||||||||||||||||||
| 293 | - | |||||||||||||||||||
| 294 | FxTableItem *QQuickTableViewPrivate::loadedTableItem(const QPoint &cell) const | - | ||||||||||||||||||
| 295 | { | - | ||||||||||||||||||
| 296 | const int modelIndex = modelIndexAtCell(cell); | - | ||||||||||||||||||
| 297 | Q_TABLEVIEW_ASSERT(loadedItems.contains(modelIndex), modelIndex << cell); never executed: return false; | 0 | ||||||||||||||||||
| 298 | return loadedItems.value(modelIndex); never executed: return loadedItems.value(modelIndex); | 0 | ||||||||||||||||||
| 299 | } | - | ||||||||||||||||||
| 300 | - | |||||||||||||||||||
| 301 | FxTableItem *QQuickTableViewPrivate::createFxTableItem(const QPoint &cell, QQmlIncubator::IncubationMode incubationMode) | - | ||||||||||||||||||
| 302 | { | - | ||||||||||||||||||
| 303 | Q_Q(QQuickTableView); | - | ||||||||||||||||||
| 304 | - | |||||||||||||||||||
| 305 | bool ownItem = false; | - | ||||||||||||||||||
| 306 | int modelIndex = modelIndexAtCell(cell); | - | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | QObject* object = model->object(modelIndex, incubationMode); | - | ||||||||||||||||||
| 309 | if (!object) {
| 0 | ||||||||||||||||||
| 310 | if (model->incubationStatus(modelIndex) == QQmlIncubator::Loading) {
| 0 | ||||||||||||||||||
| 311 | // Item is incubating. Return nullptr for now, and let the table call this | - | ||||||||||||||||||
| 312 | // function again once we get a callback to itemCreatedCallback(). | - | ||||||||||||||||||
| 313 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||
| 314 | } | - | ||||||||||||||||||
| 315 | - | |||||||||||||||||||
| 316 | qWarning() << "TableView: failed loading index:" << modelIndex; | - | ||||||||||||||||||
| 317 | object = new QQuickItem(); | - | ||||||||||||||||||
| 318 | ownItem = true; | - | ||||||||||||||||||
| 319 | } never executed: end of block | 0 | ||||||||||||||||||
| 320 | - | |||||||||||||||||||
| 321 | QQuickItem *item = qmlobject_cast<QQuickItem*>(object); | - | ||||||||||||||||||
| 322 | if (!item) {
| 0 | ||||||||||||||||||
| 323 | // The model could not provide an QQuickItem for the | - | ||||||||||||||||||
| 324 | // given index, so we create a placeholder instead. | - | ||||||||||||||||||
| 325 | qWarning() << "TableView: delegate is not an item:" << modelIndex; | - | ||||||||||||||||||
| 326 | model->release(object); | - | ||||||||||||||||||
| 327 | item = new QQuickItem(); | - | ||||||||||||||||||
| 328 | ownItem = true; | - | ||||||||||||||||||
| 329 | } never executed: end of block | 0 | ||||||||||||||||||
| 330 | - | |||||||||||||||||||
| 331 | item->setParentItem(q->contentItem()); | - | ||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | FxTableItem *fxTableItem = new FxTableItem(item, q, ownItem); | - | ||||||||||||||||||
| 334 | fxTableItem->setVisible(false); | - | ||||||||||||||||||
| 335 | fxTableItem->cell = cell; | - | ||||||||||||||||||
| 336 | fxTableItem->index = modelIndex; | - | ||||||||||||||||||
| 337 | return fxTableItem; never executed: return fxTableItem; | 0 | ||||||||||||||||||
| 338 | } | - | ||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | FxTableItem *QQuickTableViewPrivate::loadFxTableItem(const QPoint &cell, QQmlIncubator::IncubationMode incubationMode) | - | ||||||||||||||||||
| 341 | { | - | ||||||||||||||||||
| 342 | #ifdef QT_DEBUG | - | ||||||||||||||||||
| 343 | // Since TableView needs to work flawlessly when e.g incubating inside an async | - | ||||||||||||||||||
| 344 | // loader, being able to override all loading to async while debugging can be helpful. | - | ||||||||||||||||||
| 345 | static const bool forcedAsync = forcedIncubationMode == QLatin1String("async"); | - | ||||||||||||||||||
| 346 | if (forcedAsync)
| 0 | ||||||||||||||||||
| 347 | incubationMode = QQmlIncubator::Asynchronous; never executed: incubationMode = QQmlIncubator::Asynchronous; | 0 | ||||||||||||||||||
| 348 | #endif | - | ||||||||||||||||||
| 349 | - | |||||||||||||||||||
| 350 | // Note that even if incubation mode is asynchronous, the item might | - | ||||||||||||||||||
| 351 | // be ready immediately since the model has a cache of items. | - | ||||||||||||||||||
| 352 | QBoolBlocker guard(blockItemCreatedCallback); | - | ||||||||||||||||||
| 353 | auto item = createFxTableItem(cell, incubationMode); | - | ||||||||||||||||||
| 354 | qCDebug(lcTableViewDelegateLifecycle) << cell << "ready?" << bool(item); never executed: QMessageLogger(__FILE__, 354, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle().categoryName()).debug() << cell << "ready?" << bool(item);
| 0 | ||||||||||||||||||
| 355 | return item; never executed: return item; | 0 | ||||||||||||||||||
| 356 | } | - | ||||||||||||||||||
| 357 | - | |||||||||||||||||||
| 358 | void QQuickTableViewPrivate::releaseLoadedItems() { | - | ||||||||||||||||||
| 359 | // Make a copy and clear the list of items first to avoid destroyed | - | ||||||||||||||||||
| 360 | // items being accessed during the loop (QTBUG-61294) | - | ||||||||||||||||||
| 361 | auto const tmpList = loadedItems; | - | ||||||||||||||||||
| 362 | loadedItems.clear(); | - | ||||||||||||||||||
| 363 | for (FxTableItem *item : tmpList) | - | ||||||||||||||||||
| 364 | releaseItem(item); never executed: releaseItem(item); | 0 | ||||||||||||||||||
| 365 | } executed 204 times by 1 test: end of blockExecuted by:
| 204 | ||||||||||||||||||
| 366 | - | |||||||||||||||||||
| 367 | void QQuickTableViewPrivate::releaseItem(FxTableItem *fxTableItem) | - | ||||||||||||||||||
| 368 | { | - | ||||||||||||||||||
| 369 | if (fxTableItem->item) {
| 0 | ||||||||||||||||||
| 370 | if (fxTableItem->ownItem)
| 0 | ||||||||||||||||||
| 371 | delete fxTableItem->item; never executed: delete fxTableItem->item; | 0 | ||||||||||||||||||
| 372 | else if (model->release(fxTableItem->item) != QQmlInstanceModel::Destroyed)
| 0 | ||||||||||||||||||
| 373 | fxTableItem->item->setParentItem(nullptr); never executed: fxTableItem->item->setParentItem(nullptr); | 0 | ||||||||||||||||||
| 374 | } never executed: end of block | 0 | ||||||||||||||||||
| 375 | - | |||||||||||||||||||
| 376 | delete fxTableItem; | - | ||||||||||||||||||
| 377 | } never executed: end of block | 0 | ||||||||||||||||||
| 378 | - | |||||||||||||||||||
| 379 | void QQuickTableViewPrivate::clear() | - | ||||||||||||||||||
| 380 | { | - | ||||||||||||||||||
| 381 | tableInvalid = true; | - | ||||||||||||||||||
| 382 | tableRebuilding = false; | - | ||||||||||||||||||
| 383 | if (loadRequest.isActive())
| 0-204 | ||||||||||||||||||
| 384 | cancelLoadRequest(); never executed: cancelLoadRequest(); | 0 | ||||||||||||||||||
| 385 | - | |||||||||||||||||||
| 386 | releaseLoadedItems(); | - | ||||||||||||||||||
| 387 | loadedTable = QRect(); | - | ||||||||||||||||||
| 388 | loadedTableOuterRect = QRect(); | - | ||||||||||||||||||
| 389 | loadedTableInnerRect = QRect(); | - | ||||||||||||||||||
| 390 | columnWidths.clear(); | - | ||||||||||||||||||
| 391 | rowHeights.clear(); | - | ||||||||||||||||||
| 392 | contentSizeBenchMarkPoint = QPoint(-1, -1); | - | ||||||||||||||||||
| 393 | - | |||||||||||||||||||
| 394 | updateContentWidth(); | - | ||||||||||||||||||
| 395 | updateContentHeight(); | - | ||||||||||||||||||
| 396 | } executed 204 times by 1 test: end of blockExecuted by:
| 204 | ||||||||||||||||||
| 397 | - | |||||||||||||||||||
| 398 | void QQuickTableViewPrivate::unloadItem(const QPoint &cell) | - | ||||||||||||||||||
| 399 | { | - | ||||||||||||||||||
| 400 | const int modelIndex = modelIndexAtCell(cell); | - | ||||||||||||||||||
| 401 | Q_TABLEVIEW_ASSERT(loadedItems.contains(modelIndex), modelIndex << cell); never executed: return false; | 0 | ||||||||||||||||||
| 402 | releaseItem(loadedItems.take(modelIndex)); | - | ||||||||||||||||||
| 403 | } never executed: end of block | 0 | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | void QQuickTableViewPrivate::unloadItems(const QLine &items) | - | ||||||||||||||||||
| 406 | { | - | ||||||||||||||||||
| 407 | qCDebug(lcTableViewDelegateLifecycle) << items; never executed: QMessageLogger(__FILE__, 407, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle().categoryName()).debug() << items;
| 0 | ||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | if (items.dx()) {
| 0 | ||||||||||||||||||
| 410 | int y = items.p1().y(); | - | ||||||||||||||||||
| 411 | for (int x = items.p1().x(); x <= items.p2().x(); ++x)
| 0 | ||||||||||||||||||
| 412 | unloadItem(QPoint(x, y)); never executed: unloadItem(QPoint(x, y)); | 0 | ||||||||||||||||||
| 413 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 414 | int x = items.p1().x(); | - | ||||||||||||||||||
| 415 | for (int y = items.p1().y(); y <= items.p2().y(); ++y)
| 0 | ||||||||||||||||||
| 416 | unloadItem(QPoint(x, y)); never executed: unloadItem(QPoint(x, y)); | 0 | ||||||||||||||||||
| 417 | } never executed: end of block | 0 | ||||||||||||||||||
| 418 | } | - | ||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | bool QQuickTableViewPrivate::canLoadTableEdge(Qt::Edge tableEdge, const QRectF fillRect) const | - | ||||||||||||||||||
| 421 | { | - | ||||||||||||||||||
| 422 | switch (tableEdge) { | - | ||||||||||||||||||
| 423 | case Qt::LeftEdge: never executed: case Qt::LeftEdge: | 0 | ||||||||||||||||||
| 424 | if (loadedTable.topLeft().x() == 0)
| 0 | ||||||||||||||||||
| 425 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 426 | return loadedTableOuterRect.left() > fillRect.left() + cellSpacing.width(); never executed: return loadedTableOuterRect.left() > fillRect.left() + cellSpacing.width(); | 0 | ||||||||||||||||||
| 427 | case Qt::RightEdge: never executed: case Qt::RightEdge: | 0 | ||||||||||||||||||
| 428 | if (loadedTable.bottomRight().x() >= tableSize.width() - 1)
| 0 | ||||||||||||||||||
| 429 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 430 | return loadedTableOuterRect.right() < fillRect.right() - cellSpacing.width(); never executed: return loadedTableOuterRect.right() < fillRect.right() - cellSpacing.width(); | 0 | ||||||||||||||||||
| 431 | case Qt::TopEdge: never executed: case Qt::TopEdge: | 0 | ||||||||||||||||||
| 432 | if (loadedTable.topLeft().y() == 0)
| 0 | ||||||||||||||||||
| 433 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 434 | return loadedTableOuterRect.top() > fillRect.top() + cellSpacing.height(); never executed: return loadedTableOuterRect.top() > fillRect.top() + cellSpacing.height(); | 0 | ||||||||||||||||||
| 435 | case Qt::BottomEdge: never executed: case Qt::BottomEdge: | 0 | ||||||||||||||||||
| 436 | if (loadedTable.bottomRight().y() >= tableSize.height() - 1)
| 0 | ||||||||||||||||||
| 437 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 438 | return loadedTableOuterRect.bottom() < fillRect.bottom() - cellSpacing.height(); never executed: return loadedTableOuterRect.bottom() < fillRect.bottom() - cellSpacing.height(); | 0 | ||||||||||||||||||
| 439 | } | - | ||||||||||||||||||
| 440 | - | |||||||||||||||||||
| 441 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 442 | } | - | ||||||||||||||||||
| 443 | - | |||||||||||||||||||
| 444 | bool QQuickTableViewPrivate::canUnloadTableEdge(Qt::Edge tableEdge, const QRectF fillRect) const | - | ||||||||||||||||||
| 445 | { | - | ||||||||||||||||||
| 446 | // Note: if there is only one row or column left, we cannot unload, since | - | ||||||||||||||||||
| 447 | // they are needed as anchor point for further layouting. | - | ||||||||||||||||||
| 448 | switch (tableEdge) { | - | ||||||||||||||||||
| 449 | case Qt::LeftEdge: never executed: case Qt::LeftEdge: | 0 | ||||||||||||||||||
| 450 | if (loadedTable.width() <= 1)
| 0 | ||||||||||||||||||
| 451 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 452 | return loadedTableInnerRect.left() < fillRect.left(); never executed: return loadedTableInnerRect.left() < fillRect.left(); | 0 | ||||||||||||||||||
| 453 | case Qt::RightEdge: never executed: case Qt::RightEdge: | 0 | ||||||||||||||||||
| 454 | if (loadedTable.width() <= 1)
| 0 | ||||||||||||||||||
| 455 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 456 | return loadedTableInnerRect.right() > fillRect.right(); never executed: return loadedTableInnerRect.right() > fillRect.right(); | 0 | ||||||||||||||||||
| 457 | case Qt::TopEdge: never executed: case Qt::TopEdge: | 0 | ||||||||||||||||||
| 458 | if (loadedTable.height() <= 1)
| 0 | ||||||||||||||||||
| 459 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 460 | return loadedTableInnerRect.top() < fillRect.top(); never executed: return loadedTableInnerRect.top() < fillRect.top(); | 0 | ||||||||||||||||||
| 461 | case Qt::BottomEdge: never executed: case Qt::BottomEdge: | 0 | ||||||||||||||||||
| 462 | if (loadedTable.height() <= 1)
| 0 | ||||||||||||||||||
| 463 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 464 | return loadedTableInnerRect.bottom() > fillRect.bottom(); never executed: return loadedTableInnerRect.bottom() > fillRect.bottom(); | 0 | ||||||||||||||||||
| 465 | } | - | ||||||||||||||||||
| 466 | Q_TABLEVIEW_UNREACHABLE(tableEdge); | - | ||||||||||||||||||
| 467 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 468 | } | - | ||||||||||||||||||
| 469 | - | |||||||||||||||||||
| 470 | Qt::Edge QQuickTableViewPrivate::nextEdgeToLoad(const QRectF rect) | - | ||||||||||||||||||
| 471 | { | - | ||||||||||||||||||
| 472 | for (Qt::Edge edge : allTableEdges) { | - | ||||||||||||||||||
| 473 | if (canLoadTableEdge(edge, rect))
| 0 | ||||||||||||||||||
| 474 | return edge; never executed: return edge; | 0 | ||||||||||||||||||
| 475 | } never executed: end of block | 0 | ||||||||||||||||||
| 476 | return Qt::Edge(0); never executed: return Qt::Edge(0); | 0 | ||||||||||||||||||
| 477 | } | - | ||||||||||||||||||
| 478 | - | |||||||||||||||||||
| 479 | Qt::Edge QQuickTableViewPrivate::nextEdgeToUnload(const QRectF rect) | - | ||||||||||||||||||
| 480 | { | - | ||||||||||||||||||
| 481 | for (Qt::Edge edge : allTableEdges) { | - | ||||||||||||||||||
| 482 | if (canUnloadTableEdge(edge, rect))
| 0 | ||||||||||||||||||
| 483 | return edge; never executed: return edge; | 0 | ||||||||||||||||||
| 484 | } never executed: end of block | 0 | ||||||||||||||||||
| 485 | return Qt::Edge(0); never executed: return Qt::Edge(0); | 0 | ||||||||||||||||||
| 486 | } | - | ||||||||||||||||||
| 487 | - | |||||||||||||||||||
| 488 | qreal QQuickTableViewPrivate::cellWidth(const QPoint& cell) | - | ||||||||||||||||||
| 489 | { | - | ||||||||||||||||||
| 490 | // If a delegate item has TableView.cellWidth set, then | - | ||||||||||||||||||
| 491 | // we prefer that. Otherwise we fall back to use implicitWidth. | - | ||||||||||||||||||
| 492 | // Using an items width directly is not an option, since we change | - | ||||||||||||||||||
| 493 | // it during layout (which would also cause problems when recycling items). | - | ||||||||||||||||||
| 494 | auto const cellItem = loadedTableItem(cell)->item; | - | ||||||||||||||||||
| 495 | if (auto const attached = getAttachedObject(cellItem)) {
| 0 | ||||||||||||||||||
| 496 | if (!attached->m_cellWidth.isNull)
| 0 | ||||||||||||||||||
| 497 | return attached->m_cellWidth; never executed: return attached->m_cellWidth; | 0 | ||||||||||||||||||
| 498 | } never executed: end of block | 0 | ||||||||||||||||||
| 499 | return cellItem->implicitWidth(); never executed: return cellItem->implicitWidth(); | 0 | ||||||||||||||||||
| 500 | } | - | ||||||||||||||||||
| 501 | - | |||||||||||||||||||
| 502 | qreal QQuickTableViewPrivate::cellHeight(const QPoint& cell) | - | ||||||||||||||||||
| 503 | { | - | ||||||||||||||||||
| 504 | // If a delegate item has TableView.cellHeight set, then | - | ||||||||||||||||||
| 505 | // we prefer that. Otherwise we fall back to use implicitHeight. | - | ||||||||||||||||||
| 506 | // Using an items height directly is not an option, since we change | - | ||||||||||||||||||
| 507 | // it during layout (which would also cause problems when recycling items). | - | ||||||||||||||||||
| 508 | auto const cellItem = loadedTableItem(cell)->item; | - | ||||||||||||||||||
| 509 | if (auto const attached = getAttachedObject(cellItem)) {
| 0 | ||||||||||||||||||
| 510 | if (!attached->m_cellHeight.isNull)
| 0 | ||||||||||||||||||
| 511 | return attached->m_cellHeight; never executed: return attached->m_cellHeight; | 0 | ||||||||||||||||||
| 512 | } never executed: end of block | 0 | ||||||||||||||||||
| 513 | return cellItem->implicitHeight(); never executed: return cellItem->implicitHeight(); | 0 | ||||||||||||||||||
| 514 | } | - | ||||||||||||||||||
| 515 | - | |||||||||||||||||||
| 516 | void QQuickTableViewPrivate::calculateColumnWidthsAfterRebuilding() | - | ||||||||||||||||||
| 517 | { | - | ||||||||||||||||||
| 518 | qreal prevColumnWidth = 0; | - | ||||||||||||||||||
| 519 | for (int column = loadedTable.left(); column <= loadedTable.right(); ++column) {
| 0 | ||||||||||||||||||
| 520 | qreal columnWidth = 0; | - | ||||||||||||||||||
| 521 | for (int row = loadedTable.top(); row <= loadedTable.bottom(); ++row)
| 0 | ||||||||||||||||||
| 522 | columnWidth = qMax(columnWidth, cellWidth(QPoint(column, row))); never executed: columnWidth = qMax(columnWidth, cellWidth(QPoint(column, row))); | 0 | ||||||||||||||||||
| 523 | - | |||||||||||||||||||
| 524 | if (columnWidth <= 0)
| 0 | ||||||||||||||||||
| 525 | columnWidth = kDefaultColumnWidth; never executed: columnWidth = kDefaultColumnWidth; | 0 | ||||||||||||||||||
| 526 | - | |||||||||||||||||||
| 527 | if (columnWidth == prevColumnWidth)
| 0 | ||||||||||||||||||
| 528 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 529 | - | |||||||||||||||||||
| 530 | columnWidths.append({column, columnWidth}); | - | ||||||||||||||||||
| 531 | prevColumnWidth = columnWidth; | - | ||||||||||||||||||
| 532 | } never executed: end of block | 0 | ||||||||||||||||||
| 533 | - | |||||||||||||||||||
| 534 | if (columnWidths.isEmpty()) {
| 0 | ||||||||||||||||||
| 535 | // Add at least one column, wo we don't need | - | ||||||||||||||||||
| 536 | // to check if the vector is empty elsewhere. | - | ||||||||||||||||||
| 537 | columnWidths.append({0, 0}); | - | ||||||||||||||||||
| 538 | } never executed: end of block | 0 | ||||||||||||||||||
| 539 | } never executed: end of block | 0 | ||||||||||||||||||
| 540 | - | |||||||||||||||||||
| 541 | void QQuickTableViewPrivate::calculateRowHeightsAfterRebuilding() | - | ||||||||||||||||||
| 542 | { | - | ||||||||||||||||||
| 543 | qreal prevRowHeight = 0; | - | ||||||||||||||||||
| 544 | for (int row = loadedTable.top(); row <= loadedTable.bottom(); ++row) {
| 0 | ||||||||||||||||||
| 545 | qreal rowHeight = 0; | - | ||||||||||||||||||
| 546 | for (int column = loadedTable.left(); column <= loadedTable.right(); ++column)
| 0 | ||||||||||||||||||
| 547 | rowHeight = qMax(rowHeight, cellHeight(QPoint(column, row))); never executed: rowHeight = qMax(rowHeight, cellHeight(QPoint(column, row))); | 0 | ||||||||||||||||||
| 548 | - | |||||||||||||||||||
| 549 | if (rowHeight <= 0)
| 0 | ||||||||||||||||||
| 550 | rowHeight = kDefaultRowHeight; never executed: rowHeight = kDefaultRowHeight; | 0 | ||||||||||||||||||
| 551 | - | |||||||||||||||||||
| 552 | if (rowHeight == prevRowHeight)
| 0 | ||||||||||||||||||
| 553 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 554 | - | |||||||||||||||||||
| 555 | rowHeights.append({row, rowHeight}); | - | ||||||||||||||||||
| 556 | prevRowHeight = rowHeight; | - | ||||||||||||||||||
| 557 | } never executed: end of block | 0 | ||||||||||||||||||
| 558 | - | |||||||||||||||||||
| 559 | if (rowHeights.isEmpty()) {
| 0 | ||||||||||||||||||
| 560 | // Add at least one row, wo we don't need | - | ||||||||||||||||||
| 561 | // to check if the vector is empty elsewhere. | - | ||||||||||||||||||
| 562 | rowHeights.append({0, 0}); | - | ||||||||||||||||||
| 563 | } never executed: end of block | 0 | ||||||||||||||||||
| 564 | } never executed: end of block | 0 | ||||||||||||||||||
| 565 | - | |||||||||||||||||||
| 566 | void QQuickTableViewPrivate::calculateColumnWidth(int column) | - | ||||||||||||||||||
| 567 | { | - | ||||||||||||||||||
| 568 | if (column < columnWidths.last().index) {
| 0 | ||||||||||||||||||
| 569 | // We only do the calculation once, and then stick with the size. | - | ||||||||||||||||||
| 570 | // See comments inside ColumnRowSize struct. | - | ||||||||||||||||||
| 571 | return; never executed: return; | 0 | ||||||||||||||||||
| 572 | } | - | ||||||||||||||||||
| 573 | - | |||||||||||||||||||
| 574 | qreal columnWidth = 0; | - | ||||||||||||||||||
| 575 | for (int row = loadedTable.top(); row <= loadedTable.bottom(); ++row)
| 0 | ||||||||||||||||||
| 576 | columnWidth = qMax(columnWidth, cellWidth(QPoint(column, row))); never executed: columnWidth = qMax(columnWidth, cellWidth(QPoint(column, row))); | 0 | ||||||||||||||||||
| 577 | - | |||||||||||||||||||
| 578 | if (columnWidth <= 0)
| 0 | ||||||||||||||||||
| 579 | columnWidth = kDefaultColumnWidth; never executed: columnWidth = kDefaultColumnWidth; | 0 | ||||||||||||||||||
| 580 | - | |||||||||||||||||||
| 581 | if (columnWidth == columnWidths.last().size)
| 0 | ||||||||||||||||||
| 582 | return; never executed: return; | 0 | ||||||||||||||||||
| 583 | - | |||||||||||||||||||
| 584 | columnWidths.append({column, columnWidth}); | - | ||||||||||||||||||
| 585 | } never executed: end of block | 0 | ||||||||||||||||||
| 586 | - | |||||||||||||||||||
| 587 | void QQuickTableViewPrivate::calculateRowHeight(int row) | - | ||||||||||||||||||
| 588 | { | - | ||||||||||||||||||
| 589 | if (row < rowHeights.last().index) {
| 0 | ||||||||||||||||||
| 590 | // We only do the calculation once, and then stick with the size. | - | ||||||||||||||||||
| 591 | // See comments inside ColumnRowSize struct. | - | ||||||||||||||||||
| 592 | return; never executed: return; | 0 | ||||||||||||||||||
| 593 | } | - | ||||||||||||||||||
| 594 | - | |||||||||||||||||||
| 595 | qreal rowHeight = 0; | - | ||||||||||||||||||
| 596 | for (int column = loadedTable.left(); column <= loadedTable.right(); ++column)
| 0 | ||||||||||||||||||
| 597 | rowHeight = qMax(rowHeight, cellHeight(QPoint(column, row))); never executed: rowHeight = qMax(rowHeight, cellHeight(QPoint(column, row))); | 0 | ||||||||||||||||||
| 598 | - | |||||||||||||||||||
| 599 | if (rowHeight <= 0)
| 0 | ||||||||||||||||||
| 600 | rowHeight = kDefaultRowHeight; never executed: rowHeight = kDefaultRowHeight; | 0 | ||||||||||||||||||
| 601 | - | |||||||||||||||||||
| 602 | if (rowHeight == rowHeights.last().size)
| 0 | ||||||||||||||||||
| 603 | return; never executed: return; | 0 | ||||||||||||||||||
| 604 | - | |||||||||||||||||||
| 605 | rowHeights.append({row, rowHeight}); | - | ||||||||||||||||||
| 606 | } never executed: end of block | 0 | ||||||||||||||||||
| 607 | - | |||||||||||||||||||
| 608 | void QQuickTableViewPrivate::calculateEdgeSizeFromLoadRequest() | - | ||||||||||||||||||
| 609 | { | - | ||||||||||||||||||
| 610 | if (tableRebuilding)
| 0 | ||||||||||||||||||
| 611 | return; never executed: return; | 0 | ||||||||||||||||||
| 612 | - | |||||||||||||||||||
| 613 | switch (loadRequest.edge()) { | - | ||||||||||||||||||
| 614 | case Qt::LeftEdge: never executed: case Qt::LeftEdge: | 0 | ||||||||||||||||||
| 615 | case Qt::TopEdge: never executed: case Qt::TopEdge: | 0 | ||||||||||||||||||
| 616 | // Flicking left or up through "never loaded" rows/columns is currently | - | ||||||||||||||||||
| 617 | // not supported. You always need to start loading the table from the beginning. | - | ||||||||||||||||||
| 618 | return; never executed: return; | 0 | ||||||||||||||||||
| 619 | case Qt::RightEdge: never executed: case Qt::RightEdge: | 0 | ||||||||||||||||||
| 620 | if (tableSize.height() > 1)
| 0 | ||||||||||||||||||
| 621 | calculateColumnWidth(loadedTable.right()); never executed: calculateColumnWidth(loadedTable.right()); | 0 | ||||||||||||||||||
| 622 | break; never executed: break; | 0 | ||||||||||||||||||
| 623 | case Qt::BottomEdge: never executed: case Qt::BottomEdge: | 0 | ||||||||||||||||||
| 624 | if (tableSize.width() > 1)
| 0 | ||||||||||||||||||
| 625 | calculateRowHeight(loadedTable.bottom()); never executed: calculateRowHeight(loadedTable.bottom()); | 0 | ||||||||||||||||||
| 626 | break; never executed: break; | 0 | ||||||||||||||||||
| 627 | default: never executed: default: | 0 | ||||||||||||||||||
| 628 | Q_TABLEVIEW_UNREACHABLE("This function should not be called when loading top-left item"); | - | ||||||||||||||||||
| 629 | } never executed: end of block | 0 | ||||||||||||||||||
| 630 | } | - | ||||||||||||||||||
| 631 | - | |||||||||||||||||||
| 632 | void QQuickTableViewPrivate::calculateTableSize() | - | ||||||||||||||||||
| 633 | { | - | ||||||||||||||||||
| 634 | // tableSize is the same as row and column count, and will always | - | ||||||||||||||||||
| 635 | // be the same as the number of rows and columns in the model. | - | ||||||||||||||||||
| 636 | Q_Q(QQuickTableView); | - | ||||||||||||||||||
| 637 | QSize prevTableSize = tableSize; | - | ||||||||||||||||||
| 638 | - | |||||||||||||||||||
| 639 | if (delegateModel)
| 0-102 | ||||||||||||||||||
| 640 | tableSize = QSize(delegateModel->columns(), delegateModel->rows()); executed 102 times by 1 test: tableSize = QSize(delegateModel->columns(), delegateModel->rows());Executed by:
| 102 | ||||||||||||||||||
| 641 | else if (model)
| 0 | ||||||||||||||||||
| 642 | tableSize = QSize(1, model->count()); never executed: tableSize = QSize(1, model->count()); | 0 | ||||||||||||||||||
| 643 | else | - | ||||||||||||||||||
| 644 | tableSize = QSize(0, 0); never executed: tableSize = QSize(0, 0); | 0 | ||||||||||||||||||
| 645 | - | |||||||||||||||||||
| 646 | if (prevTableSize.width() != tableSize.width())
| 0-102 | ||||||||||||||||||
| 647 | emit q->columnsChanged(); executed 102 times by 1 test: q->columnsChanged();Executed by:
| 102 | ||||||||||||||||||
| 648 | if (prevTableSize.height() != tableSize.height())
| 0-102 | ||||||||||||||||||
| 649 | emit q->rowsChanged(); executed 102 times by 1 test: q->rowsChanged();Executed by:
| 102 | ||||||||||||||||||
| 650 | } executed 102 times by 1 test: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 651 | - | |||||||||||||||||||
| 652 | qreal QQuickTableViewPrivate::columnWidth(int column) | - | ||||||||||||||||||
| 653 | { | - | ||||||||||||||||||
| 654 | if (!columnWidths.isEmpty()) {
| 0 | ||||||||||||||||||
| 655 | // Find the first ColumnRowSize with a column before, or at, the given column | - | ||||||||||||||||||
| 656 | auto iter = std::upper_bound(columnWidths.constBegin(), columnWidths.constEnd(), | - | ||||||||||||||||||
| 657 | ColumnRowSize{column, -1}, ColumnRowSize::lessThan); | - | ||||||||||||||||||
| 658 | - | |||||||||||||||||||
| 659 | if (iter == columnWidths.constEnd()) {
| 0 | ||||||||||||||||||
| 660 | // If the table is not a list, return the size | - | ||||||||||||||||||
| 661 | // of the last recorded ColumnRowSize. | - | ||||||||||||||||||
| 662 | if (tableSize.height() > 1)
| 0 | ||||||||||||||||||
| 663 | return columnWidths.last().size; never executed: return columnWidths.last().size; | 0 | ||||||||||||||||||
| 664 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 665 | // Check if we got an explicit assignment for this column | - | ||||||||||||||||||
| 666 | if (iter->index == column)
| 0 | ||||||||||||||||||
| 667 | return iter->size; never executed: return iter->size; | 0 | ||||||||||||||||||
| 668 | - | |||||||||||||||||||
| 669 | // If the table is not a list, return the size of | - | ||||||||||||||||||
| 670 | // ColumnRowSize element found before column. Since there | - | ||||||||||||||||||
| 671 | // is always an element stored for column 0, this is safe. | - | ||||||||||||||||||
| 672 | // Otherwise we continue, and return the size of the delegate | - | ||||||||||||||||||
| 673 | // item at the given column instead. | - | ||||||||||||||||||
| 674 | if (tableSize.height() > 1)
| 0 | ||||||||||||||||||
| 675 | return (iter - 1)->size; never executed: return (iter - 1)->size; | 0 | ||||||||||||||||||
| 676 | } never executed: end of block | 0 | ||||||||||||||||||
| 677 | } | - | ||||||||||||||||||
| 678 | - | |||||||||||||||||||
| 679 | // If we have an item loaded at column, return the width of the item. | - | ||||||||||||||||||
| 680 | if (column >= loadedTable.left() && column <= loadedTable.right())
| 0 | ||||||||||||||||||
| 681 | return cellWidth(QPoint(column, loadedTable.top())); never executed: return cellWidth(QPoint(column, loadedTable.top())); | 0 | ||||||||||||||||||
| 682 | - | |||||||||||||||||||
| 683 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 684 | } | - | ||||||||||||||||||
| 685 | - | |||||||||||||||||||
| 686 | qreal QQuickTableViewPrivate::rowHeight(int row) | - | ||||||||||||||||||
| 687 | { | - | ||||||||||||||||||
| 688 | if (!rowHeights.isEmpty()) {
| 0 | ||||||||||||||||||
| 689 | // Find the ColumnRowSize assignment before, or at, row | - | ||||||||||||||||||
| 690 | auto iter = std::lower_bound(rowHeights.constBegin(), rowHeights.constEnd(), | - | ||||||||||||||||||
| 691 | ColumnRowSize{row, -1}, ColumnRowSize::lessThan); | - | ||||||||||||||||||
| 692 | - | |||||||||||||||||||
| 693 | if (iter == rowHeights.constEnd()) {
| 0 | ||||||||||||||||||
| 694 | // If the table is not a list, return the size | - | ||||||||||||||||||
| 695 | // of the last recorded ColumnRowSize. | - | ||||||||||||||||||
| 696 | if (tableSize.width() > 1)
| 0 | ||||||||||||||||||
| 697 | return rowHeights.last().size; never executed: return rowHeights.last().size; | 0 | ||||||||||||||||||
| 698 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 699 | // Check if we got an explicit assignment for this row | - | ||||||||||||||||||
| 700 | if (iter->index == row)
| 0 | ||||||||||||||||||
| 701 | return iter->size; never executed: return iter->size; | 0 | ||||||||||||||||||
| 702 | - | |||||||||||||||||||
| 703 | // If the table is not a list, return the size of | - | ||||||||||||||||||
| 704 | // ColumnRowSize element found before row. Since there | - | ||||||||||||||||||
| 705 | // is always an element stored for row 0, this is safe. | - | ||||||||||||||||||
| 706 | // Otherwise we continue, and return the size of the delegate | - | ||||||||||||||||||
| 707 | // item at the given row instead. | - | ||||||||||||||||||
| 708 | if (tableSize.width() > 1)
| 0 | ||||||||||||||||||
| 709 | return (iter - 1)->size; never executed: return (iter - 1)->size; | 0 | ||||||||||||||||||
| 710 | } never executed: end of block | 0 | ||||||||||||||||||
| 711 | } | - | ||||||||||||||||||
| 712 | - | |||||||||||||||||||
| 713 | // If we have an item loaded at row, return the height of the item. | - | ||||||||||||||||||
| 714 | if (row >= loadedTable.top() && row <= loadedTable.bottom())
| 0 | ||||||||||||||||||
| 715 | return cellHeight(QPoint(loadedTable.left(), row)); never executed: return cellHeight(QPoint(loadedTable.left(), row)); | 0 | ||||||||||||||||||
| 716 | - | |||||||||||||||||||
| 717 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 718 | } | - | ||||||||||||||||||
| 719 | - | |||||||||||||||||||
| 720 | void QQuickTableViewPrivate::relayoutTable() | - | ||||||||||||||||||
| 721 | { | - | ||||||||||||||||||
| 722 | relayoutTableItems(); | - | ||||||||||||||||||
| 723 | columnRowPositionsInvalid = false; | - | ||||||||||||||||||
| 724 | - | |||||||||||||||||||
| 725 | syncLoadedTableRectFromLoadedTable(); | - | ||||||||||||||||||
| 726 | contentSizeBenchMarkPoint = QPoint(-1, -1); | - | ||||||||||||||||||
| 727 | updateContentWidth(); | - | ||||||||||||||||||
| 728 | updateContentHeight(); | - | ||||||||||||||||||
| 729 | } never executed: end of block | 0 | ||||||||||||||||||
| 730 | - | |||||||||||||||||||
| 731 | void QQuickTableViewPrivate::relayoutTableItems() | - | ||||||||||||||||||
| 732 | { | - | ||||||||||||||||||
| 733 | qCDebug(lcTableViewDelegateLifecycle); never executed: QMessageLogger(__FILE__, 733, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle().categoryName()).debug();
| 0 | ||||||||||||||||||
| 734 | columnRowPositionsInvalid = false; | - | ||||||||||||||||||
| 735 | - | |||||||||||||||||||
| 736 | qreal nextColumnX = loadedTableOuterRect.x(); | - | ||||||||||||||||||
| 737 | qreal nextRowY = loadedTableOuterRect.y(); | - | ||||||||||||||||||
| 738 | - | |||||||||||||||||||
| 739 | for (int column = loadedTable.left(); column <= loadedTable.right(); ++column) {
| 0 | ||||||||||||||||||
| 740 | // Adjust the geometry of all cells in the current column | - | ||||||||||||||||||
| 741 | qreal width = columnWidth(column); | - | ||||||||||||||||||
| 742 | if (width <= 0)
| 0 | ||||||||||||||||||
| 743 | width = kDefaultColumnWidth; never executed: width = kDefaultColumnWidth; | 0 | ||||||||||||||||||
| 744 | - | |||||||||||||||||||
| 745 | for (int row = loadedTable.top(); row <= loadedTable.bottom(); ++row) {
| 0 | ||||||||||||||||||
| 746 | auto item = loadedTableItem(QPoint(column, row)); | - | ||||||||||||||||||
| 747 | QRectF geometry = item->geometry(); | - | ||||||||||||||||||
| 748 | geometry.moveLeft(nextColumnX); | - | ||||||||||||||||||
| 749 | geometry.setWidth(width); | - | ||||||||||||||||||
| 750 | item->setGeometry(geometry); | - | ||||||||||||||||||
| 751 | } never executed: end of block | 0 | ||||||||||||||||||
| 752 | - | |||||||||||||||||||
| 753 | nextColumnX += width + cellSpacing.width(); | - | ||||||||||||||||||
| 754 | } never executed: end of block | 0 | ||||||||||||||||||
| 755 | - | |||||||||||||||||||
| 756 | for (int row = loadedTable.top(); row <= loadedTable.bottom(); ++row) {
| 0 | ||||||||||||||||||
| 757 | // Adjust the geometry of all cells in the current row | - | ||||||||||||||||||
| 758 | qreal height = rowHeight(row); | - | ||||||||||||||||||
| 759 | if (height <= 0)
| 0 | ||||||||||||||||||
| 760 | height = kDefaultRowHeight; never executed: height = kDefaultRowHeight; | 0 | ||||||||||||||||||
| 761 | - | |||||||||||||||||||
| 762 | for (int column = loadedTable.left(); column <= loadedTable.right(); ++column) {
| 0 | ||||||||||||||||||
| 763 | auto item = loadedTableItem(QPoint(column, row)); | - | ||||||||||||||||||
| 764 | QRectF geometry = item->geometry(); | - | ||||||||||||||||||
| 765 | geometry.moveTop(nextRowY); | - | ||||||||||||||||||
| 766 | geometry.setHeight(height); | - | ||||||||||||||||||
| 767 | item->setGeometry(geometry); | - | ||||||||||||||||||
| 768 | } never executed: end of block | 0 | ||||||||||||||||||
| 769 | - | |||||||||||||||||||
| 770 | nextRowY += height + cellSpacing.height(); | - | ||||||||||||||||||
| 771 | } never executed: end of block | 0 | ||||||||||||||||||
| 772 | - | |||||||||||||||||||
| 773 | if (Q_UNLIKELY(lcTableViewDelegateLifecycle().isDebugEnabled())) {
| 0 | ||||||||||||||||||
| 774 | for (int column = loadedTable.left(); column <= loadedTable.right(); ++column) {
| 0 | ||||||||||||||||||
| 775 | for (int row = loadedTable.top(); row <= loadedTable.bottom(); ++row) {
| 0 | ||||||||||||||||||
| 776 | QPoint cell = QPoint(column, row); | - | ||||||||||||||||||
| 777 | qCDebug(lcTableViewDelegateLifecycle()) << "relayout item:" << cell << loadedTableItem(cell)->geometry(); never executed: QMessageLogger(__FILE__, 777, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle()().categoryName()).debug() << "relayout item:" << cell << loadedTableItem(cell)->geometry();
| 0 | ||||||||||||||||||
| 778 | } never executed: end of block | 0 | ||||||||||||||||||
| 779 | } never executed: end of block | 0 | ||||||||||||||||||
| 780 | } never executed: end of block | 0 | ||||||||||||||||||
| 781 | } never executed: end of block | 0 | ||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | void QQuickTableViewPrivate::layoutVerticalEdge(Qt::Edge tableEdge) | - | ||||||||||||||||||
| 784 | { | - | ||||||||||||||||||
| 785 | int column = (tableEdge == Qt::LeftEdge) ? loadedTable.left() : loadedTable.right();
| 0 | ||||||||||||||||||
| 786 | QPoint neighbourDirection = (tableEdge == Qt::LeftEdge) ? kRight : kLeft;
| 0 | ||||||||||||||||||
| 787 | qreal left = -1; | - | ||||||||||||||||||
| 788 | - | |||||||||||||||||||
| 789 | qreal width = columnWidth(column); | - | ||||||||||||||||||
| 790 | if (width <= 0)
| 0 | ||||||||||||||||||
| 791 | width = kDefaultColumnWidth; never executed: width = kDefaultColumnWidth; | 0 | ||||||||||||||||||
| 792 | - | |||||||||||||||||||
| 793 | for (int row = loadedTable.top(); row <= loadedTable.bottom(); ++row) {
| 0 | ||||||||||||||||||
| 794 | auto fxTableItem = loadedTableItem(QPoint(column, row)); | - | ||||||||||||||||||
| 795 | auto const neighbourItem = itemNextTo(fxTableItem, neighbourDirection); | - | ||||||||||||||||||
| 796 | - | |||||||||||||||||||
| 797 | QRectF geometry = fxTableItem->geometry(); | - | ||||||||||||||||||
| 798 | geometry.setWidth(width); | - | ||||||||||||||||||
| 799 | geometry.setHeight(neighbourItem->geometry().height()); | - | ||||||||||||||||||
| 800 | - | |||||||||||||||||||
| 801 | if (left == -1) {
| 0 | ||||||||||||||||||
| 802 | // left will be the same for all items in the | - | ||||||||||||||||||
| 803 | // column, so do the calculation once. | - | ||||||||||||||||||
| 804 | left = tableEdge == Qt::LeftEdge ?
| 0 | ||||||||||||||||||
| 805 | neighbourItem->geometry().left() - cellSpacing.width() - geometry.width() : | - | ||||||||||||||||||
| 806 | neighbourItem->geometry().right() + cellSpacing.width(); | - | ||||||||||||||||||
| 807 | } never executed: end of block | 0 | ||||||||||||||||||
| 808 | - | |||||||||||||||||||
| 809 | geometry.moveLeft(left); | - | ||||||||||||||||||
| 810 | geometry.moveTop(neighbourItem->geometry().top()); | - | ||||||||||||||||||
| 811 | - | |||||||||||||||||||
| 812 | fxTableItem->setGeometry(geometry); | - | ||||||||||||||||||
| 813 | fxTableItem->setVisible(true); | - | ||||||||||||||||||
| 814 | - | |||||||||||||||||||
| 815 | qCDebug(lcTableViewDelegateLifecycle()) << "layout item:" << QPoint(column, row) << fxTableItem->geometry(); never executed: QMessageLogger(__FILE__, 815, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle()().categoryName()).debug() << "layout item:" << QPoint(column, row) << fxTableItem->geometry();
| 0 | ||||||||||||||||||
| 816 | } never executed: end of block | 0 | ||||||||||||||||||
| 817 | } never executed: end of block | 0 | ||||||||||||||||||
| 818 | - | |||||||||||||||||||
| 819 | void QQuickTableViewPrivate::layoutHorizontalEdge(Qt::Edge tableEdge) | - | ||||||||||||||||||
| 820 | { | - | ||||||||||||||||||
| 821 | int row = (tableEdge == Qt::TopEdge) ? loadedTable.top() : loadedTable.bottom();
| 0 | ||||||||||||||||||
| 822 | QPoint neighbourDirection = (tableEdge == Qt::TopEdge) ? kDown : kUp;
| 0 | ||||||||||||||||||
| 823 | qreal top = -1; | - | ||||||||||||||||||
| 824 | - | |||||||||||||||||||
| 825 | qreal height = rowHeight(row); | - | ||||||||||||||||||
| 826 | if (height <= 0)
| 0 | ||||||||||||||||||
| 827 | height = kDefaultRowHeight; never executed: height = kDefaultRowHeight; | 0 | ||||||||||||||||||
| 828 | - | |||||||||||||||||||
| 829 | for (int column = loadedTable.left(); column <= loadedTable.right(); ++column) {
| 0 | ||||||||||||||||||
| 830 | auto fxTableItem = loadedTableItem(QPoint(column, row)); | - | ||||||||||||||||||
| 831 | auto const neighbourItem = itemNextTo(fxTableItem, neighbourDirection); | - | ||||||||||||||||||
| 832 | - | |||||||||||||||||||
| 833 | QRectF geometry = fxTableItem->geometry(); | - | ||||||||||||||||||
| 834 | geometry.setWidth(neighbourItem->geometry().width()); | - | ||||||||||||||||||
| 835 | geometry.setHeight(height); | - | ||||||||||||||||||
| 836 | - | |||||||||||||||||||
| 837 | if (top == -1) {
| 0 | ||||||||||||||||||
| 838 | // top will be the same for all items in the | - | ||||||||||||||||||
| 839 | // row, so do the calculation once. | - | ||||||||||||||||||
| 840 | top = tableEdge == Qt::TopEdge ?
| 0 | ||||||||||||||||||
| 841 | neighbourItem->geometry().top() - cellSpacing.height() - geometry.height() : | - | ||||||||||||||||||
| 842 | neighbourItem->geometry().bottom() + cellSpacing.height(); | - | ||||||||||||||||||
| 843 | } never executed: end of block | 0 | ||||||||||||||||||
| 844 | - | |||||||||||||||||||
| 845 | geometry.moveTop(top); | - | ||||||||||||||||||
| 846 | geometry.moveLeft(neighbourItem->geometry().left()); | - | ||||||||||||||||||
| 847 | - | |||||||||||||||||||
| 848 | fxTableItem->setGeometry(geometry); | - | ||||||||||||||||||
| 849 | fxTableItem->setVisible(true); | - | ||||||||||||||||||
| 850 | - | |||||||||||||||||||
| 851 | qCDebug(lcTableViewDelegateLifecycle()) << "layout item:" << QPoint(column, row) << fxTableItem->geometry(); never executed: QMessageLogger(__FILE__, 851, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle()().categoryName()).debug() << "layout item:" << QPoint(column, row) << fxTableItem->geometry();
| 0 | ||||||||||||||||||
| 852 | } never executed: end of block | 0 | ||||||||||||||||||
| 853 | } never executed: end of block | 0 | ||||||||||||||||||
| 854 | - | |||||||||||||||||||
| 855 | void QQuickTableViewPrivate::layoutTopLeftItem() | - | ||||||||||||||||||
| 856 | { | - | ||||||||||||||||||
| 857 | // ###todo: support starting with other top-left items than 0,0 | - | ||||||||||||||||||
| 858 | const QPoint cell = loadRequest.firstCell(); | - | ||||||||||||||||||
| 859 | Q_TABLEVIEW_ASSERT(cell == QPoint(0, 0), loadRequest.toString()); never executed: return false; | 0 | ||||||||||||||||||
| 860 | auto topLeftItem = loadedTableItem(cell); | - | ||||||||||||||||||
| 861 | auto item = topLeftItem->item; | - | ||||||||||||||||||
| 862 | - | |||||||||||||||||||
| 863 | qreal width = cellWidth(cell); | - | ||||||||||||||||||
| 864 | qreal height = cellHeight(cell); | - | ||||||||||||||||||
| 865 | if (width <= 0)
| 0 | ||||||||||||||||||
| 866 | width = kDefaultColumnWidth; never executed: width = kDefaultColumnWidth; | 0 | ||||||||||||||||||
| 867 | if (height <= 0)
| 0 | ||||||||||||||||||
| 868 | height = kDefaultRowHeight; never executed: height = kDefaultRowHeight; | 0 | ||||||||||||||||||
| 869 | - | |||||||||||||||||||
| 870 | item->setPosition(QPoint(tableMargins.left(), tableMargins.top())); | - | ||||||||||||||||||
| 871 | item->setSize(QSizeF(width, height)); | - | ||||||||||||||||||
| 872 | topLeftItem->setVisible(true); | - | ||||||||||||||||||
| 873 | qCDebug(lcTableViewDelegateLifecycle) << "geometry:" << topLeftItem->geometry(); never executed: QMessageLogger(__FILE__, 873, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle().categoryName()).debug() << "geometry:" << topLeftItem->geometry();
| 0 | ||||||||||||||||||
| 874 | } never executed: end of block | 0 | ||||||||||||||||||
| 875 | - | |||||||||||||||||||
| 876 | void QQuickTableViewPrivate::layoutTableEdgeFromLoadRequest() | - | ||||||||||||||||||
| 877 | { | - | ||||||||||||||||||
| 878 | switch (loadRequest.edge()) { | - | ||||||||||||||||||
| 879 | case Qt::LeftEdge: never executed: case Qt::LeftEdge: | 0 | ||||||||||||||||||
| 880 | case Qt::RightEdge: never executed: case Qt::RightEdge: | 0 | ||||||||||||||||||
| 881 | layoutVerticalEdge(loadRequest.edge()); | - | ||||||||||||||||||
| 882 | break; never executed: break; | 0 | ||||||||||||||||||
| 883 | case Qt::TopEdge: never executed: case Qt::TopEdge: | 0 | ||||||||||||||||||
| 884 | case Qt::BottomEdge: never executed: case Qt::BottomEdge: | 0 | ||||||||||||||||||
| 885 | layoutHorizontalEdge(loadRequest.edge()); | - | ||||||||||||||||||
| 886 | break; never executed: break; | 0 | ||||||||||||||||||
| 887 | default: never executed: default: | 0 | ||||||||||||||||||
| 888 | layoutTopLeftItem(); | - | ||||||||||||||||||
| 889 | break; never executed: break; | 0 | ||||||||||||||||||
| 890 | } | - | ||||||||||||||||||
| 891 | } | - | ||||||||||||||||||
| 892 | - | |||||||||||||||||||
| 893 | void QQuickTableViewPrivate::cancelLoadRequest() | - | ||||||||||||||||||
| 894 | { | - | ||||||||||||||||||
| 895 | loadRequest.markAsDone(); | - | ||||||||||||||||||
| 896 | model->cancel(modelIndexAtCell(loadRequest.currentCell())); | - | ||||||||||||||||||
| 897 | - | |||||||||||||||||||
| 898 | if (tableInvalid) {
| 0 | ||||||||||||||||||
| 899 | // No reason to rollback already loaded edge items | - | ||||||||||||||||||
| 900 | // since we anyway are about to reload all items. | - | ||||||||||||||||||
| 901 | return; never executed: return; | 0 | ||||||||||||||||||
| 902 | } | - | ||||||||||||||||||
| 903 | - | |||||||||||||||||||
| 904 | if (loadRequest.atBeginning()) {
| 0 | ||||||||||||||||||
| 905 | // No items have yet been loaded, so nothing to unload | - | ||||||||||||||||||
| 906 | return; never executed: return; | 0 | ||||||||||||||||||
| 907 | } | - | ||||||||||||||||||
| 908 | - | |||||||||||||||||||
| 909 | QLine rollbackItems; | - | ||||||||||||||||||
| 910 | rollbackItems.setP1(loadRequest.firstCell()); | - | ||||||||||||||||||
| 911 | rollbackItems.setP2(loadRequest.previousCell()); | - | ||||||||||||||||||
| 912 | qCDebug(lcTableViewDelegateLifecycle()) << "rollback:" << rollbackItems << tableLayoutToString(); never executed: QMessageLogger(__FILE__, 912, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle()().categoryName()).debug() << "rollback:" << rollbackItems << tableLayoutToString();
| 0 | ||||||||||||||||||
| 913 | unloadItems(rollbackItems); | - | ||||||||||||||||||
| 914 | } never executed: end of block | 0 | ||||||||||||||||||
| 915 | - | |||||||||||||||||||
| 916 | void QQuickTableViewPrivate::processLoadRequest() | - | ||||||||||||||||||
| 917 | { | - | ||||||||||||||||||
| 918 | Q_TABLEVIEW_ASSERT(loadRequest.isActive(), ""); never executed: return false; | 0 | ||||||||||||||||||
| 919 | - | |||||||||||||||||||
| 920 | while (loadRequest.hasCurrentCell()) {
| 0 | ||||||||||||||||||
| 921 | QPoint cell = loadRequest.currentCell(); | - | ||||||||||||||||||
| 922 | FxTableItem *fxTableItem = loadFxTableItem(cell, loadRequest.incubationMode()); | - | ||||||||||||||||||
| 923 | - | |||||||||||||||||||
| 924 | if (!fxTableItem) {
| 0 | ||||||||||||||||||
| 925 | // Requested item is not yet ready. Just leave, and wait for this | - | ||||||||||||||||||
| 926 | // function to be called again when the item is ready. | - | ||||||||||||||||||
| 927 | return; never executed: return; | 0 | ||||||||||||||||||
| 928 | } | - | ||||||||||||||||||
| 929 | - | |||||||||||||||||||
| 930 | loadedItems.insert(modelIndexAtCell(cell), fxTableItem); | - | ||||||||||||||||||
| 931 | loadRequest.moveToNextCell(); | - | ||||||||||||||||||
| 932 | } never executed: end of block | 0 | ||||||||||||||||||
| 933 | - | |||||||||||||||||||
| 934 | qCDebug(lcTableViewDelegateLifecycle()) << "all items loaded!"; never executed: QMessageLogger(__FILE__, 934, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle()().categoryName()).debug() << "all items loaded!";
| 0 | ||||||||||||||||||
| 935 | - | |||||||||||||||||||
| 936 | syncLoadedTableFromLoadRequest(); | - | ||||||||||||||||||
| 937 | calculateEdgeSizeFromLoadRequest(); | - | ||||||||||||||||||
| 938 | layoutTableEdgeFromLoadRequest(); | - | ||||||||||||||||||
| 939 | - | |||||||||||||||||||
| 940 | syncLoadedTableRectFromLoadedTable(); | - | ||||||||||||||||||
| 941 | enforceFirstRowColumnAtOrigo(); | - | ||||||||||||||||||
| 942 | updateContentWidth(); | - | ||||||||||||||||||
| 943 | updateContentHeight(); | - | ||||||||||||||||||
| 944 | - | |||||||||||||||||||
| 945 | loadRequest.markAsDone(); | - | ||||||||||||||||||
| 946 | qCDebug(lcTableViewDelegateLifecycle()) << "request completed! Table:" << tableLayoutToString(); never executed: QMessageLogger(__FILE__, 946, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle()().categoryName()).debug() << "request completed! Table:" << tableLayoutToString();
| 0 | ||||||||||||||||||
| 947 | } never executed: end of block | 0 | ||||||||||||||||||
| 948 | - | |||||||||||||||||||
| 949 | void QQuickTableViewPrivate::beginRebuildTable() | - | ||||||||||||||||||
| 950 | { | - | ||||||||||||||||||
| 951 | qCDebug(lcTableViewDelegateLifecycle()); never executed: QMessageLogger(__FILE__, 951, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle()().categoryName()).debug();
| 0-102 | ||||||||||||||||||
| 952 | clear(); | - | ||||||||||||||||||
| 953 | tableInvalid = false; | - | ||||||||||||||||||
| 954 | tableRebuilding = true; | - | ||||||||||||||||||
| 955 | calculateTableSize(); | - | ||||||||||||||||||
| 956 | loadInitialTopLeftItem(); | - | ||||||||||||||||||
| 957 | loadAndUnloadVisibleEdges(); | - | ||||||||||||||||||
| 958 | } executed 102 times by 1 test: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 959 | - | |||||||||||||||||||
| 960 | void QQuickTableViewPrivate::endRebuildTable() | - | ||||||||||||||||||
| 961 | { | - | ||||||||||||||||||
| 962 | tableRebuilding = false; | - | ||||||||||||||||||
| 963 | - | |||||||||||||||||||
| 964 | if (loadedItems.isEmpty())
| 0-102 | ||||||||||||||||||
| 965 | return; executed 102 times by 1 test: return;Executed by:
| 102 | ||||||||||||||||||
| 966 | - | |||||||||||||||||||
| 967 | // We don't calculate row/column sizes for lists. | - | ||||||||||||||||||
| 968 | // Instead we we use the sizes of the items directly | - | ||||||||||||||||||
| 969 | // unless for explicit row/column size assignments. | - | ||||||||||||||||||
| 970 | columnWidths.clear(); | - | ||||||||||||||||||
| 971 | rowHeights.clear(); | - | ||||||||||||||||||
| 972 | if (tableSize.height() > 1)
| 0 | ||||||||||||||||||
| 973 | calculateColumnWidthsAfterRebuilding(); never executed: calculateColumnWidthsAfterRebuilding(); | 0 | ||||||||||||||||||
| 974 | if (tableSize.width() > 1)
| 0 | ||||||||||||||||||
| 975 | calculateRowHeightsAfterRebuilding(); never executed: calculateRowHeightsAfterRebuilding(); | 0 | ||||||||||||||||||
| 976 | - | |||||||||||||||||||
| 977 | relayoutTable(); | - | ||||||||||||||||||
| 978 | qCDebug(lcTableViewDelegateLifecycle()) << tableLayoutToString(); never executed: QMessageLogger(__FILE__, 978, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle()().categoryName()).debug() << tableLayoutToString();
| 0 | ||||||||||||||||||
| 979 | } never executed: end of block | 0 | ||||||||||||||||||
| 980 | - | |||||||||||||||||||
| 981 | void QQuickTableViewPrivate::loadInitialTopLeftItem() | - | ||||||||||||||||||
| 982 | { | - | ||||||||||||||||||
| 983 | Q_TABLEVIEW_ASSERT(loadedItems.isEmpty(), ""); never executed: return false; | 0 | ||||||||||||||||||
| 984 | - | |||||||||||||||||||
| 985 | if (tableSize.isEmpty())
| 0-102 | ||||||||||||||||||
| 986 | return; executed 102 times by 1 test: return;Executed by:
| 102 | ||||||||||||||||||
| 987 | - | |||||||||||||||||||
| 988 | if (model->count() == 0)
| 0 | ||||||||||||||||||
| 989 | return; never executed: return; | 0 | ||||||||||||||||||
| 990 | - | |||||||||||||||||||
| 991 | // Load top-left item. After loaded, loadItemsInsideRect() will take | - | ||||||||||||||||||
| 992 | // care of filling out the rest of the table. | - | ||||||||||||||||||
| 993 | loadRequest.begin(QPoint(0, 0), QQmlIncubator::AsynchronousIfNested); | - | ||||||||||||||||||
| 994 | processLoadRequest(); | - | ||||||||||||||||||
| 995 | } never executed: end of block | 0 | ||||||||||||||||||
| 996 | - | |||||||||||||||||||
| 997 | void QQuickTableViewPrivate::unloadEdge(Qt::Edge edge) | - | ||||||||||||||||||
| 998 | { | - | ||||||||||||||||||
| 999 | unloadItems(rectangleEdge(loadedTable, edge)); | - | ||||||||||||||||||
| 1000 | loadedTable = expandedRect(loadedTable, edge, -1); | - | ||||||||||||||||||
| 1001 | syncLoadedTableRectFromLoadedTable(); | - | ||||||||||||||||||
| 1002 | qCDebug(lcTableViewDelegateLifecycle) << tableLayoutToString(); never executed: QMessageLogger(__FILE__, 1002, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle().categoryName()).debug() << tableLayoutToString();
| 0 | ||||||||||||||||||
| 1003 | } never executed: end of block | 0 | ||||||||||||||||||
| 1004 | - | |||||||||||||||||||
| 1005 | void QQuickTableViewPrivate::loadEdge(Qt::Edge edge, QQmlIncubator::IncubationMode incubationMode) | - | ||||||||||||||||||
| 1006 | { | - | ||||||||||||||||||
| 1007 | QLine cellsToLoad = rectangleEdge(expandedRect(loadedTable, edge, 1), edge); | - | ||||||||||||||||||
| 1008 | loadRequest.begin(cellsToLoad, edge, incubationMode); | - | ||||||||||||||||||
| 1009 | processLoadRequest(); | - | ||||||||||||||||||
| 1010 | } never executed: end of block | 0 | ||||||||||||||||||
| 1011 | - | |||||||||||||||||||
| 1012 | void QQuickTableViewPrivate::loadAndUnloadVisibleEdges() | - | ||||||||||||||||||
| 1013 | { | - | ||||||||||||||||||
| 1014 | // Unload table edges that have been moved outside the visible part of the | - | ||||||||||||||||||
| 1015 | // table (including buffer area), and load new edges that has been moved inside. | - | ||||||||||||||||||
| 1016 | // Note: an important point is that we always keep the table rectangular | - | ||||||||||||||||||
| 1017 | // and without holes to reduce complexity (we never leave the table in | - | ||||||||||||||||||
| 1018 | // a half-loaded state, or keep track of multiple patches). | - | ||||||||||||||||||
| 1019 | // We load only one edge (row or column) at a time. This is especially | - | ||||||||||||||||||
| 1020 | // important when loading into the buffer, since we need to be able to | - | ||||||||||||||||||
| 1021 | // cancel the buffering quickly if the user starts to flick, and then | - | ||||||||||||||||||
| 1022 | // focus all further loading on the edges that are flicked into view. | - | ||||||||||||||||||
| 1023 | - | |||||||||||||||||||
| 1024 | if (loadRequest.isActive()) {
| 0-102 | ||||||||||||||||||
| 1025 | // Don't start loading more edges while we're | - | ||||||||||||||||||
| 1026 | // already waiting for another one to load. | - | ||||||||||||||||||
| 1027 | return; never executed: return; | 0 | ||||||||||||||||||
| 1028 | } | - | ||||||||||||||||||
| 1029 | - | |||||||||||||||||||
| 1030 | if (loadedItems.isEmpty()) {
| 0-102 | ||||||||||||||||||
| 1031 | // We need at least the top-left item to be loaded before we can | - | ||||||||||||||||||
| 1032 | // start loading edges around it. Not having a top-left item at | - | ||||||||||||||||||
| 1033 | // this point means that the model is empty (or no delegate). | - | ||||||||||||||||||
| 1034 | return; executed 102 times by 1 test: return;Executed by:
| 102 | ||||||||||||||||||
| 1035 | } | - | ||||||||||||||||||
| 1036 | - | |||||||||||||||||||
| 1037 | const QRectF unloadRect = hasBufferedItems ? bufferRect() : viewportRect;
| 0 | ||||||||||||||||||
| 1038 | bool tableModified; | - | ||||||||||||||||||
| 1039 | - | |||||||||||||||||||
| 1040 | do { | - | ||||||||||||||||||
| 1041 | tableModified = false; | - | ||||||||||||||||||
| 1042 | - | |||||||||||||||||||
| 1043 | if (Qt::Edge edge = nextEdgeToUnload(unloadRect)) {
| 0 | ||||||||||||||||||
| 1044 | tableModified = true; | - | ||||||||||||||||||
| 1045 | unloadEdge(edge); | - | ||||||||||||||||||
| 1046 | } never executed: end of block | 0 | ||||||||||||||||||
| 1047 | - | |||||||||||||||||||
| 1048 | if (Qt::Edge edge = nextEdgeToLoad(viewportRect)) {
| 0 | ||||||||||||||||||
| 1049 | tableModified = true; | - | ||||||||||||||||||
| 1050 | loadEdge(edge, QQmlIncubator::AsynchronousIfNested); | - | ||||||||||||||||||
| 1051 | if (loadRequest.isActive())
| 0 | ||||||||||||||||||
| 1052 | return; never executed: return; | 0 | ||||||||||||||||||
| 1053 | } never executed: end of block | 0 | ||||||||||||||||||
| 1054 | } while (tableModified); never executed: end of block
| 0 | ||||||||||||||||||
| 1055 | - | |||||||||||||||||||
| 1056 | } never executed: end of block | 0 | ||||||||||||||||||
| 1057 | - | |||||||||||||||||||
| 1058 | void QQuickTableViewPrivate::loadBuffer() | - | ||||||||||||||||||
| 1059 | { | - | ||||||||||||||||||
| 1060 | // Rather than making sure to stop the timer from all locations that can | - | ||||||||||||||||||
| 1061 | // violate the "buffering allowed" state, we just check that we're in the | - | ||||||||||||||||||
| 1062 | // right state here before we start buffering. | - | ||||||||||||||||||
| 1063 | if (cacheBuffer <= 0 || loadRequest.isActive() || loadedItems.isEmpty())
| 0 | ||||||||||||||||||
| 1064 | return; never executed: return; | 0 | ||||||||||||||||||
| 1065 | - | |||||||||||||||||||
| 1066 | qCDebug(lcTableViewDelegateLifecycle()); never executed: QMessageLogger(__FILE__, 1066, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle()().categoryName()).debug();
| 0 | ||||||||||||||||||
| 1067 | const QRectF loadRect = bufferRect(); | - | ||||||||||||||||||
| 1068 | while (Qt::Edge edge = nextEdgeToLoad(loadRect)) {
| 0 | ||||||||||||||||||
| 1069 | loadEdge(edge, QQmlIncubator::Asynchronous); | - | ||||||||||||||||||
| 1070 | if (loadRequest.isActive())
| 0 | ||||||||||||||||||
| 1071 | break; never executed: break; | 0 | ||||||||||||||||||
| 1072 | } never executed: end of block | 0 | ||||||||||||||||||
| 1073 | - | |||||||||||||||||||
| 1074 | hasBufferedItems = true; | - | ||||||||||||||||||
| 1075 | } never executed: end of block | 0 | ||||||||||||||||||
| 1076 | - | |||||||||||||||||||
| 1077 | void QQuickTableViewPrivate::unloadBuffer() | - | ||||||||||||||||||
| 1078 | { | - | ||||||||||||||||||
| 1079 | if (!hasBufferedItems)
| 0-102 | ||||||||||||||||||
| 1080 | return; executed 102 times by 1 test: return;Executed by:
| 102 | ||||||||||||||||||
| 1081 | - | |||||||||||||||||||
| 1082 | qCDebug(lcTableViewDelegateLifecycle()); never executed: QMessageLogger(__FILE__, 1082, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle()().categoryName()).debug();
| 0 | ||||||||||||||||||
| 1083 | hasBufferedItems = false; | - | ||||||||||||||||||
| 1084 | cacheBufferDelayTimer.stop(); | - | ||||||||||||||||||
| 1085 | if (loadRequest.isActive())
| 0 | ||||||||||||||||||
| 1086 | cancelLoadRequest(); never executed: cancelLoadRequest(); | 0 | ||||||||||||||||||
| 1087 | while (Qt::Edge edge = nextEdgeToUnload(viewportRect))
| 0 | ||||||||||||||||||
| 1088 | unloadEdge(edge); never executed: unloadEdge(edge); | 0 | ||||||||||||||||||
| 1089 | } never executed: end of block | 0 | ||||||||||||||||||
| 1090 | - | |||||||||||||||||||
| 1091 | QRectF QQuickTableViewPrivate::bufferRect() | - | ||||||||||||||||||
| 1092 | { | - | ||||||||||||||||||
| 1093 | return viewportRect.adjusted(-cacheBuffer, -cacheBuffer, cacheBuffer, cacheBuffer); never executed: return viewportRect.adjusted(-cacheBuffer, -cacheBuffer, cacheBuffer, cacheBuffer); | 0 | ||||||||||||||||||
| 1094 | } | - | ||||||||||||||||||
| 1095 | - | |||||||||||||||||||
| 1096 | void QQuickTableViewPrivate::invalidateTable() { | - | ||||||||||||||||||
| 1097 | tableInvalid = true; | - | ||||||||||||||||||
| 1098 | if (loadRequest.isActive())
| 0-102 | ||||||||||||||||||
| 1099 | cancelLoadRequest(); never executed: cancelLoadRequest(); | 0 | ||||||||||||||||||
| 1100 | q_func()->polish(); | - | ||||||||||||||||||
| 1101 | } executed 102 times by 1 test: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 1102 | - | |||||||||||||||||||
| 1103 | void QQuickTableViewPrivate::invalidateColumnRowPositions() { | - | ||||||||||||||||||
| 1104 | columnRowPositionsInvalid = true; | - | ||||||||||||||||||
| 1105 | q_func()->polish(); | - | ||||||||||||||||||
| 1106 | } executed 200 times by 1 test: end of blockExecuted by:
| 200 | ||||||||||||||||||
| 1107 | - | |||||||||||||||||||
| 1108 | void QQuickTableViewPrivate::updatePolish() | - | ||||||||||||||||||
| 1109 | { | - | ||||||||||||||||||
| 1110 | // Whenever something changes, e.g viewport moves, spacing is set to a | - | ||||||||||||||||||
| 1111 | // new value, model changes etc, this function will end up being called. Here | - | ||||||||||||||||||
| 1112 | // we check what needs to be done, and load/unload cells accordingly. | - | ||||||||||||||||||
| 1113 | Q_Q(QQuickTableView); | - | ||||||||||||||||||
| 1114 | - | |||||||||||||||||||
| 1115 | if (loadRequest.isActive()) {
| 0-306 | ||||||||||||||||||
| 1116 | // We're currently loading items async to build a new edge in the table. We see the loading | - | ||||||||||||||||||
| 1117 | // as an atomic operation, which means that we don't continue doing anything else until all | - | ||||||||||||||||||
| 1118 | // items have been received and laid out. Note that updatePolish is then called once more | - | ||||||||||||||||||
| 1119 | // after the loadRequest has completed to handle anything that might have occurred in-between. | - | ||||||||||||||||||
| 1120 | return; never executed: return; | 0 | ||||||||||||||||||
| 1121 | } | - | ||||||||||||||||||
| 1122 | - | |||||||||||||||||||
| 1123 | // viewportRect describes the part of the content view that is actually visible. Since a | - | ||||||||||||||||||
| 1124 | // negative width/height can happen (e.g during start-up), we check for this to avoid rebuilding | - | ||||||||||||||||||
| 1125 | // the table (and e.g calculate initial row/column sizes) based on a premature viewport rect. | - | ||||||||||||||||||
| 1126 | viewportRect = QRectF(q->contentX(), q->contentY(), q->width(), q->height()); | - | ||||||||||||||||||
| 1127 | if (!viewportRect.isValid())
| 102-204 | ||||||||||||||||||
| 1128 | return; executed 102 times by 1 test: return;Executed by:
| 102 | ||||||||||||||||||
| 1129 | - | |||||||||||||||||||
| 1130 | if (tableInvalid) {
| 102 | ||||||||||||||||||
| 1131 | beginRebuildTable(); | - | ||||||||||||||||||
| 1132 | if (loadRequest.isActive())
| 0-102 | ||||||||||||||||||
| 1133 | return; never executed: return; | 0 | ||||||||||||||||||
| 1134 | } executed 102 times by 1 test: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 1135 | - | |||||||||||||||||||
| 1136 | if (tableRebuilding)
| 102 | ||||||||||||||||||
| 1137 | endRebuildTable(); executed 102 times by 1 test: endRebuildTable();Executed by:
| 102 | ||||||||||||||||||
| 1138 | - | |||||||||||||||||||
| 1139 | if (loadedItems.isEmpty()) {
| 0-204 | ||||||||||||||||||
| 1140 | qCDebug(lcTableViewDelegateLifecycle()) << "no items loaded, meaning empty model or no delegate"; never executed: QMessageLogger(__FILE__, 1140, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle()().categoryName()).debug() << "no items loaded, meaning empty model or no delegate";
| 0-204 | ||||||||||||||||||
| 1141 | return; executed 204 times by 1 test: return;Executed by:
| 204 | ||||||||||||||||||
| 1142 | } | - | ||||||||||||||||||
| 1143 | - | |||||||||||||||||||
| 1144 | if (columnRowPositionsInvalid)
| 0 | ||||||||||||||||||
| 1145 | relayoutTable(); never executed: relayoutTable(); | 0 | ||||||||||||||||||
| 1146 | - | |||||||||||||||||||
| 1147 | if (hasBufferedItems && nextEdgeToLoad(viewportRect)) {
| 0 | ||||||||||||||||||
| 1148 | // We are about to load more edges, so trim down the table as much | - | ||||||||||||||||||
| 1149 | // as possible to avoid loading cells that are outside the viewport. | - | ||||||||||||||||||
| 1150 | unloadBuffer(); | - | ||||||||||||||||||
| 1151 | } never executed: end of block | 0 | ||||||||||||||||||
| 1152 | - | |||||||||||||||||||
| 1153 | loadAndUnloadVisibleEdges(); | - | ||||||||||||||||||
| 1154 | - | |||||||||||||||||||
| 1155 | if (loadRequest.isActive())
| 0 | ||||||||||||||||||
| 1156 | return; never executed: return; | 0 | ||||||||||||||||||
| 1157 | - | |||||||||||||||||||
| 1158 | if (cacheBuffer > 0) {
| 0 | ||||||||||||||||||
| 1159 | // When polish hasn't been called for a while (which means that the viewport | - | ||||||||||||||||||
| 1160 | // rect hasn't changed), we start buffering items. We delay this operation by | - | ||||||||||||||||||
| 1161 | // using a timer to increase performance (by not loading hidden items) while | - | ||||||||||||||||||
| 1162 | // the user is flicking. | - | ||||||||||||||||||
| 1163 | cacheBufferDelayTimer.start(kBufferTimerInterval); | - | ||||||||||||||||||
| 1164 | } never executed: end of block | 0 | ||||||||||||||||||
| 1165 | } never executed: end of block | 0 | ||||||||||||||||||
| 1166 | - | |||||||||||||||||||
| 1167 | void QQuickTableViewPrivate::createWrapperModel() | - | ||||||||||||||||||
| 1168 | { | - | ||||||||||||||||||
| 1169 | Q_Q(QQuickTableView); | - | ||||||||||||||||||
| 1170 | - | |||||||||||||||||||
| 1171 | delegateModel = new QQmlDelegateModel(qmlContext(q), q); | - | ||||||||||||||||||
| 1172 | if (q->isComponentComplete())
| 0-102 | ||||||||||||||||||
| 1173 | delegateModel->componentComplete(); never executed: delegateModel->componentComplete(); | 0 | ||||||||||||||||||
| 1174 | model = delegateModel; | - | ||||||||||||||||||
| 1175 | } executed 102 times by 1 test: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 1176 | - | |||||||||||||||||||
| 1177 | void QQuickTableViewPrivate::itemCreatedCallback(int modelIndex, QObject*) | - | ||||||||||||||||||
| 1178 | { | - | ||||||||||||||||||
| 1179 | if (blockItemCreatedCallback)
| 0 | ||||||||||||||||||
| 1180 | return; never executed: return; | 0 | ||||||||||||||||||
| 1181 | - | |||||||||||||||||||
| 1182 | qCDebug(lcTableViewDelegateLifecycle) << "item done loading:" never executed: QMessageLogger(__FILE__, 1182, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle().categoryName()).debug() << "item done loading:" << cellAtModelIndex(modelIndex);
| 0 | ||||||||||||||||||
| 1183 | << cellAtModelIndex(modelIndex); never executed: QMessageLogger(__FILE__, 1182, __PRETTY_FUNCTION__, lcTableViewDelegateLifecycle().categoryName()).debug() << "item done loading:" << cellAtModelIndex(modelIndex); | 0 | ||||||||||||||||||
| 1184 | - | |||||||||||||||||||
| 1185 | // Since the item we waited for has finished incubating, we can | - | ||||||||||||||||||
| 1186 | // continue with the load request. processLoadRequest will | - | ||||||||||||||||||
| 1187 | // ask the model for the requested item once more, which will be | - | ||||||||||||||||||
| 1188 | // quick since the model has cached it. | - | ||||||||||||||||||
| 1189 | processLoadRequest(); | - | ||||||||||||||||||
| 1190 | loadAndUnloadVisibleEdges(); | - | ||||||||||||||||||
| 1191 | updatePolish(); | - | ||||||||||||||||||
| 1192 | } never executed: end of block | 0 | ||||||||||||||||||
| 1193 | - | |||||||||||||||||||
| 1194 | void QQuickTableViewPrivate::initItemCallback(int modelIndex, QObject *object) | - | ||||||||||||||||||
| 1195 | { | - | ||||||||||||||||||
| 1196 | Q_UNUSED(modelIndex); | - | ||||||||||||||||||
| 1197 | auto attached = getAttachedObject(object); | - | ||||||||||||||||||
| 1198 | if (!attached)
| 0 | ||||||||||||||||||
| 1199 | return; never executed: return; | 0 | ||||||||||||||||||
| 1200 | - | |||||||||||||||||||
| 1201 | // Even though row and column is injected directly into the context of a delegate item | - | ||||||||||||||||||
| 1202 | // from QQmlDelegateModel and its model classes, they will only return which row and | - | ||||||||||||||||||
| 1203 | // column an item represents in the model. This might be different from which | - | ||||||||||||||||||
| 1204 | // cell an item ends up in in the Table, if a different rows/columns has been set | - | ||||||||||||||||||
| 1205 | // on it (which is typically the case for list models). For those cases, Table.row | - | ||||||||||||||||||
| 1206 | // and Table.column can be helpful. | - | ||||||||||||||||||
| 1207 | QPoint cell = cellAtModelIndex(modelIndex); | - | ||||||||||||||||||
| 1208 | attached->setTableView(q_func()); | - | ||||||||||||||||||
| 1209 | attached->setColumn(cell.x()); | - | ||||||||||||||||||
| 1210 | attached->setRow(cell.y()); | - | ||||||||||||||||||
| 1211 | } never executed: end of block | 0 | ||||||||||||||||||
| 1212 | - | |||||||||||||||||||
| 1213 | void QQuickTableViewPrivate::modelUpdated(const QQmlChangeSet &changeSet, bool reset) | - | ||||||||||||||||||
| 1214 | { | - | ||||||||||||||||||
| 1215 | Q_UNUSED(changeSet); | - | ||||||||||||||||||
| 1216 | Q_UNUSED(reset); | - | ||||||||||||||||||
| 1217 | - | |||||||||||||||||||
| 1218 | // TODO: implement fine-grained support for model changes | - | ||||||||||||||||||
| 1219 | invalidateTable(); | - | ||||||||||||||||||
| 1220 | } never executed: end of block | 0 | ||||||||||||||||||
| 1221 | - | |||||||||||||||||||
| 1222 | QQuickTableView::QQuickTableView(QQuickItem *parent) | - | ||||||||||||||||||
| 1223 | : QQuickFlickable(*(new QQuickTableViewPrivate), parent) | - | ||||||||||||||||||
| 1224 | { | - | ||||||||||||||||||
| 1225 | } executed 102 times by 1 test: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 1226 | - | |||||||||||||||||||
| 1227 | int QQuickTableView::rows() const | - | ||||||||||||||||||
| 1228 | { | - | ||||||||||||||||||
| 1229 | return d_func()->tableSize.height(); never executed: return d_func()->tableSize.height(); | 0 | ||||||||||||||||||
| 1230 | } | - | ||||||||||||||||||
| 1231 | - | |||||||||||||||||||
| 1232 | int QQuickTableView::columns() const | - | ||||||||||||||||||
| 1233 | { | - | ||||||||||||||||||
| 1234 | return d_func()->tableSize.width(); never executed: return d_func()->tableSize.width(); | 0 | ||||||||||||||||||
| 1235 | } | - | ||||||||||||||||||
| 1236 | - | |||||||||||||||||||
| 1237 | qreal QQuickTableView::rowSpacing() const | - | ||||||||||||||||||
| 1238 | { | - | ||||||||||||||||||
| 1239 | return d_func()->cellSpacing.height(); never executed: return d_func()->cellSpacing.height(); | 0 | ||||||||||||||||||
| 1240 | } | - | ||||||||||||||||||
| 1241 | - | |||||||||||||||||||
| 1242 | void QQuickTableView::setRowSpacing(qreal spacing) | - | ||||||||||||||||||
| 1243 | { | - | ||||||||||||||||||
| 1244 | Q_D(QQuickTableView); | - | ||||||||||||||||||
| 1245 | if (qFuzzyCompare(d->cellSpacing.height(), spacing))
| 0-100 | ||||||||||||||||||
| 1246 | return; never executed: return; | 0 | ||||||||||||||||||
| 1247 | - | |||||||||||||||||||
| 1248 | d->cellSpacing.setHeight(spacing); | - | ||||||||||||||||||
| 1249 | d->invalidateColumnRowPositions(); | - | ||||||||||||||||||
| 1250 | emit rowSpacingChanged(); | - | ||||||||||||||||||
| 1251 | } executed 100 times by 1 test: end of blockExecuted by:
| 100 | ||||||||||||||||||
| 1252 | - | |||||||||||||||||||
| 1253 | qreal QQuickTableView::columnSpacing() const | - | ||||||||||||||||||
| 1254 | { | - | ||||||||||||||||||
| 1255 | return d_func()->cellSpacing.width(); never executed: return d_func()->cellSpacing.width(); | 0 | ||||||||||||||||||
| 1256 | } | - | ||||||||||||||||||
| 1257 | - | |||||||||||||||||||
| 1258 | void QQuickTableView::setColumnSpacing(qreal spacing) | - | ||||||||||||||||||
| 1259 | { | - | ||||||||||||||||||
| 1260 | Q_D(QQuickTableView); | - | ||||||||||||||||||
| 1261 | if (qFuzzyCompare(d->cellSpacing.width(), spacing))
| 0-100 | ||||||||||||||||||
| 1262 | return; never executed: return; | 0 | ||||||||||||||||||
| 1263 | - | |||||||||||||||||||
| 1264 | d->cellSpacing.setWidth(spacing); | - | ||||||||||||||||||
| 1265 | d->invalidateColumnRowPositions(); | - | ||||||||||||||||||
| 1266 | emit columnSpacingChanged(); | - | ||||||||||||||||||
| 1267 | } executed 100 times by 1 test: end of blockExecuted by:
| 100 | ||||||||||||||||||
| 1268 | - | |||||||||||||||||||
| 1269 | qreal QQuickTableView::topMargin() const | - | ||||||||||||||||||
| 1270 | { | - | ||||||||||||||||||
| 1271 | return d_func()->tableMargins.top(); never executed: return d_func()->tableMargins.top(); | 0 | ||||||||||||||||||
| 1272 | } | - | ||||||||||||||||||
| 1273 | - | |||||||||||||||||||
| 1274 | void QQuickTableView::setTopMargin(qreal margin) | - | ||||||||||||||||||
| 1275 | { | - | ||||||||||||||||||
| 1276 | Q_D(QQuickTableView); | - | ||||||||||||||||||
| 1277 | if (qt_is_nan(margin))
| 0 | ||||||||||||||||||
| 1278 | return; never executed: return; | 0 | ||||||||||||||||||
| 1279 | if (qFuzzyCompare(d->tableMargins.top(), margin))
| 0 | ||||||||||||||||||
| 1280 | return; never executed: return; | 0 | ||||||||||||||||||
| 1281 | - | |||||||||||||||||||
| 1282 | d->tableMargins.setTop(margin); | - | ||||||||||||||||||
| 1283 | d->invalidateColumnRowPositions(); | - | ||||||||||||||||||
| 1284 | emit topMarginChanged(); | - | ||||||||||||||||||
| 1285 | } never executed: end of block | 0 | ||||||||||||||||||
| 1286 | - | |||||||||||||||||||
| 1287 | qreal QQuickTableView::bottomMargin() const | - | ||||||||||||||||||
| 1288 | { | - | ||||||||||||||||||
| 1289 | return d_func()->tableMargins.bottom(); never executed: return d_func()->tableMargins.bottom(); | 0 | ||||||||||||||||||
| 1290 | } | - | ||||||||||||||||||
| 1291 | - | |||||||||||||||||||
| 1292 | void QQuickTableView::setBottomMargin(qreal margin) | - | ||||||||||||||||||
| 1293 | { | - | ||||||||||||||||||
| 1294 | Q_D(QQuickTableView); | - | ||||||||||||||||||
| 1295 | if (qt_is_nan(margin))
| 0 | ||||||||||||||||||
| 1296 | return; never executed: return; | 0 | ||||||||||||||||||
| 1297 | if (qFuzzyCompare(d->tableMargins.bottom(), margin))
| 0 | ||||||||||||||||||
| 1298 | return; never executed: return; | 0 | ||||||||||||||||||
| 1299 | - | |||||||||||||||||||
| 1300 | d->tableMargins.setBottom(margin); | - | ||||||||||||||||||
| 1301 | d->invalidateColumnRowPositions(); | - | ||||||||||||||||||
| 1302 | emit bottomMarginChanged(); | - | ||||||||||||||||||
| 1303 | } never executed: end of block | 0 | ||||||||||||||||||
| 1304 | - | |||||||||||||||||||
| 1305 | qreal QQuickTableView::leftMargin() const | - | ||||||||||||||||||
| 1306 | { | - | ||||||||||||||||||
| 1307 | return d_func()->tableMargins.left(); never executed: return d_func()->tableMargins.left(); | 0 | ||||||||||||||||||
| 1308 | } | - | ||||||||||||||||||
| 1309 | - | |||||||||||||||||||
| 1310 | void QQuickTableView::setLeftMargin(qreal margin) | - | ||||||||||||||||||
| 1311 | { | - | ||||||||||||||||||
| 1312 | Q_D(QQuickTableView); | - | ||||||||||||||||||
| 1313 | if (qt_is_nan(margin))
| 0 | ||||||||||||||||||
| 1314 | return; never executed: return; | 0 | ||||||||||||||||||
| 1315 | if (qFuzzyCompare(d->tableMargins.left(), margin))
| 0 | ||||||||||||||||||
| 1316 | return; never executed: return; | 0 | ||||||||||||||||||
| 1317 | - | |||||||||||||||||||
| 1318 | d->tableMargins.setLeft(margin); | - | ||||||||||||||||||
| 1319 | d->invalidateColumnRowPositions(); | - | ||||||||||||||||||
| 1320 | emit leftMarginChanged(); | - | ||||||||||||||||||
| 1321 | } never executed: end of block | 0 | ||||||||||||||||||
| 1322 | - | |||||||||||||||||||
| 1323 | qreal QQuickTableView::rightMargin() const | - | ||||||||||||||||||
| 1324 | { | - | ||||||||||||||||||
| 1325 | return d_func()->tableMargins.right(); never executed: return d_func()->tableMargins.right(); | 0 | ||||||||||||||||||
| 1326 | } | - | ||||||||||||||||||
| 1327 | - | |||||||||||||||||||
| 1328 | void QQuickTableView::setRightMargin(qreal margin) | - | ||||||||||||||||||
| 1329 | { | - | ||||||||||||||||||
| 1330 | Q_D(QQuickTableView); | - | ||||||||||||||||||
| 1331 | if (qt_is_nan(margin))
| 0 | ||||||||||||||||||
| 1332 | return; never executed: return; | 0 | ||||||||||||||||||
| 1333 | if (qFuzzyCompare(d->tableMargins.right(), margin))
| 0 | ||||||||||||||||||
| 1334 | return; never executed: return; | 0 | ||||||||||||||||||
| 1335 | - | |||||||||||||||||||
| 1336 | d->tableMargins.setRight(margin); | - | ||||||||||||||||||
| 1337 | d->invalidateColumnRowPositions(); | - | ||||||||||||||||||
| 1338 | emit rightMarginChanged(); | - | ||||||||||||||||||
| 1339 | } never executed: end of block | 0 | ||||||||||||||||||
| 1340 | - | |||||||||||||||||||
| 1341 | int QQuickTableView::cacheBuffer() const | - | ||||||||||||||||||
| 1342 | { | - | ||||||||||||||||||
| 1343 | return d_func()->cacheBuffer; never executed: return d_func()->cacheBuffer; | 0 | ||||||||||||||||||
| 1344 | } | - | ||||||||||||||||||
| 1345 | - | |||||||||||||||||||
| 1346 | void QQuickTableView::setCacheBuffer(int newBuffer) | - | ||||||||||||||||||
| 1347 | { | - | ||||||||||||||||||
| 1348 | Q_D(QQuickTableView); | - | ||||||||||||||||||
| 1349 | if (d->cacheBuffer == newBuffer || newBuffer < 0)
| 0-102 | ||||||||||||||||||
| 1350 | return; never executed: return; | 0 | ||||||||||||||||||
| 1351 | - | |||||||||||||||||||
| 1352 | d->cacheBuffer = newBuffer; | - | ||||||||||||||||||
| 1353 | - | |||||||||||||||||||
| 1354 | if (newBuffer == 0)
| 0-102 | ||||||||||||||||||
| 1355 | d->unloadBuffer(); executed 102 times by 1 test: d->unloadBuffer();Executed by:
| 102 | ||||||||||||||||||
| 1356 | - | |||||||||||||||||||
| 1357 | emit cacheBufferChanged(); | - | ||||||||||||||||||
| 1358 | polish(); | - | ||||||||||||||||||
| 1359 | } executed 102 times by 1 test: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 1360 | - | |||||||||||||||||||
| 1361 | QVariant QQuickTableView::model() const | - | ||||||||||||||||||
| 1362 | { | - | ||||||||||||||||||
| 1363 | return d_func()->modelVariant; never executed: return d_func()->modelVariant; | 0 | ||||||||||||||||||
| 1364 | } | - | ||||||||||||||||||
| 1365 | - | |||||||||||||||||||
| 1366 | void QQuickTableView::setModel(const QVariant &newModel) | - | ||||||||||||||||||
| 1367 | { | - | ||||||||||||||||||
| 1368 | Q_D(QQuickTableView); | - | ||||||||||||||||||
| 1369 | - | |||||||||||||||||||
| 1370 | d->modelVariant = newModel; | - | ||||||||||||||||||
| 1371 | QVariant effectiveModelVariant = d->modelVariant; | - | ||||||||||||||||||
| 1372 | if (effectiveModelVariant.userType() == qMetaTypeId<QJSValue>())
| 0 | ||||||||||||||||||
| 1373 | effectiveModelVariant = effectiveModelVariant.value<QJSValue>().toVariant(); never executed: effectiveModelVariant = effectiveModelVariant.value<QJSValue>().toVariant(); | 0 | ||||||||||||||||||
| 1374 | - | |||||||||||||||||||
| 1375 | if (d->model) {
| 0 | ||||||||||||||||||
| 1376 | QObjectPrivate::disconnect(d->model, &QQmlInstanceModel::createdItem, d, &QQuickTableViewPrivate::itemCreatedCallback); | - | ||||||||||||||||||
| 1377 | QObjectPrivate::disconnect(d->model, &QQmlInstanceModel::initItem, d, &QQuickTableViewPrivate::initItemCallback); | - | ||||||||||||||||||
| 1378 | QObjectPrivate::disconnect(d->model, &QQmlInstanceModel::modelUpdated, d, &QQuickTableViewPrivate::modelUpdated); | - | ||||||||||||||||||
| 1379 | } never executed: end of block | 0 | ||||||||||||||||||
| 1380 | - | |||||||||||||||||||
| 1381 | const auto instanceModel = qobject_cast<QQmlInstanceModel *>(qvariant_cast<QObject*>(effectiveModelVariant)); | - | ||||||||||||||||||
| 1382 | - | |||||||||||||||||||
| 1383 | if (instanceModel) {
| 0 | ||||||||||||||||||
| 1384 | if (d->delegateModel)
| 0 | ||||||||||||||||||
| 1385 | delete d->delegateModel; never executed: delete d->delegateModel; | 0 | ||||||||||||||||||
| 1386 | d->model = instanceModel; | - | ||||||||||||||||||
| 1387 | d->delegateModel = qmlobject_cast<QQmlDelegateModel *>(instanceModel); | - | ||||||||||||||||||
| 1388 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1389 | if (!d->delegateModel)
| 0 | ||||||||||||||||||
| 1390 | d->createWrapperModel(); never executed: d->createWrapperModel(); | 0 | ||||||||||||||||||
| 1391 | QQmlDelegateModelPrivate::get(d->delegateModel)->m_useFirstColumnOnly = false; | - | ||||||||||||||||||
| 1392 | d->delegateModel->setModel(effectiveModelVariant); | - | ||||||||||||||||||
| 1393 | } never executed: end of block | 0 | ||||||||||||||||||
| 1394 | - | |||||||||||||||||||
| 1395 | Q_ASSERT(d->model); | - | ||||||||||||||||||
| 1396 | QObjectPrivate::connect(d->model, &QQmlInstanceModel::createdItem, d, &QQuickTableViewPrivate::itemCreatedCallback); | - | ||||||||||||||||||
| 1397 | QObjectPrivate::connect(d->model, &QQmlInstanceModel::initItem, d, &QQuickTableViewPrivate::initItemCallback); | - | ||||||||||||||||||
| 1398 | QObjectPrivate::connect(d->model, &QQmlInstanceModel::modelUpdated, d, &QQuickTableViewPrivate::modelUpdated); | - | ||||||||||||||||||
| 1399 | - | |||||||||||||||||||
| 1400 | d->invalidateTable(); | - | ||||||||||||||||||
| 1401 | - | |||||||||||||||||||
| 1402 | emit modelChanged(); | - | ||||||||||||||||||
| 1403 | } never executed: end of block | 0 | ||||||||||||||||||
| 1404 | - | |||||||||||||||||||
| 1405 | QQmlComponent *QQuickTableView::delegate() const | - | ||||||||||||||||||
| 1406 | { | - | ||||||||||||||||||
| 1407 | Q_D(const QQuickTableView); | - | ||||||||||||||||||
| 1408 | if (d->delegateModel)
| 0-102 | ||||||||||||||||||
| 1409 | return d->delegateModel->delegate(); never executed: return d->delegateModel->delegate(); | 0 | ||||||||||||||||||
| 1410 | - | |||||||||||||||||||
| 1411 | return nullptr; executed 102 times by 1 test: return nullptr;Executed by:
| 102 | ||||||||||||||||||
| 1412 | } | - | ||||||||||||||||||
| 1413 | - | |||||||||||||||||||
| 1414 | void QQuickTableView::setDelegate(QQmlComponent *newDelegate) | - | ||||||||||||||||||
| 1415 | { | - | ||||||||||||||||||
| 1416 | Q_D(QQuickTableView); | - | ||||||||||||||||||
| 1417 | if (newDelegate == delegate())
| 0-102 | ||||||||||||||||||
| 1418 | return; never executed: return; | 0 | ||||||||||||||||||
| 1419 | - | |||||||||||||||||||
| 1420 | if (!d->delegateModel)
| 0-102 | ||||||||||||||||||
| 1421 | d->createWrapperModel(); executed 102 times by 1 test: d->createWrapperModel();Executed by:
| 102 | ||||||||||||||||||
| 1422 | - | |||||||||||||||||||
| 1423 | d->delegateModel->setDelegate(newDelegate); | - | ||||||||||||||||||
| 1424 | d->invalidateTable(); | - | ||||||||||||||||||
| 1425 | - | |||||||||||||||||||
| 1426 | emit delegateChanged(); | - | ||||||||||||||||||
| 1427 | } executed 102 times by 1 test: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 1428 | - | |||||||||||||||||||
| 1429 | QQuickTableViewAttached *QQuickTableView::qmlAttachedProperties(QObject *obj) | - | ||||||||||||||||||
| 1430 | { | - | ||||||||||||||||||
| 1431 | return new QQuickTableViewAttached(obj); never executed: return new QQuickTableViewAttached(obj); | 0 | ||||||||||||||||||
| 1432 | } | - | ||||||||||||||||||
| 1433 | - | |||||||||||||||||||
| 1434 | void QQuickTableView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | - | ||||||||||||||||||
| 1435 | { | - | ||||||||||||||||||
| 1436 | Q_D(QQuickTableView); | - | ||||||||||||||||||
| 1437 | QQuickFlickable::geometryChanged(newGeometry, oldGeometry); | - | ||||||||||||||||||
| 1438 | // We update the viewport rect from within updatePolish to | - | ||||||||||||||||||
| 1439 | // ensure that we update when we're ready to update, and not | - | ||||||||||||||||||
| 1440 | // while we're in the middle of loading/unloading edges. | - | ||||||||||||||||||
| 1441 | d->updatePolish(); | - | ||||||||||||||||||
| 1442 | } executed 204 times by 1 test: end of blockExecuted by:
| 204 | ||||||||||||||||||
| 1443 | - | |||||||||||||||||||
| 1444 | void QQuickTableView::viewportMoved(Qt::Orientations orientation) | - | ||||||||||||||||||
| 1445 | { | - | ||||||||||||||||||
| 1446 | Q_D(QQuickTableView); | - | ||||||||||||||||||
| 1447 | QQuickFlickable::viewportMoved(orientation); | - | ||||||||||||||||||
| 1448 | // We update the viewport rect from within updatePolish to | - | ||||||||||||||||||
| 1449 | // ensure that we update when we're ready to update, and not | - | ||||||||||||||||||
| 1450 | // while we're in the middle of loading/unloading edges. | - | ||||||||||||||||||
| 1451 | d->updatePolish(); | - | ||||||||||||||||||
| 1452 | } never executed: end of block | 0 | ||||||||||||||||||
| 1453 | - | |||||||||||||||||||
| 1454 | void QQuickTableView::componentComplete() | - | ||||||||||||||||||
| 1455 | { | - | ||||||||||||||||||
| 1456 | Q_D(QQuickTableView); | - | ||||||||||||||||||
| 1457 | - | |||||||||||||||||||
| 1458 | if (!d->model)
| 0-102 | ||||||||||||||||||
| 1459 | setModel(QVariant()); never executed: setModel(QVariant()); | 0 | ||||||||||||||||||
| 1460 | - | |||||||||||||||||||
| 1461 | if (d->delegateModel)
| 0-102 | ||||||||||||||||||
| 1462 | d->delegateModel->componentComplete(); executed 102 times by 1 test: d->delegateModel->componentComplete();Executed by:
| 102 | ||||||||||||||||||
| 1463 | - | |||||||||||||||||||
| 1464 | QQuickFlickable::componentComplete(); | - | ||||||||||||||||||
| 1465 | } executed 102 times by 1 test: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 1466 | - | |||||||||||||||||||
| 1467 | #include "moc_qquicktableview_p.cpp" | - | ||||||||||||||||||
| 1468 | - | |||||||||||||||||||
| 1469 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |