Hello Jerome!
Yes, you could simply remove all self.buildings occurences in your code
to remove redundancy. If you need a list of all buildings in the model,
you could implement a get_buildings_list() method that builds and
returns a list from the models items.
For editing entries QDelegates are great, you can define any widget as
editor. In the delegates, you can also handle invalid input, sometimes
QValidator is another option. Have a look at both directions and their
subclasses, they are very powerful.
Have a nice evening!
Aaron
Am 03.03.2014 18:13, schrieb Jérôme:
Hi.
Thank you all for your answers/precisions.
I adapted the code proposed by Aaron to my needs. I'm attaching the new
version.
I implemented Add, Edit, Remove, and even Copy (i.e. "Edit as new").
A few questions remain (and probably much more to come...).
Isn't there a data duplication in the TableModel class, with both the
buildings[] list, and the model's Items ? In practice, this is what I
was going to do since there will be attributes that are not values but
references to other custom classes instances. But although I was
expecting to do this, I suspected it might not be the best way.
I ended up removing the Controller and merging it with the Main window.
It looked simpler to me, but it might not be the best choice.
I also had to remove the TableView class, because the TableView is
already instanciated in the .py file generated by Qt Designer and I
didn't know how to do otherwise.
In practice, I now have a main window that acts both as view and
controller, and a building model. (Qt's doc talks about Model/View
programming.)
The whole {TableView + AddEditCopyRemove buttons} is meant to be used
extensively in this application, so it may become a custom widget.
There is currently no value check. At some point, the model would need
to be able to perform a check and return an error if, for instance, we
don't want two buildings with the same name. I suppose I'll find a way
using Exceptions.
Thanks again for your precious help. Things are clearer now and I'm not
stuck anymore.
Have a nice evening.
_______________________________________________
PySide mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside
_______________________________________________
PySide mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside