QSortFilterProxyModel: inconsistent changes reported by source model
-
I find this:
@int proxy_count = proxy_to_source.size();
if (proxy_count > source_to_proxy.size()) {
// mapping is in an inconsistent state -- redo the whole mapping
qWarning("QSortFilterProxyModel: inconsistent changes reported by source model");
remove_from_mapping(source_parent);
Q_Q(QSortFilterProxyModel);
q->reset();
return;
}@
but i don't know how right set size of proxy model.
unless of course this is the case. -
While using the following decision:
@
void MainWindow::cancelLoadPrice ()
{
tableProxyModel->setSourceModel( NULL ); //reset proxy model
for (int i = 0; i < lsProperty.count(); ++i)
{
if (lsProperty.at(i)->isMarked)
{model.delPricePosition(3, lsProperty.at(i)->contra); lsProperty.at(i)->isLoad = false; } } tableProxyModel->setSourceModel(model.getTableModel()); //again use proxy ui->tableView->resizeColumnsToContents(); ui->tableView->resizeRowsToContents();
@
Removing move very fast. But I think it is not right resolving
} -
In source model:
@
bool CatalogTableModel::removeRows (int row, int count, const QModelIndex &parent)
{
//TODO:
Q_UNUSED (parent);
beginRemoveRows(QModelIndex(), row, row + count - 1);
//int column = row + count;
for (int i = 0; i < count; ++i)
{
delete listItem->at(row);
listItem->removeAt(row);
}
emit layoutChanged();
endRemoveRows();
return true;
}
@
I don't sure correctly it is or not.. -
I don't think that you need to emit the layoutChanged() signal. The {begin|end}RemoveRows() functions do everything that is needed for you. Try removing that emit end see if it works then.
I suspect what is happening is that the proxy and views are receiving signals from you and from {begin|end}RemoveRows() in an unexpected order which causes them to misbehave.
-
Setting a proxy is a one-liner so I doubt it is that. I suspect you have a problem in your model. I suggest that you run your model with the qmodeltest helper which diagnoses common model implementation problems. This "wiki article":http://developer.qt.nokia.com/wiki/Model_Test describes how to use qmodeltest and the source can be downloaded from "gitorious":https://qt.gitorious.org/qt/qt/trees/4.7/tests/auto/modeltest.
-
I get error:
@
void QSortFilterProxyModelPrivate::source_items_removed(
const QModelIndex &source_parent, int start, int end, Qt::Orientation orient)
{
if ((start < 0) || (end < 0))
return;
IndexMap::const_iterator it = source_index_mapping.constFind(source_parent);
if (it == source_index_mapping.constEnd()) {
// Don't care, since we don't have mapping for this index
return;
}Mapping *m = it.value(); QVector<int> &source_to_proxy = (orient == Qt::Vertical) ? m->proxy_rows : m->proxy_columns; QVector<int> &proxy_to_source = (orient == Qt::Vertical) ? m->source_rows : m->source_columns; if (end >= source_to_proxy.size()) end = source_to_proxy.size() - 1; // Shrink the source-to-proxy mapping to reflect the new item count int delta_item_count = end - start + 1; source_to_proxy.remove(start, delta_item_count); //This crash
@
-
As ZapB said
[quote author="ZapB" date="1310123242"]Setting a proxy is a one-liner[/quote]unless you must overwrite a standard function of QSortFilterProxyModel.Normally removing rows will be done in the sourcemodel. As you do a selection in the view you have to map the indexes getting from the view to the source with
@// single selection
QModelIndex SourceIndex = tableProxyModel->mapToSource(viewIndex);// multiple selection
QModelIndexList SourceIndexList;
for (int i=0; i<viewIndexList.length(); i++)
{
SourceIndexList.append(tableProxyModel->mapToSource(viewIndexList[i]));
}
@Also, if you have multiple selection you must sort the indexlist before removing like this:
@void CatalogTableModel::removeSelectedRows(const QModelIndexList &indexlist)
{
QList<int> rows;
foreach(const QModelIndex & index, indexlist)
{
rows.append(index.row());
}qSort(rows); int prev = -1; for(int i=rows.count()-1; i>=0; i-=1 ) { int current = rows[i]; if(current != prev) { QModelIndex _index = createIndex(current, 0); removeLabel(_index); prev = current; } }
}
@Cheers,
ThomasEdit: Uuups, little bit late ...