The example is very simple and only illustrates the way of handling things. To implement features you want, you'd probably have to reimplement setData() and connect proper signals and slots so that changes propagate between models.
The example is very simple and only illustrates the way of handling things. To implement features you want, you'd probably have to reimplement setData() and connect proper signals and slots so that changes propagate between models.
By reimplementing setData() in the proxy model, I managed to get changes in the proxy model to be reflected by in the original model.
However, I am still having a slight problem keeping the proxy in sync with the original model. For example, if I changed row 1, column 1, from "1" (the original value) to "A", the proxy model's view is not updated until I do something like move the scroll bar or something else that generates events or signals.
Which signal should I connect to which slot (and which object)?
The transpose proxy code (http://wiki.qtcentre.org/index.php?t...se_Proxy_Model) works fine but only with quadratic models where there are the same number of rows and columns. If there are e.g. more columns than rows the data() function is not called for all cells that it needs to be called for. Is there anyone who knows how to implement this transpose with a on-quadratic model?
The model is broken, it was just an example. But it should work for non-square models too, I don't see what would prevent it from that. The only two things that are not in the model is reacting to changes in the source model and handling hierarchical source models. Apart from that the example is fully functional.
It does not work for non-square models since the data-functions is not called enough number of times if there is e.g. more columns than rows
You are wrong, I just checked it. The model works fine for non-square models.
Qt Code:
int main(int argc, char **argv){ QTableView v1; QTableView v2; for(int i=0;i<5;i++) for(int j=0;j<3;j++){ model.setData(model.index(j,i), qrand()%20); } v1.setModel(&model); TransposeProxyModel proxy; proxy.setSourceModel(&model); v2.setModel(&proxy); v1.show(); v2.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
Bookmarks