neuronet
1st January 2015, 02:16
I am working on understanding trees, working through the simpletreemodel example that comes with Qt. I am working in PySide, not Qt, and while I don't know much c++ I often find it helpful to look at the Qt source code to help me understand what is happening.
I understand indexes a bit (because of a thread here (http://www.qtcentre.org/threads/61213-Source-code-for-createIndex%28%29)), and now am trying to understand QTreeView, in particular how it paints the initial tree, determines what to draw, when/where it calls model.rowCount() and other methods from my QAbstractItemModel subclass.
I've been looking over qtreeview.cpp (https://qt.gitorious.org/qt/qt/source/5fe6a7457033b183d8cc3861fe8593338ad3385b:src/gui/itemviews/qtreeview.cpp) and am confused. My first confusion is about what the 'd' class is. I think it is an instance of QTreeView, because starting on line 196 we have:
QTreeView::QTreeView(QTreeViewPrivate &dd, QWidget *parent)
: QAbstractItemView(dd, parent)
{
Q_D(QTreeView);
d->initialize();
}
But there are lots of methods/attributes of d that I cannot find defined anywhere. For instance viewItems seems pretty key, and has many methods (e.g., resize(), clear()) that I'd like to study. Unfortunately I am not sure where viewItems is defined initially, what it means. I have never seen it documented, or used it explicitly in my custom views. In addition to qtreeview.cpp, I searched for it in qtreeview.h (https://qt.gitorious.org/qt/qt/source/57756e72adf2081137b97f0e689dd16c770d10b1:src/gui/itemviews/qtreeview.h), qabstractitemview.cpp (https://qt.gitorious.org/qt/qt/source/9d9b7f53750dce2da88d7d11d312b4b36250b5c5:src/gui/itemviews/qabstractitemview.cpp), and qabstractitemview.h (https://qt.gitorious.org/qt/qt/source/57756e72adf2081137b97f0e689dd16c770d10b1:src/gui/itemviews/qabstractitemview.h).
So I seem to be having a problem similar to when I was tracking down the definition of createIndex. Namely, figuring out where to find the relevant source code.
More generally, anyone please let us know if you have seen a good nuts 'n' bolts explanation of how QTreeView works. I have found high-level descriptions of what is going on (e.g., the view uses indexes to determine what to paint to the screen), but I really want to know more under the hood. I have started putting print commands in the model for all the methods (e.g., rowCount), but this has made me even more confused: for instance, sometimes it is calling rowCount with input from a parent index from a row that is way below my selection. :confused:
Thanks for reading.
I understand indexes a bit (because of a thread here (http://www.qtcentre.org/threads/61213-Source-code-for-createIndex%28%29)), and now am trying to understand QTreeView, in particular how it paints the initial tree, determines what to draw, when/where it calls model.rowCount() and other methods from my QAbstractItemModel subclass.
I've been looking over qtreeview.cpp (https://qt.gitorious.org/qt/qt/source/5fe6a7457033b183d8cc3861fe8593338ad3385b:src/gui/itemviews/qtreeview.cpp) and am confused. My first confusion is about what the 'd' class is. I think it is an instance of QTreeView, because starting on line 196 we have:
QTreeView::QTreeView(QTreeViewPrivate &dd, QWidget *parent)
: QAbstractItemView(dd, parent)
{
Q_D(QTreeView);
d->initialize();
}
But there are lots of methods/attributes of d that I cannot find defined anywhere. For instance viewItems seems pretty key, and has many methods (e.g., resize(), clear()) that I'd like to study. Unfortunately I am not sure where viewItems is defined initially, what it means. I have never seen it documented, or used it explicitly in my custom views. In addition to qtreeview.cpp, I searched for it in qtreeview.h (https://qt.gitorious.org/qt/qt/source/57756e72adf2081137b97f0e689dd16c770d10b1:src/gui/itemviews/qtreeview.h), qabstractitemview.cpp (https://qt.gitorious.org/qt/qt/source/9d9b7f53750dce2da88d7d11d312b4b36250b5c5:src/gui/itemviews/qabstractitemview.cpp), and qabstractitemview.h (https://qt.gitorious.org/qt/qt/source/57756e72adf2081137b97f0e689dd16c770d10b1:src/gui/itemviews/qabstractitemview.h).
So I seem to be having a problem similar to when I was tracking down the definition of createIndex. Namely, figuring out where to find the relevant source code.
More generally, anyone please let us know if you have seen a good nuts 'n' bolts explanation of how QTreeView works. I have found high-level descriptions of what is going on (e.g., the view uses indexes to determine what to paint to the screen), but I really want to know more under the hood. I have started putting print commands in the model for all the methods (e.g., rowCount), but this has made me even more confused: for instance, sometimes it is calling rowCount with input from a parent index from a row that is way below my selection. :confused:
Thanks for reading.