QTransposeproxymodel rewrite?
-
Hi everyone,
I have two views (where always only one is visible).
- First view uses a derived version of QAbstractTableModel (with many individual stuff for inserts and so on)
- The second view uses the same model, but with QTransposeProxyModel between ist:
m_modelTransposed = new QTransposeProxyModel(this); m_modelTransposed->setSourceModel(m_model);
In this situation m_modelTransposed doesn´t know the individual stuff I wrote for the model of the "first view", because setSourceModel gets a pointer of QAbstractItemModel, (called Upcast, right?)
Maybe its now a little bit late, but what would be the best approach, that I can use the individual stuff from the model of 1. in the view of 2. but with the functionalitiy of QTransposeProxyModel as well?
Do I have to rewrite QTransposeProxyModel completly?
Some ideas or hints would be enough :-)
Thank you!
-
@firen said in QTransposeproxymodel rewrite?:
In this situation m_modelTransposed doesn´t know the individual stuff I wrote for the model of the "first view", because setSourceModel gets a pointer of QAbstractItemModel, (called Upcast, right?)
If I understand your question correctly. This is where you can use C++
dynamic_cast<>
(or Qtqobject_cast<>
) for somewhere to determine what derived type aQAbstractTableModel
actually is.MyDerivedModel *myDerivedModel= dynamic_cast<MyDerivedModel *>(m_modelTransposed->sourceModel()); if (myDerivedModel) { // it's a `MyDerivedModel` myDerivedModel->someMethodOfMyDerivedModel(); // :) }
P.S.
If I have misunderstood and you havem_modelTransposed
points toQTransposeProxyModel
points toSomeModelOfYours
, and you wantm_modelTransposed
to be able to get atSomeModelOfYours
, then you can go viaQTransposeProxyModel *proxyModel = dynamic_cast<QTransposeProxyModel *>(m_modelTransposed->sourceModel()); if (proxyModel) { MyModel *myModel = dynamic_cast<MyModel *>(proxyModel->sourceModel()); if (myModel) ... }
I get confused as to which situation you are asking about :) But one of the above should help?
-
@firen said in QTransposeproxymodel rewrite?:
I can use the individual stuff from the model of 1. in the view of 2. but with the functionalitiy of QTransposeProxyModel as well?
What is "stuff from the model of 1"? data should be managed automatically
-
Thanks guys so far!
Maybe I am in less trouble than I thought (see @VRonin s comment) I am not 100% sure to be honest. I am going to implement a new Dialog where I will realy need the transposed view.
Maybe then it is easier to understand for me what the problem is or if there is no real problem... :-)I leave this ticket open if thats ok