Hello,
I have a set of custom widgets that each contain a QTableView and an underlying QStandardItemModel. Some of these widgets are dependant on the models contained within other widgets. Currently, I am simply passing around QStandardItemModel pointers to achieve this. As such, the dependant widgets need to know what each model it's using "looks" like (headers, # of rows/columns, etc.).
Note: that the dependant widgets also need to respond to changes in the data they are depending on. Currently this is achieved by connecting a signal from a widget to a private slot of a dependant widget.
A possible change would be to subclass QStandardItemModel and provide a data specific interface to the model. For example, if I had a table that stored car information, clients would use:
Car *car = model->getCar(row)
int numSeats = car->numSeats;
Car *car = model->getCar(row)
int numSeats = car->numSeats;
To copy to clipboard, switch view to plain text mode
instead of:
int numSeats = item->data(Qt::DisplayRole).toInt();
QStandardItem *item = model->item(row, col);
int numSeats = item->data(Qt::DisplayRole).toInt();
To copy to clipboard, switch view to plain text mode
I have several tables, so creating a wrapper interface for each one seems a little overkill, but at the same time the way I am currently doing things seems a little error prone.
What is the best practice in this case?
Any suggestions and ideas appreciated!
Thanks
Bookmarks