tidy&format(all): all files formatted and relevant warnings resolved
C++ / build (pull_request) Failing after 15s
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 28s
Python / lint-format (pull_request) Successful in 45s
Python / test (pull_request) Successful in 38s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m45s

This commit is contained in:
2026-06-30 02:04:24 +02:00
parent fed9372b35
commit 467e44bb9f
85 changed files with 4139 additions and 3738 deletions
+190 -264
View File
@@ -21,8 +21,7 @@ qreal LazyListViewAttached::preferredHeight() const {
}
void LazyListViewAttached::setPreferredHeight(qreal height) {
if (qFuzzyCompare(m_preferredHeight + 1.0, height + 1.0))
return;
if (qFuzzyCompare(m_preferredHeight + 1.0, height + 1.0)) return;
m_preferredHeight = height;
emit preferredHeightChanged();
}
@@ -32,8 +31,7 @@ qreal LazyListViewAttached::visibleHeight() const {
}
void LazyListViewAttached::setVisibleHeight(qreal height) {
if (qFuzzyCompare(m_visibleHeight + 1.0, height + 1.0))
return;
if (qFuzzyCompare(m_visibleHeight + 1.0, height + 1.0)) return;
m_visibleHeight = height;
emit visibleHeightChanged();
}
@@ -43,8 +41,7 @@ bool LazyListViewAttached::ready() const {
}
void LazyListViewAttached::setReady(bool ready) {
if (m_ready == ready)
return;
if (m_ready == ready) return;
m_ready = ready;
emit readyChanged();
}
@@ -54,8 +51,7 @@ bool LazyListViewAttached::adding() const {
}
void LazyListViewAttached::setAdding(bool adding) {
if (m_adding == adding)
return;
if (m_adding == adding) return;
m_adding = adding;
emit addingChanged();
}
@@ -65,8 +61,7 @@ bool LazyListViewAttached::removing() const {
}
void LazyListViewAttached::setRemoving(bool removing) {
if (m_removing == removing)
return;
if (m_removing == removing) return;
m_removing = removing;
emit removingChanged();
}
@@ -76,8 +71,7 @@ bool LazyListViewAttached::trackViewport() const {
}
void LazyListViewAttached::setTrackViewport(bool track) {
if (m_trackViewport == track)
return;
if (m_trackViewport == track) return;
m_trackViewport = track;
emit trackViewportChanged();
}
@@ -102,16 +96,13 @@ QAbstractItemModel* LazyListView::model() const {
}
void LazyListView::setModel(QAbstractItemModel* model) {
if (m_model == model)
return;
if (m_model == model) return;
if (m_model)
disconnectModel();
if (m_model) disconnectModel();
m_model = model;
if (m_model)
connectModel();
if (m_model) connectModel();
resetContent();
emit modelChanged();
@@ -122,8 +113,7 @@ QQmlComponent* LazyListView::delegate() const {
}
void LazyListView::setDelegate(QQmlComponent* delegate) {
if (m_delegate == delegate)
return;
if (m_delegate == delegate) return;
m_delegate = delegate;
resetContent();
@@ -135,8 +125,7 @@ qreal LazyListView::spacing() const {
}
void LazyListView::setSpacing(qreal spacing) {
if (qFuzzyCompare(m_spacing, spacing))
return;
if (qFuzzyCompare(m_spacing, spacing)) return;
m_spacing = spacing;
emit spacingChanged();
polish();
@@ -155,8 +144,7 @@ qreal LazyListView::contentY() const {
}
void LazyListView::setContentY(qreal contentY) {
if (qFuzzyCompare(m_contentY, contentY))
return;
if (qFuzzyCompare(m_contentY, contentY)) return;
m_contentY = contentY;
emit contentYChanged();
polish();
@@ -167,12 +155,10 @@ QRectF LazyListView::viewport() const {
}
void LazyListView::setViewport(const QRectF& viewport) {
if (m_viewport == viewport)
return;
if (m_viewport == viewport) return;
m_viewport = viewport;
emit viewportChanged();
if (m_useCustomViewport)
polish();
if (m_useCustomViewport) polish();
}
bool LazyListView::useCustomViewport() const {
@@ -180,8 +166,7 @@ bool LazyListView::useCustomViewport() const {
}
void LazyListView::setUseCustomViewport(bool use) {
if (m_useCustomViewport == use)
return;
if (m_useCustomViewport == use) return;
m_useCustomViewport = use;
emit useCustomViewportChanged();
polish();
@@ -192,8 +177,7 @@ qreal LazyListView::cacheBuffer() const {
}
void LazyListView::setCacheBuffer(qreal buffer) {
if (qFuzzyCompare(m_cacheBuffer, buffer))
return;
if (qFuzzyCompare(m_cacheBuffer, buffer)) return;
m_cacheBuffer = buffer;
emit cacheBufferChanged();
polish();
@@ -204,8 +188,7 @@ qreal LazyListView::estimatedHeight() const {
}
void LazyListView::setEstimatedHeight(qreal height) {
if (qFuzzyCompare(m_estimatedHeight, height))
return;
if (qFuzzyCompare(m_estimatedHeight, height)) return;
m_estimatedHeight = height;
emit estimatedHeightChanged();
polish();
@@ -216,17 +199,14 @@ bool LazyListView::asynchronous() const {
}
void LazyListView::setAsynchronous(bool async) {
if (m_asynchronous == async)
return;
if (m_asynchronous == async) return;
m_asynchronous = async;
emit asynchronousChanged();
}
qreal LazyListView::effectiveEstimatedHeight() const {
if (m_estimatedHeight >= 0)
return m_estimatedHeight;
if (m_knownHeightCount > 0)
return m_knownHeightSum / m_knownHeightCount;
if (m_estimatedHeight >= 0) return m_estimatedHeight;
if (m_knownHeightCount > 0) return m_knownHeightSum / m_knownHeightCount;
return 40;
}
@@ -241,8 +221,7 @@ void LazyListView::untrackHeight(qreal height) {
}
qreal LazyListView::delegateHeight(QQuickItem* item) {
if (!item)
return 0;
if (!item) return 0;
auto* attached = qobject_cast<LazyListViewAttached*>(
qmlAttachedPropertiesObject<LazyListView>(item, false));
@@ -253,14 +232,12 @@ qreal LazyListView::delegateHeight(QQuickItem* item) {
}
qreal LazyListView::delegateVisibleHeight(QQuickItem* item) {
if (!item)
return 0;
if (!item) return 0;
auto* attached = qobject_cast<LazyListViewAttached*>(
qmlAttachedPropertiesObject<LazyListView>(item, false));
if (attached) {
if (attached->visibleHeight() >= 0)
return attached->visibleHeight();
if (attached->visibleHeight() >= 0) return attached->visibleHeight();
if (attached->preferredHeight() >= 0)
return attached->preferredHeight();
}
@@ -269,8 +246,7 @@ qreal LazyListView::delegateVisibleHeight(QQuickItem* item) {
}
bool LazyListView::isDelegateReady(QQuickItem* item) {
if (!item)
return false;
if (!item) return false;
auto* att = qobject_cast<LazyListViewAttached*>(
qmlAttachedPropertiesObject<LazyListView>(item, false));
return !att || att->ready();
@@ -281,8 +257,7 @@ int LazyListView::removeDuration() const {
}
void LazyListView::setRemoveDuration(int duration) {
if (m_removeDuration == duration)
return;
if (m_removeDuration == duration) return;
m_removeDuration = duration;
emit removeDurationChanged();
}
@@ -292,8 +267,7 @@ int LazyListView::readyDelay() const {
}
void LazyListView::setReadyDelay(int delay) {
if (m_readyDelay == delay)
return;
if (m_readyDelay == delay) return;
m_readyDelay = delay;
emit readyDelayChanged();
}
@@ -308,17 +282,15 @@ void LazyListView::componentComplete() {
resetContent();
}
void LazyListView::geometryChange(const QRectF& newGeometry,
const QRectF& oldGeometry) {
void LazyListView::geometryChange(
const QRectF& newGeometry, const QRectF& oldGeometry) {
QQuickItem::geometryChange(newGeometry, oldGeometry);
if (!m_componentComplete)
return;
if (!m_componentComplete) return;
if (!qFuzzyCompare(newGeometry.width(), oldGeometry.width())) {
for (auto& entry : m_delegates) {
if (entry.item)
entry.item->setWidth(newGeometry.width());
if (entry.item) entry.item->setWidth(newGeometry.width());
}
}
@@ -326,8 +298,7 @@ void LazyListView::geometryChange(const QRectF& newGeometry,
}
void LazyListView::updatePolish() {
if (!m_componentComplete || !m_model || !m_delegate)
return;
if (!m_componentComplete || !m_model || !m_delegate) return;
// Flush pending inserts — make items visible and clear the adding flag
// so enter animations begin. When readyDelay > 0 the entire insert is
@@ -335,9 +306,9 @@ void LazyListView::updatePolish() {
// Collect pending indices first — avoids scanning the entire hash each frame
QList<int> pendingIndices;
for (auto it = m_delegates.constBegin(); it != m_delegates.constEnd(); ++it) {
if (it->pendingInsert && it->item)
pendingIndices.append(it.key());
for (auto it = m_delegates.constBegin(); it != m_delegates.constEnd();
++it) {
if (it->pendingInsert && it->item) pendingIndices.append(it.key());
}
for (int pendingIdx : pendingIndices) {
@@ -349,8 +320,7 @@ void LazyListView::updatePolish() {
auto* item = entry.item;
QTimer::singleShot(m_readyDelay, this, [this, item] {
auto indexIt = m_itemToIndex.find(item);
if (indexIt == m_itemToIndex.end())
return;
if (indexIt == m_itemToIndex.end()) return;
const int idx = indexIt.value();
auto it = m_delegates.find(idx);
if (it == m_delegates.end() || it->item != item ||
@@ -375,14 +345,11 @@ void LazyListView::updatePolish() {
? m_layout[i].height
: effectiveEstimatedHeight();
if (h > 0) {
if (hasVisItem)
visualY += m_spacing;
if (hasVisItem) visualY += m_spacing;
hasVisItem = true;
}
if (i == idx)
break;
if (h > 0)
visualY += h;
if (i == idx) break;
if (h > 0) visualY += h;
}
item->setY(visualY - m_contentY);
}
@@ -397,8 +364,8 @@ void LazyListView::updatePolish() {
// Animate from visual position to layout position
if (idx >= 0 && idx < static_cast<int>(m_layout.size()))
item->setProperty("y",
m_layout[idx].targetY - m_contentY);
item->setProperty(
"y", m_layout[idx].targetY - m_contentY);
polish();
});
@@ -432,8 +399,7 @@ void LazyListView::updatePolish() {
continue;
const int idx = entry.modelIndex;
if (idx < 0 || idx >= layoutSize)
continue;
if (idx < 0 || idx >= layoutSize) continue;
if (m_layout[idx].heightKnown && qFuzzyIsNull(m_layout[idx].height))
continue;
@@ -444,8 +410,6 @@ void LazyListView::updatePolish() {
}
}
// --- Layout Engine ---
void LazyListView::relayout() {
// Layout positioning uses preferredHeight (final/non-animated).
// Only add spacing between items with non-zero height.
@@ -455,8 +419,7 @@ void LazyListView::relayout() {
const qreal layoutH = record.heightKnown ? record.height
: effectiveEstimatedHeight();
if (layoutH > 0) {
if (hasLayoutItem)
y += m_spacing;
if (hasLayoutItem) y += m_spacing;
hasLayoutItem = true;
record.targetY = y;
y += layoutH;
@@ -483,8 +446,7 @@ void LazyListView::relayout() {
h = m_layout[i].heightKnown ? m_layout[i].height
: effectiveEstimatedHeight();
if (h > 0) {
if (hasVisItem)
visY += m_spacing;
if (hasVisItem) visY += m_spacing;
hasVisItem = true;
visY += h;
}
@@ -492,11 +454,9 @@ void LazyListView::relayout() {
// Account for dying delegates still visually present
for (const auto& dying : std::as_const(m_dyingDelegates)) {
if (!dying.item)
continue;
if (!dying.item) continue;
const qreal dyingH = delegateVisibleHeight(dying.item);
if (dyingH > 0)
visY = std::max(visY, dying.item->y() + dyingH);
if (dyingH > 0) visY = std::max(visY, dying.item->y() + dyingH);
}
if (!qFuzzyCompare(m_contentHeight + 1.0, visY + 1.0)) {
@@ -519,8 +479,7 @@ QRectF LazyListView::effectiveViewport() const {
if (!m_useCustomViewport && m_layoutHeight > 0) {
const qreal top = std::min(vp.y(), m_layoutHeight);
const qreal bottom = std::max(vp.y() + vp.height(), 0.0);
if (bottom > top)
vp = QRectF(vp.x(), top, vp.width(), bottom - top);
if (bottom > top) vp = QRectF(vp.x(), top, vp.width(), bottom - top);
}
vp.adjust(0, -m_cacheBuffer, 0, m_cacheBuffer);
@@ -541,12 +500,10 @@ QRectF LazyListView::effectiveViewport() const {
}
std::pair<int, int> LazyListView::computeVisibleRange() const {
if (m_layout.isEmpty())
return {-1, -1};
if (m_layout.isEmpty()) return {-1, -1};
const auto vp = effectiveViewport();
if (vp.isEmpty())
return {-1, -1};
if (vp.isEmpty()) return {-1, -1};
const qreal vpTop = vp.y();
const qreal vpBottom = vp.y() + vp.height();
@@ -571,22 +528,18 @@ std::pair<int, int> LazyListView::computeVisibleRange() const {
}
}
if (first >= static_cast<int>(m_layout.size()))
return {-1, -1};
if (first >= static_cast<int>(m_layout.size())) return {-1, -1};
// Linear scan for last visible item
int last = first;
for (int i = first; i < static_cast<int>(m_layout.size()); ++i) {
if (m_layout[i].targetY > vpBottom)
break;
if (m_layout[i].targetY > vpBottom) break;
last = i;
}
return {first, last};
}
// --- Delegate Lifecycle ---
void LazyListView::syncDelegates() {
const auto [first, last] = computeVisibleRange();
@@ -601,8 +554,7 @@ void LazyListView::syncDelegates() {
const auto vp = effectiveViewport();
QList<int> toRemove;
for (auto it = m_delegates.begin(); it != m_delegates.end(); ++it) {
if (visibleIndices.contains(it.key()))
continue;
if (visibleIndices.contains(it.key())) continue;
if (!it->item || vp.isEmpty()) {
toRemove.append(it.key());
continue;
@@ -622,11 +574,9 @@ void LazyListView::syncDelegates() {
std::min(destroyBudget, static_cast<int>(toRemove.size())));
int destroyed = 0;
for (int idx : toRemove) {
if (destroyed >= destroyBudget)
break;
if (destroyed >= destroyBudget) break;
auto entry = m_delegates.take(idx);
if (entry.item)
m_itemToIndex.remove(entry.item);
if (entry.item) m_itemToIndex.remove(entry.item);
removedEntries.append(std::move(entry));
++destroyed;
}
@@ -637,8 +587,7 @@ void LazyListView::syncDelegates() {
QList<int> toCreate;
if (first >= 0) {
for (int i = first; i <= last; ++i) {
if (!m_delegates.contains(i))
toCreate.append(i);
if (!m_delegates.contains(i)) toCreate.append(i);
}
}
@@ -647,8 +596,7 @@ void LazyListView::syncDelegates() {
: static_cast<int>(toCreate.size());
int created = 0;
for (int i : toCreate) {
if (created >= createBudget)
break;
if (created >= createBudget) break;
auto entry = createDelegate(i);
if (entry.item) {
@@ -674,25 +622,21 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) {
DelegateEntry entry;
entry.modelIndex = modelIndex;
if (!m_delegate || !m_model)
return entry;
if (!m_delegate || !m_model) return entry;
const auto roleNames = m_model->roleNames();
// Use the delegate component's creation context for beginCreate
// so bound components (pragma ComponentBehavior: Bound) are accepted.
auto* compContext = m_delegate->creationContext();
if (!compContext)
compContext = qmlContext(this);
if (!compContext)
return entry;
if (!compContext) compContext = qmlContext(this);
if (!compContext) return entry;
auto* obj = m_delegate->beginCreate(compContext);
entry.item = qobject_cast<QQuickItem*>(obj);
if (!entry.item) {
if (obj)
m_delegate->completeCreate();
if (obj) m_delegate->completeCreate();
delete obj;
return entry;
}
@@ -705,16 +649,15 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) {
for (auto it = roleNames.constBegin(); it != roleNames.constEnd(); ++it) {
const auto name = QString::fromUtf8(it.value());
initialProps.insert(name, m_model->data(index, it.key()));
if (name == QStringLiteral("modelData"))
hasModelData = true;
if (name == QStringLiteral("modelData")) hasModelData = true;
}
initialProps.insert(QStringLiteral("index"), modelIndex);
if (!hasModelData) {
const auto role = roleNames.isEmpty() ? Qt::DisplayRole
: roleNames.constBegin().key();
initialProps.insert(QStringLiteral("modelData"),
m_model->data(index, role));
initialProps.insert(
QStringLiteral("modelData"), m_model->data(index, role));
}
m_delegate->setInitialProperties(entry.item, initialProps);
@@ -728,8 +671,7 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) {
m_layout[modelIndex].isNew) {
auto* addingAttached = qobject_cast<LazyListViewAttached*>(
qmlAttachedPropertiesObject<LazyListView>(entry.item, true));
if (addingAttached)
addingAttached->setAdding(true);
if (addingAttached) addingAttached->setAdding(true);
}
m_delegate->completeCreate();
@@ -740,15 +682,12 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) {
// Height-change handler — uses m_itemToIndex for O(1) lookup.
// Ignored while the delegate is not yet ready.
auto onHeightChanged = [this, item = entry.item] {
if (!isDelegateReady(item))
return;
if (!isDelegateReady(item)) return;
auto indexIt = m_itemToIndex.find(item);
if (indexIt == m_itemToIndex.end())
return;
if (indexIt == m_itemToIndex.end()) return;
const int idx = indexIt.value();
auto delegateIt = m_delegates.find(idx);
if (delegateIt == m_delegates.end() || delegateIt->item != item)
return;
if (delegateIt == m_delegates.end() || delegateIt->item != item) return;
const qreal h = delegateHeight(item);
if (idx < static_cast<int>(m_layout.size()) &&
!qFuzzyCompare(m_layout[idx].height + 1.0, h + 1.0)) {
@@ -756,8 +695,7 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) {
const bool wasKnown = m_layout[idx].heightKnown;
m_layout[idx].height = h;
m_layout[idx].heightKnown = true;
if (wasKnown)
untrackHeight(oldH);
if (wasKnown) untrackHeight(oldH);
trackHeight(h);
// If this tracked item is above the viewport, emit a
@@ -785,58 +723,56 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) {
};
// Watch implicitHeight as fallback
connect(entry.item,
&QQuickItem::implicitHeightChanged,
this,
onHeightChanged);
connect(
entry.item, &QQuickItem::implicitHeightChanged, this, onHeightChanged);
// Watch attached properties if the delegate uses them
auto* attached = qobject_cast<LazyListViewAttached*>(
qmlAttachedPropertiesObject<LazyListView>(entry.item, false));
if (attached) {
connect(attached,
&LazyListViewAttached::preferredHeightChanged,
this,
onHeightChanged);
connect(attached,
&LazyListViewAttached::visibleHeightChanged,
this,
[this] { polish(); });
connect(attached,
&LazyListViewAttached::readyChanged,
this,
[this, item = entry.item] {
auto indexIt = m_itemToIndex.find(item);
if (indexIt == m_itemToIndex.end())
return;
const int idx = indexIt.value();
if (idx >= static_cast<int>(m_layout.size()))
return;
auto* att = qobject_cast<LazyListViewAttached*>(
qmlAttachedPropertiesObject<LazyListView>(item, false));
if (!att || !att->ready())
return;
connect(
attached,
&LazyListViewAttached::preferredHeightChanged,
this,
onHeightChanged);
connect(
attached,
&LazyListViewAttached::visibleHeightChanged,
this,
[this] { polish(); });
connect(
attached,
&LazyListViewAttached::readyChanged,
this,
[this, item = entry.item] {
auto indexIt = m_itemToIndex.find(item);
if (indexIt == m_itemToIndex.end()) return;
const int idx = indexIt.value();
if (idx >= static_cast<int>(m_layout.size())) return;
auto* att = qobject_cast<LazyListViewAttached*>(
qmlAttachedPropertiesObject<LazyListView>(item, false));
if (!att || !att->ready()) return;
const qreal h = delegateHeight(item);
const qreal oldLayoutH = m_layout[idx].heightKnown
? m_layout[idx].height
: effectiveEstimatedHeight();
if (m_layout[idx].heightKnown)
untrackHeight(m_layout[idx].height);
m_layout[idx].height = h;
m_layout[idx].heightKnown = true;
trackHeight(h);
const qreal h = delegateHeight(item);
const qreal oldLayoutH = m_layout[idx].heightKnown
? m_layout[idx].height
: effectiveEstimatedHeight();
if (m_layout[idx].heightKnown)
untrackHeight(m_layout[idx].height);
m_layout[idx].height = h;
m_layout[idx].heightKnown = true;
trackHeight(h);
if (att->trackViewport() &&
!qFuzzyCompare(h + 1.0, oldLayoutH + 1.0)) {
const qreal vpTop = m_useCustomViewport ? m_viewport.y()
: m_contentY;
if (m_layout[idx].targetY < vpTop)
emit viewportAdjustNeeded(h - oldLayoutH);
}
if (att->trackViewport() &&
!qFuzzyCompare(h + 1.0, oldLayoutH + 1.0)) {
const qreal vpTop = m_useCustomViewport ? m_viewport.y()
: m_contentY;
if (m_layout[idx].targetY < vpTop)
emit viewportAdjustNeeded(h - oldLayoutH);
}
polish();
});
polish();
});
}
return entry;
@@ -852,8 +788,7 @@ void LazyListView::destroyDelegate(DelegateEntry& entry) {
}
void LazyListView::updateDelegateData(DelegateEntry& entry) {
if (!m_model || !entry.item)
return;
if (!m_model || !entry.item) return;
const auto roleNames = m_model->roleNames();
const auto index = m_model->index(entry.modelIndex, 0);
@@ -861,10 +796,9 @@ void LazyListView::updateDelegateData(DelegateEntry& entry) {
for (auto it = roleNames.constBegin(); it != roleNames.constEnd(); ++it) {
const auto name = QString::fromUtf8(it.value());
entry.item->setProperty(name.toUtf8().constData(),
m_model->data(index, it.key()));
if (name == QStringLiteral("modelData"))
hasModelData = true;
entry.item->setProperty(
name.toUtf8().constData(), m_model->data(index, it.key()));
if (name == QStringLiteral("modelData")) hasModelData = true;
}
entry.item->setProperty("index", entry.modelIndex);
@@ -876,53 +810,58 @@ void LazyListView::updateDelegateData(DelegateEntry& entry) {
}
}
// --- Model Connection ---
void LazyListView::connectModel() {
if (!m_model)
return;
if (!m_model) return;
m_modelConnections = {
connect(m_model,
&QAbstractItemModel::rowsInserted,
this,
&LazyListView::onRowsInserted),
connect(m_model,
&QAbstractItemModel::rowsAboutToBeRemoved,
this,
&LazyListView::onRowsAboutToBeRemoved),
connect(m_model,
&QAbstractItemModel::rowsRemoved,
this,
&LazyListView::onRowsRemoved),
connect(m_model,
&QAbstractItemModel::rowsMoved,
this,
&LazyListView::onRowsMoved),
connect(m_model,
&QAbstractItemModel::dataChanged,
this,
&LazyListView::onDataChanged),
connect(m_model,
&QAbstractItemModel::modelReset,
this,
&LazyListView::onModelReset),
connect(m_model,
&QAbstractItemModel::layoutChanged,
this,
[this] {
for (auto& entry : m_delegates)
updateDelegateData(entry);
polish();
}),
connect(m_model,
&QObject::destroyed,
this,
[this] {
m_model = nullptr;
resetContent();
emit modelChanged();
}),
connect(
m_model,
&QAbstractItemModel::rowsInserted,
this,
&LazyListView::onRowsInserted),
connect(
m_model,
&QAbstractItemModel::rowsAboutToBeRemoved,
this,
&LazyListView::onRowsAboutToBeRemoved),
connect(
m_model,
&QAbstractItemModel::rowsRemoved,
this,
&LazyListView::onRowsRemoved),
connect(
m_model,
&QAbstractItemModel::rowsMoved,
this,
&LazyListView::onRowsMoved),
connect(
m_model,
&QAbstractItemModel::dataChanged,
this,
&LazyListView::onDataChanged),
connect(
m_model,
&QAbstractItemModel::modelReset,
this,
&LazyListView::onModelReset),
connect(
m_model,
&QAbstractItemModel::layoutChanged,
this,
[this] {
for (auto& entry : m_delegates)
updateDelegateData(entry);
polish();
}),
connect(
m_model,
&QObject::destroyed,
this,
[this] {
m_model = nullptr;
resetContent();
emit modelChanged();
}),
};
}
@@ -962,11 +901,9 @@ void LazyListView::resetContent() {
polish();
}
void LazyListView::onRowsInserted(const QModelIndex& parent,
int first,
int last) {
if (parent.isValid())
return;
void LazyListView::onRowsInserted(
const QModelIndex& parent, int first, int last) {
if (parent.isValid()) return;
const int insertCount = last - first + 1;
// Insert new layout records
@@ -990,19 +927,15 @@ void LazyListView::onRowsInserted(const QModelIndex& parent,
polish();
}
void LazyListView::onRowsAboutToBeRemoved(const QModelIndex& parent,
int first,
int last) {
if (parent.isValid())
return;
void LazyListView::onRowsAboutToBeRemoved(
const QModelIndex& parent, int first, int last) {
if (parent.isValid()) return;
for (int i = first; i <= last; ++i) {
if (!m_delegates.contains(i))
continue;
if (!m_delegates.contains(i)) continue;
auto entry = m_delegates.take(i);
if (entry.item)
m_itemToIndex.remove(entry.item);
if (entry.item) m_itemToIndex.remove(entry.item);
entry.pendingRemoval = true;
// Never made visible — skip remove animation
@@ -1014,8 +947,7 @@ void LazyListView::onRowsAboutToBeRemoved(const QModelIndex& parent,
if (m_removeDuration > 0 && entry.item) {
auto* attached = qobject_cast<LazyListViewAttached*>(
qmlAttachedPropertiesObject<LazyListView>(entry.item, false));
if (attached)
attached->setRemoving(true);
if (attached) attached->setRemoving(true);
// Schedule destruction after the remove animation duration
auto* item = entry.item;
@@ -1037,18 +969,15 @@ void LazyListView::onRowsAboutToBeRemoved(const QModelIndex& parent,
}
}
void LazyListView::onRowsRemoved(const QModelIndex& parent,
int first,
int last) {
if (parent.isValid())
return;
void LazyListView::onRowsRemoved(
const QModelIndex& parent, int first, int last) {
if (parent.isValid()) return;
const int removeCount = last - first + 1;
// Untrack known heights being removed
for (int i = first; i <= last; ++i) {
if (m_layout[i].heightKnown)
untrackHeight(m_layout[i].height);
if (m_layout[i].heightKnown) untrackHeight(m_layout[i].height);
}
// Remove layout records
@@ -1072,13 +1001,13 @@ void LazyListView::onRowsRemoved(const QModelIndex& parent,
polish();
}
void LazyListView::onRowsMoved(const QModelIndex& parent,
int start,
int end,
const QModelIndex& destination,
int row) {
if (parent.isValid() || destination.isValid())
return;
void LazyListView::onRowsMoved(
const QModelIndex& parent,
int start,
int end,
const QModelIndex& destination,
int row) {
if (parent.isValid() || destination.isValid()) return;
const int count = end - start + 1;
const int dest = row > start ? row - count : row;
@@ -1101,10 +1030,8 @@ void LazyListView::onRowsMoved(const QModelIndex& parent,
if (oldIdx >= start && oldIdx <= end) {
newIdx = dest + (oldIdx - start);
} else {
if (oldIdx > end)
newIdx -= count;
if (newIdx >= dest)
newIdx += count;
if (oldIdx > end) newIdx -= count;
if (newIdx >= dest) newIdx += count;
}
auto entry = std::move(it.value());
@@ -1120,17 +1047,16 @@ void LazyListView::onRowsMoved(const QModelIndex& parent,
polish();
}
void LazyListView::onDataChanged(const QModelIndex& topLeft,
const QModelIndex& bottomRight,
const QList<int>& roles) {
void LazyListView::onDataChanged(
const QModelIndex& topLeft,
const QModelIndex& bottomRight,
const QList<int>& roles) {
Q_UNUSED(roles)
if (topLeft.parent().isValid())
return;
if (topLeft.parent().isValid()) return;
for (int i = topLeft.row(); i <= bottomRight.row(); ++i) {
if (m_delegates.contains(i))
updateDelegateData(m_delegates[i]);
if (m_delegates.contains(i)) updateDelegateData(m_delegates[i]);
}
}