PDA

View Full Version : How to remove row from Model without removing from source



poporacer
30th April 2011, 04:05
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?

MasterBLB
30th April 2011, 16:15
removeRow() and editStrategy:: onManualSubmit shoud do the work done Brother ;]

poporacer
2nd May 2011, 05:29
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?

franz
2nd May 2011, 07:21
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.

poporacer
2nd May 2011, 15:46
Make sure dataChanged is emitted from your model when data has changed I do not know how to check that.

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?

MasterBLB
2nd May 2011, 16:43
connect that dataChanged to a slot inside which there is a qDebug or message box.Later on put there this invalidating of the filter.