Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTransposeproxymodel rewrite?



  • Hi everyone,

    I have two views (where always only one is visible).

    1. First view uses a derived version of QAbstractTableModel (with many individual stuff for inserts and so on)
    2. 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 Qt qobject_cast<>) for somewhere to determine what derived type a QAbstractTableModel 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 have m_modelTransposed points to QTransposeProxyModel points to SomeModelOfYours, and you want m_modelTransposed to be able to get at SomeModelOfYours, then you can go via

    QTransposeProxyModel *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


Log in to reply