How to remove row from Model without removing from source
I have a tableView created from a QSqlRelationalTableModel and a proxy model. I use the table to let the user display data to their needs. I use the proxyModel to highlight the high and low values in a column. The user needs to be able to sort the table and remove certain rows. BUT I don't want the underlying source to be modified. I tried to remove the row from the model, but it removed it from the source as well. I tried to hide the row, but then if the user sorted the column, the hidden data becomes available. What would be the best way to do this? The table is not going to be very big. If there isn't a better method, one idea I had was to create another table in my database and store the "original" data (the filtered data from the SQLRelation and filtered data) when the dialog is created. Then if the user wants to revert back to the original data, the dialog could "DROP" the table, Create the table again and repopulate the table row by row. This way the original data would be intact. Is there a method to remove items from a model/view without removing them from the source?
Re: How to remove row from Model without removing from source
removeRow() and editStrategy:: onManualSubmit shoud do the work done Brother ;]
Re: How to remove row from Model without removing from source
Thanks,
I thought I had tried that, but I guess I didn't
Added after 1 15 minutes:
A quick add on, I don't know if I should create a new thread. I use a proxymodel to highlight cells. After the delete function, I need to have the tableView updated (call data()) I was thinking that I need to emit dataChanged() to repopulate the tableView. But it didn't work. The compiler stated
'virtual void QAbstractItemView::dataChanged(const QModelIndex&, const QModelIndex&)' is protected
I this the correct way or is there a better way?
Re: How to remove row from Model without removing from source
Make sure dataChanged is emitted from your model when data has changed. If that is the case, let your proxy model invalidate its filter when data has changed. Your view will then be automatically updated.
Re: How to remove row from Model without removing from source
Quote:
Make sure dataChanged is emitted from your model when data has changed
I do not know how to check that.
Quote:
If that is the case, let your proxy model invalidate its filter when data has changed. Your view will then be automatically updated.
And how do I do that?
Re: How to remove row from Model without removing from source
connect that dataChanged to a slot inside which there is a qDebug or message box.Later on put there this invalidating of the filter.