Qiniactitemmodel
Qiniactitemmodel is an abstract class. The pure virtual methods not implemented by this abstract class include:
Qmodelindex q1_actitemmodel: Index (INT row, int column, const qmodelindex & parent = qmodelindex () const [pure virtual]
Qmodelindex q1_actitemmodel: parent (const qmodelindex & Index) const [pure virtual]
Int qiniactitemmodel: rowcount (const qmodelindex & parent = qmodelindex () const [pure virtual]
Int qiniactitemmodel: columncount (const qmodelindex & parent = qmodelindex () const [pure virtual]
Qvariant qiniactitemmodel: Data (const qmodelindex & Index, int role = QT: displayrole) const [pure virtual]
Index ()
When the model is a hierarchical model, index () is used to return the sub-index with the position (row, column) below the parent when the parent level is parent.
Parent ()
Returns the parent index of the index. If the index is the root index or the index is invalid, the qmodelindex () is returned ().
Rowcount ()
Used to tell the model and view the number of data rows in the source data after the row title is removed.
Columncount ()
Used to tell the model and view, excluding the column title, the number of data columns in the source data.
Data ()
The specific implementation of model data acquisition.
The important virtual methods implemented by this model are headerdata ()
Virtual qvariant headerdata (INT section, QT: Orientation orientation, int role = QT: displayrole) const
The default implementation of this method is: When role is QT: displayrole in any direction, the returned value is the title number of section + 1, and in other cases, a blank qvariant instance is returned.
Data can be displayed normally when you write a table using examples in the previous example in the application book. This time, I wrote it all myself and found that the column title in the table view is not displayed. After debugging, it is found that only the direction judgment does not display the title data. Only after the role judgment is performed can the title be correctly displayed. It is reasonable to say that only direction judgment involves both direction judgment and role judgment. Finally, you can see the source code of qiniactitemmodel. The model (or view) only has an empty qvarient, and does not set an appropriate size for meaningless dimensions. I would like to see whether the model is setting the default value or the view is setting the default value, but I finally gave up. A function definition is easy to find and a function call is too troublesome.
Whether it is data () or headerdata (), when delivering data, we need to judge the data role and then provide the corresponding data. Otherwise, the view may not be able to display the data, or the data display method is unreasonable. The reason why the data cannot be displayed is that if the model needs to obtain the table size suggestion, the role is QT: sizehintrole. If we provide a non-empty qvarient instance, the model uses the size data contained in the instance. If the size data makes sense, the model uses the data to define the table size, otherwise, set the table size to 0x0 (guess). If we provide an empty qvarient instance, the model or view will set a reasonable size. Similarly, for other roles that affect data display, we also need to determine roles and provide appropriate data.