jkv
18th November 2010, 18:49
Hello, I'm having a slight problem with model/proxy/view -combo.
As I call beginRemoveRows(.., FIRST, LAST) to remove all items from the model I get selectionChanged(..) from the View's SelectionModel (assuming I had some items selected). The receiving slot then results in following functions being called
void FileVersionManager::installSelectionChanged(
const QItemSelection& selected, const QItemSelection& deselected)
{
installSet_.listSelectionChanged(selected, deselected); // keep track of # of selected rows
if (installSet_.selectedRowCount == 1)
{
hoverInstallInfo_ = false;
setActiveInstallFromFile(installSet_.selectedFile( ));
}
else
{
hoverInstallInfo_ = true;
setActiveInstallFromFile(installSet_.hoverFile()); // <-- relevant call
}
updateInstallActions();
}
FileNode* FileSet::hoverFile() const
{
QPoint pnt = view->viewport()->mapFromGlobal(QCursor::pos());
return proxy->mapToFile(view->indexAt(pnt));
}
FileNode* FileSetSortFilterProxyModel::mapToFile(const QModelIndex& index) const
{
return model_.mapToFile(mapToSource(index));
}
FileNode* InstallSetModel::mapToFile(const QModelIndex& index) const
{
if (index.isValid())
return static_cast<FileNode*>(index.internalPointer());
return 0;
}
The problem is that the FileNode* I get is not NULL as I'd hope it to be due to beginRemoveRows() call. This will eventually segfault later due to the "deleted" file being set where it shouldn't.
Is it normal behaviour that the view returns valid QModelIndex even when the underlying model's all rows are being removed ? Or should I just avoid calling indexAt() or any other functions that return indexes from the views until after endRemoveRows() ?
Thanks.
As I call beginRemoveRows(.., FIRST, LAST) to remove all items from the model I get selectionChanged(..) from the View's SelectionModel (assuming I had some items selected). The receiving slot then results in following functions being called
void FileVersionManager::installSelectionChanged(
const QItemSelection& selected, const QItemSelection& deselected)
{
installSet_.listSelectionChanged(selected, deselected); // keep track of # of selected rows
if (installSet_.selectedRowCount == 1)
{
hoverInstallInfo_ = false;
setActiveInstallFromFile(installSet_.selectedFile( ));
}
else
{
hoverInstallInfo_ = true;
setActiveInstallFromFile(installSet_.hoverFile()); // <-- relevant call
}
updateInstallActions();
}
FileNode* FileSet::hoverFile() const
{
QPoint pnt = view->viewport()->mapFromGlobal(QCursor::pos());
return proxy->mapToFile(view->indexAt(pnt));
}
FileNode* FileSetSortFilterProxyModel::mapToFile(const QModelIndex& index) const
{
return model_.mapToFile(mapToSource(index));
}
FileNode* InstallSetModel::mapToFile(const QModelIndex& index) const
{
if (index.isValid())
return static_cast<FileNode*>(index.internalPointer());
return 0;
}
The problem is that the FileNode* I get is not NULL as I'd hope it to be due to beginRemoveRows() call. This will eventually segfault later due to the "deleted" file being set where it shouldn't.
Is it normal behaviour that the view returns valid QModelIndex even when the underlying model's all rows are being removed ? Or should I just avoid calling indexAt() or any other functions that return indexes from the views until after endRemoveRows() ?
Thanks.