Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions liteidex/src/utils/folderview/multiindexmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ QModelIndexPairList MultiIndexModelPrivate::store_persistent_indexes(const QMode
QModelIndexPairList source_indexes;
foreach (QModelIndex proxy_index, persistentList) {
SourceModelIndex index = q->mapToSourceEx(proxy_index);
source_indexes.append(qMakePair(proxy_index, QPersistentModelIndex(index.index)));
// A source model may be rebuilding its index tree while emitting a
// layout change. Keep invalid mappings invalid instead of asking it
// to create an index from stale mapping data.
if (index.model == 0 || !index.index.isValid()) {
source_indexes.append(qMakePair(proxy_index, QPersistentModelIndex()));
} else {
source_indexes.append(qMakePair(proxy_index, QPersistentModelIndex(index.index)));
}
}
return source_indexes;
}
Expand Down Expand Up @@ -499,11 +506,18 @@ SourceModelIndex MultiIndexModel::mapToSourceEx(const QModelIndex &proxyIndex) c

Mapping *m = (Mapping*)proxyIndex.internalPointer();
if (m == 0) {
if (proxyIndex.row() < 0 || proxyIndex.row() >= d->indexList.size()) {
return SourceModelIndex();
}
SourceModelIndex si = d->indexList[proxyIndex.row()];
if (si.model == 0 || !si.index.isValid()) {
return SourceModelIndex();
}
si.index = si.index.sibling(si.index.row(),proxyIndex.column());
return si;
}
if (m->source_rows.size() <= proxyIndex.row()) {
if (m->sourceModel == 0 || proxyIndex.row() < 0 ||
m->source_rows.size() <= proxyIndex.row()) {
return SourceModelIndex();
}

Expand Down Expand Up @@ -937,14 +951,13 @@ void MultiIndexModelPrivate::_q_sourceLayoutAboutToBeChanged()
// q->layoutAboutToBeChanged();
Q_Q(MultiIndexModel);
saved_persistent_indexes.clear();
emit q->layoutAboutToBeChanged();
QModelIndexList persistentList = q->persistentIndexList();
if (persistentList.isEmpty())
return;
if (!persistentList.isEmpty())
saved_persistent_indexes = store_persistent_indexes(persistentList);

// QAbstractItemModel *model = (QAbstractItemModel*)sender();
// qDebug() << "begin changed" << model;
saved_persistent_indexes = store_persistent_indexes(persistentList);
// Save indexes before notifying observers. Views may synchronously query
// the proxy while the source model is in its layout-about-to-change phase.
emit q->layoutAboutToBeChanged();
}

void MultiIndexModelPrivate::_q_sourceLayoutChanged()
Expand Down
3 changes: 1 addition & 2 deletions liteidex/src/utils/folderview/multiindexmodel_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct Mapping
int rowCount;
QVector<int> source_rows; //source rows
QVector<int> proxy_rows; //proxy rows
QModelIndex sourceParent; //source parent
QPersistentModelIndex sourceParent; //source parent
QAbstractItemModel *sourceModel;
};

Expand Down Expand Up @@ -118,4 +118,3 @@ public slots:
};

#endif // MULTIINDEXMODEL_P_H

Loading