fix: delegate size not being tracked after rearrange
This commit is contained in:
parent
2acd8f13f8
commit
0252be370e
1 changed files with 19 additions and 16 deletions
|
|
@ -574,24 +574,27 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) {
|
||||||
entry.item->setWidth(width());
|
entry.item->setWidth(width());
|
||||||
m_delegate->completeCreate();
|
m_delegate->completeCreate();
|
||||||
|
|
||||||
// Shared height-change handler
|
// Shared height-change handler — captures item pointer instead of index
|
||||||
auto onHeightChanged = [this, modelIndex] {
|
// so it remains valid after model inserts/removes/moves shift indices.
|
||||||
if (!m_delegates.contains(modelIndex))
|
auto onHeightChanged = [this, item = entry.item] {
|
||||||
return;
|
// Find the delegate entry by item pointer
|
||||||
auto& e = m_delegates[modelIndex];
|
for (auto it = m_delegates.begin(); it != m_delegates.end(); ++it) {
|
||||||
if (!e.item)
|
if (it->item != item)
|
||||||
return;
|
continue;
|
||||||
const qreal h = delegateHeight(e.item);
|
const int idx = it.key();
|
||||||
if (modelIndex < static_cast<int>(m_layout.size()) && !qFuzzyCompare(m_layout[modelIndex].height, h)) {
|
const qreal h = delegateHeight(item);
|
||||||
const qreal oldH = m_layout[modelIndex].height;
|
if (idx < static_cast<int>(m_layout.size()) && !qFuzzyCompare(m_layout[idx].height, h)) {
|
||||||
const bool wasKnown = m_layout[modelIndex].heightKnown;
|
const qreal oldH = m_layout[idx].height;
|
||||||
m_layout[modelIndex].height = h;
|
const bool wasKnown = m_layout[idx].heightKnown;
|
||||||
m_layout[modelIndex].heightKnown = true;
|
m_layout[idx].height = h;
|
||||||
|
m_layout[idx].heightKnown = true;
|
||||||
if (wasKnown)
|
if (wasKnown)
|
||||||
untrackHeight(oldH);
|
untrackHeight(oldH);
|
||||||
trackHeight(h);
|
trackHeight(h);
|
||||||
polish();
|
polish();
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Watch implicitHeight as fallback
|
// Watch implicitHeight as fallback
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue