Unsolved QtreeView
-
I have a basic appilcation of QtreeView which I am using my own class custom model to populate the data
Now we in what sequence the following methods are called
//! [0]
class TreeModel1 : public QAbstractItemModel
{
Q_OBJECTpublic:
TreeModel1(const QString &data, QObject *parent = 0);
~TreeModel1();QVariant data(const QModelIndex &index, int role) const; Qt::ItemFlags flags(const QModelIndex &index) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex parent(const QModelIndex &index) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const;
private:
void setupModelData(const QStringList &lines, TreeItem1 *parent);TreeItem1 *rootItem;
};
-
- For each node : the sequence is
index
rowCount
columncountfollowed by the
-
header which is called every-time the treeview needs the repainting (mouse moves)
-
the parent is called if the node is a child
-
flags
-
data
Why would you care about this ?
-
Don't depend on any sort of order of these method calls. It's up to the view/delegate/anyone to call them in any order they want/need. Any logic that depends on any kind of order will fail at some point when you switch view, delegate, Qt version or someone calls one of these directly on your model.
A good behaved model should return correct data from these methods no matter the order they are called in.