[PyQt] Master-detail relationship with plain QTableView tables (no SQL database)
Mark Summerfield
list at qtrac.plus.com
Thu May 20 08:26:46 BST 2010
On 2010-05-20, Vadym Honcharuk wrote:
> 2010/5/9 Mark Summerfield <list at qtrac.plus.com>:
[snip]
> Thank you, Mark!
>
> One more question in this issue is how to save data from these three
> tables with different models in one file by QDataStream module. The
> point of problem in that save method calling from their models itself
> and if I have three models - every will try open same file and save
> data in series? But seems this is not too correct desicion...
>
> With best rgards,
> -vadym
Hi Vadym,
There are many possible approaches to this.
One approach is to make just one of the models (or a new "ModelManager"
class) responsible for saving. This class would be the only one that had
a save method and would work somewhat like this:
open the file
for each row in the "main" model:
write the row's data
for each row in the "sub" model that corresponds to main data's row:
write the sub model row data
# and if there's a sub-sub model iterate over the sub-sub
# model's rows that correspond to the sub model's rows
# and if there's more than one sub model, iterate over each
# one's corresponding rows & write their data
Other approaches are equally valid. For example, you could save one file
per model which is the simplest and probably the most maintainable
approach---and the one that I personally prefer.
Nor is saving each model's data in series necessarily bad---but it does
require you to synchronize and is more risky than the other two
approaches I've mentioned.
--
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
C++, Python, Qt, PyQt - training and consultancy
"Advanced Qt Programming" - ISBN 0321635906
More information about the PyQt
mailing list