I have a QTableView and a subclassed QStandardItemModel.

I need a Button wich deletes the selected rows. This is my current implementation:
Qt Code:
  1. //get selections
  2. QItemSelection selection = tableView->selectionModel()->selection();
  3.  
  4. //find out selected rows
  5. QList<int> removeRows;
  6. foreach(QModelIndex index, selection.indexes()) {
  7. if(!removeRows.contains(index.row())) {
  8. removeRows.append(index.row());
  9. }
  10. }
  11.  
  12. //loop through all selected rows
  13. for(int i=0;i<removeRows.count();++i)
  14. {
  15. //decrement all rows after the current - as the row-number will change if we remove the current
  16. for(int j=i;j<removeRows.count();++j) {
  17. if(removeRows.at(j) > removeRows.at(i)) {
  18. removeRows[j]--;
  19. }
  20. }
  21. //remove the selected row
  22. model->removeRows(removeRows.at(i), 1);
  23. }
To copy to clipboard, switch view to plain text mode 

which works - but can't this be easier?

thanks for any suggestions.

niko