i impemented this Editable TreeModel from Qt: Editable TreeModel
All works fine as expected, then i have modified it for my special needs, and there i'm not storing Strings, i am storing X509 certificates and some general data of it like issuer and subject. So my treeview sturcture look like this:
Subject, Issuer, Valid Till, Certificate Data
Note that the Certificate Data is not shown in the tree view, only the three other fields. This works and so my tree view could look like this, if there are certificates which are signed by another certificate:
- Certificate A
- Certificate B (which was signed by A)
- Certificate C (which wassigned by B)
- Certificate D
- Certificate E
So i implemented a double click listener which returns the certificate data (field 4), which works fine.
Now i want to make the tree view sortable. Therefore i want to use QSortFilterProxyModel. Is this the right way? Or is there another / better solution?
So i tried the following and set up my model and the QSortFilterProxyModel this way:
QVector<X509*> certificates getCertificates(storeName);
m_model = new TreeModel(certificates);
m_proxy = new QSortFilterProxyModel;
m_proxy->setSourceModel(m_model);
ui->treeView->setModel(m_proxy);
ui->treeView->expandAll();
And then inside the double click listener im calling this:
QVariant data = m_proxy->data(m_proxy->index(index.row(), 4));
This works not correct, because when i click on Certificate B or Certificate C i got everytime the data of the Certificate which is stored under Certificate A. But i need to get the data which is stored under the correct entry (row). Where is my problem?
According to Simons comment the solution for the problem is to pass the parent index (tree structure), so that my code looks this:
QVariant data = m_proxy->data(m_proxy->index(index.row(), 4, index.parent()));