mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-02-03 10:57:33 +01:00
Remove hack in MergedProxyModel and use QAbstractProxyModel::modelAboutToBeReset()
This commit is contained in:
parent
3ae9092226
commit
057ec49a3e
@ -100,6 +100,7 @@ void MergedProxyModel::DeleteAllMappings() {
|
||||
|
||||
void MergedProxyModel::AddSubModel(const QModelIndex &source_parent, QAbstractItemModel *submodel) {
|
||||
|
||||
connect(submodel, SIGNAL(modelAboutToBeReset()), this, SLOT(SubModelAboutToBeReset()));
|
||||
connect(submodel, SIGNAL(modelReset()), this, SLOT(SubModelReset()));
|
||||
connect(submodel, SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(RowsAboutToBeInserted(QModelIndex, int, int)));
|
||||
connect(submodel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(RowsAboutToBeRemoved(QModelIndex, int, int)));
|
||||
@ -191,20 +192,15 @@ void MergedProxyModel::SourceModelReset() {
|
||||
|
||||
}
|
||||
|
||||
void MergedProxyModel::SubModelReset() {
|
||||
void MergedProxyModel::SubModelAboutToBeReset() {
|
||||
|
||||
QAbstractItemModel *submodel = qobject_cast<QAbstractItemModel*>(sender());
|
||||
|
||||
// TODO: When we require Qt 4.6, use beginResetModel() and endResetModel() in CollectionModel and catch those here
|
||||
// that will let us do away with this std::numeric_limits<int>::max() hack.
|
||||
|
||||
// Remove all the children of the item that got deleted
|
||||
QModelIndex source_parent = merge_points_.value(submodel);
|
||||
QModelIndex proxy_parent = mapFromSource(source_parent);
|
||||
|
||||
// We can't know how many children it had, since it's already disappeared...
|
||||
resetting_model_ = submodel;
|
||||
beginRemoveRows(proxy_parent, 0, std::numeric_limits<int>::max() - 1);
|
||||
beginRemoveRows(proxy_parent, 0, submodel->rowCount());
|
||||
endRemoveRows();
|
||||
resetting_model_ = nullptr;
|
||||
|
||||
@ -221,6 +217,15 @@ void MergedProxyModel::SubModelReset() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MergedProxyModel::SubModelReset() {
|
||||
|
||||
QAbstractItemModel *submodel = static_cast<QAbstractItemModel*>(sender());
|
||||
|
||||
QModelIndex source_parent = merge_points_.value(submodel);
|
||||
QModelIndex proxy_parent = mapFromSource(source_parent);
|
||||
|
||||
// "Insert" items from the newly reset submodel
|
||||
int count = submodel->rowCount();
|
||||
if (count) {
|
||||
@ -553,4 +558,3 @@ QModelIndexList MergedProxyModel::mapToSource(const QModelIndexList &proxy_index
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
@ -87,6 +87,7 @@ class MergedProxyModel : public QAbstractProxyModel {
|
||||
|
||||
private slots:
|
||||
void SourceModelReset();
|
||||
void SubModelAboutToBeReset();
|
||||
void SubModelReset();
|
||||
|
||||
void RowsAboutToBeInserted(const QModelIndex &source_parent, int start, int end);
|
||||
|
Loading…
x
Reference in New Issue
Block a user