Duplicate roles across models
-
I have a list model for Interpolator, and a list model for Sequence. My Sequence objects can have an Interpolator assigned to them, and this is done via association of the Interpolator's ID.
In my Sequence list view delegate, I'd like to resolve the assigned Interpolator's ID to its name. I currently do this by exposing a duplicate role "interpolator_name" in the Sequence list model which calls data() on the Interpolator model to retrieve the name. I also connect to dataChanged() so we're aware of any name changes.
This all seems a bit fragile to me. Is there a better way?
-
Is a
duplicate role
merely an additional role in the Sequence model?
What does fragile mean?The described solution seems reasonable. An alternative is to copy the data, either relying on the Interpolator::dataChanged() signal, or a setter function that updates both models. Is efficient storage more or less important than efficient retrieval?
-
Is a duplicate role merely an additional role in the Sequence model?
Yes, but I suppose a role that points to the same data as the one in Interpolator model.
What does fragile mean?
By having the Interpolator name exposed in 2 models, we no longer have a single source of truth and have to maintain synchronisation between the 2 models. In this use case it's not a major problem so maybe I'm trying to find a solution to a non-existent problem...
-
Is a duplicate role merely an additional role in the Sequence model?
Yes, but I suppose a role that points to the same data as the one in Interpolator model.
What does fragile mean?
By having the Interpolator name exposed in 2 models, we no longer have a single source of truth and have to maintain synchronisation between the 2 models. In this use case it's not a major problem so maybe I'm trying to find a solution to a non-existent problem...
@ECEC hi,
Did you already took a look at the QSqlRelationalTableModel ?
It sounds like it should cover your use case. -
@SGaist , Would it not be overkill to introduce a relational database for such a simple task?