QObjectDiff: What fields changed in my form?
What if you want to easily tell which fields have changed in your form after the
user has saved it? What if you need it for some kind of logging, or an audit trail?
QObjectDiff lets you do exactly that.
Imagine that you have a form that allows different members of the team edit project
details; you want to keep a log of all project detail modifications, so that at the
end of the project, you could easily tell how the dates/budgets/other things have
changed over time. So, you present the user with just a simple form - the form below;
when they click on Save, you pass both the old AND the modified instances of the
Project object to the
QObjectDiff, and it spits out a detailed report on
what fields, if any, have changed. It also tells you what the old and new values of
those fields are, so that you can write it out nicely to your audit trail.
Note that
QObjectDiff can be used to compare the state of CodeGen-generated
ORM objects, or to compare two custom objects of any class.
There are two important limitations:
- QObjectDiff cannot compare private fields between the objects. This is a
fundamental limitation of reflection in PHP5.
- QObjectDiff compares the values of the actual objects only - not child
objects. If you want to compare child objects, you'll have to call
QObjectDiff::Compare()on them explicitly.
First name: