[Code Design] Config dialog
I've created a custom model that holds some configurations. I would like to create a dialog to edit this model. So I've used a QDataWidgetMapper in the dialog to do so. It works well, but every modifications are directly done in the model, and I'd like now that the modifications are apply on the model only when the user click on "OK" or "Apply", but not on "Cancel" button.
I know the QDataWidgetMapper has a submit policy, but this apply for a column in the model. I'd like all the modifications (on all columns) to be apply at the same time (when user confirm).
What is the best way to do that? I thought I could create a copy of the model, and edit this copy in the dialog. If the user cancel, I just drop the copied model. If the user confirm, I replace the original model by the copy. But I find this solution heavy as I copy the whole model in order to maybe modify 2 or 3 things into it.
So if you'd like to share some tips on the best way to do that, I thank you.
QDataWidgetMapper applies the submit policy to all fields handled by it so unless you create one mapper per widget, your use case is already covered
The QDataWidget handled all the "rows" of a column in my model (which is a table model). But it can't handle all the columns at the same time. It manages one column a the time right?
I want the user to be abble to edit the whole model and confirm afterwards. The QDataWidget allows me to edit only one column at the time.
No, you're wrong. When you call addMapping, you're giving a widget and a section. The section is a model column.
From there you can navigate from one row to another.
Yes ok, but it doesn't change the problem: how to keep all the row modification in memory until the user confirm the changes?
NOTE: You can change the sens QDataWidgetMapper works withQDataWidgetMapper::setOrientation()
Right, forgot your setOrientation (not the most common use case)
I might be wrong, bug IIRC, QDataWidgetMapper uses a model internally so it's could be already done for you.