indifference
29th August 2007, 00:24
Hello all,
I'm making my own model to work with a QTableView, by subclassing QAbstractTableModel.
The table will have to work with many rows.
Everything works well, except when I try to remove the selected rows in the table.
This is the removeRows of the model:
bool SubViewerModel::removeRows( int position, int rows/*,
const QModelIndex& parent*/ )
{
beginRemoveRows( QModelIndex(), position,
position + rows-1 );
for ( int row = 0; row < rows; ++row )
subtitles->removeAt( position );
endRemoveRows();
return true;
}
and this is how the function is called:
void MainWindow::deleteSelected()
{
QItemSelectionModel *selModel =
subViewer->selectionModel();
QModelIndexList indexes =
selModel->selectedRows();
foreach ( QModelIndex index, indexes )
subViewerModel->removeRows( index.row(), 1 );
setWindowModified( true );
}
If I select just one row, this row is deleted correctly, but I select various rows it will delete other rows that aren't selected.
Other problem is that deleting a great number of rows takes a long time...
Any sugestions to solve this?
Thanks!
I'm making my own model to work with a QTableView, by subclassing QAbstractTableModel.
The table will have to work with many rows.
Everything works well, except when I try to remove the selected rows in the table.
This is the removeRows of the model:
bool SubViewerModel::removeRows( int position, int rows/*,
const QModelIndex& parent*/ )
{
beginRemoveRows( QModelIndex(), position,
position + rows-1 );
for ( int row = 0; row < rows; ++row )
subtitles->removeAt( position );
endRemoveRows();
return true;
}
and this is how the function is called:
void MainWindow::deleteSelected()
{
QItemSelectionModel *selModel =
subViewer->selectionModel();
QModelIndexList indexes =
selModel->selectedRows();
foreach ( QModelIndex index, indexes )
subViewerModel->removeRows( index.row(), 1 );
setWindowModified( true );
}
If I select just one row, this row is deleted correctly, but I select various rows it will delete other rows that aren't selected.
Other problem is that deleting a great number of rows takes a long time...
Any sugestions to solve this?
Thanks!