Suppose, that you're writing an office application for accounting. Your customer is a bakery, it employs a set of bakers, who cook pies.
You make 2 spreadsheets:
- First one presents a table (bakers x days), where each cell contains the number of pies, cooked by each baker each day.
- Second one is (bakers x data), it presents personal data of bakers, such as salary, telephone number etc.
Each spreadsheet corresponds to a custom QTableModel
and QTableView
.
Now, I want to present an API to the customer, so that he can programmatically change his data. I want my program to have a console; through it user will be able to modify the storage of bakers' data, called Bakers
, which both models use to draw data from.
To add a new baker to Bakers
, user should call Bakers.add()
; I'd like it to traverse all models and call insertRow()
method of each of them.
But here comes the problem: in insertRow()
implementation you should call beginInsertRow()
, then actually add new baker to Bakers
and then call endInsertRow
. That way I'll end up having a baker inserted twice, cause insertRow()
should be called for each model. Could you suggest a way to circumvent this problem?