Class QAbstractItemModel:
使用QML的TreeView类来展示树状的结构,对应的是QT的Model/View模型。这个model是一个数据模型,要为TreeView提供一个模型,需要定义一个类,该类需要继承自calss QAbstractItemModel,不能直接使用该类。
另外,If you need a model to use with an item view such as QML's List View element or the C++ widgets QListView or QTableView, you should consider subclassing QAbstractListModel or QAbstractTableModel instead of this class.
定义的模型可以是有层次关系的(即有item含有孩子),模型被传递给Views和delegates. 如果模型没有层次关系,那么就指示一个简单的表格,表中的每个元素(item)都有唯一的index,index是 calss QModelIndex的对象,The QModelIndex class is used to locate data in a data model.
模型中的每一个Item对应一个model index, 可以通过QAbstractItemModel::index函数来获取,但是该函数式纯虚函数,需要使用者自己实现,具体实现方法??
Each item has a number of data elements associated with it ,each with its own role, and these elements can be retrieved(检索,取出) by specifying a role (see Qt::ItemDataRole) to the model's data() function. Data for all available roles can be obtained at the same time using theitemData() function. The roles are used by the view to indicate to the model which type of data it needs(View使用这些roles来告诉模型,自己需要模型的哪一中数据来显示在图形上). ---------- 没大明白,指的是模型中的每一个item都有很多属性吗,然后每一个属性对应着一个唯一的role,说属性的值就相当于说该属性的role的值?
Data for each role is set using a particular Qt::ItemDataRole. Data for individual roles are set individually with setData(), or they can be set for all roles with setItemData().---- Qt::ItemDataRole的作用是设置某个item的某个role对应的值。
Items can be queried with flags() (see Qt::ItemFlag) to see if they can be selected, dragged, or manipulated in other ways.---flags()为虚函数。
If an item has child objects, hasChildren() returns true for the corresponding index.----hasChildren()是虚函数。
The model has a rowCount() and a columnCount() for each level of the hierarchy. Rows and columns can be inserted and removed with insertRows(), insertColumns(), removeRows(), and removeColumns().-----rowCount() and a co