Remove hack in MergedProxyModel and use QAbstractProxyModel::modelAboutToBeReset()
This commit is contained in:
@@ -100,6 +100,7 @@ void MergedProxyModel::DeleteAllMappings() {
|
|||||||
|
|
||||||
void MergedProxyModel::AddSubModel(const QModelIndex &source_parent, QAbstractItemModel *submodel) {
|
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(modelReset()), this, SLOT(SubModelReset()));
|
||||||
connect(submodel, SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(RowsAboutToBeInserted(QModelIndex, int, int)));
|
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)));
|
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());
|
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 source_parent = merge_points_.value(submodel);
|
||||||
QModelIndex proxy_parent = mapFromSource(source_parent);
|
QModelIndex proxy_parent = mapFromSource(source_parent);
|
||||||
|
|
||||||
// We can't know how many children it had, since it's already disappeared...
|
|
||||||
resetting_model_ = submodel;
|
resetting_model_ = submodel;
|
||||||
beginRemoveRows(proxy_parent, 0, std::numeric_limits<int>::max() - 1);
|
beginRemoveRows(proxy_parent, 0, submodel->rowCount());
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
resetting_model_ = nullptr;
|
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
|
// "Insert" items from the newly reset submodel
|
||||||
int count = submodel->rowCount();
|
int count = submodel->rowCount();
|
||||||
if (count) {
|
if (count) {
|
||||||
@@ -553,4 +558,3 @@ QModelIndexList MergedProxyModel::mapToSource(const QModelIndexList &proxy_index
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ class MergedProxyModel : public QAbstractProxyModel {
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void SourceModelReset();
|
void SourceModelReset();
|
||||||
|
void SubModelAboutToBeReset();
|
||||||
void SubModelReset();
|
void SubModelReset();
|
||||||
|
|
||||||
void RowsAboutToBeInserted(const QModelIndex &source_parent, int start, int end);
|
void RowsAboutToBeInserted(const QModelIndex &source_parent, int start, int end);
|
||||||
|
|||||||
Reference in New Issue
Block a user