| CMakeLists.txt |
|
1124 |
- |
| doc |
|
|
- |
| qqmlabstractcolumnmodel.cpp |
|
18578 |
- |
| qqmlabstractcolumnmodel_p.h |
|
4622 |
- |
| qqmldelegatechooser.cpp |
|
349 |
- |
| qqmldelegatechooser_p.h |
|
1099 |
- |
| qqmlmodelsglobal_p.h |
|
578 |
- |
| qqmltablemodel.cpp |
|
21412 |
- |
| qqmltablemodel_p.h |
|
2821 |
- |
| qqmltablemodelcolumn.cpp |
!
\qmltype TableModelColumn
//! \nativetype QQmlTableModelColumn
\inqmlmodule Qt.labs.qmlmodels
\brief Represents a column in a model.
\since 5.14
The TableModelColumn class represents columns in TableModel.
TableModel supports JavaScript/JSON data where each row is an object,
a list of simple key-value pairs where the keys are unordered.
\code
{
// Each property is one cell/column.
checked: false,
amount: 1,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
// ...
\endcode
However, models in Qt are manipulated via row and column indices. Specifying
the columns with TableModelColumn allows a mapping between Qt's built-in
roles to any property in each row object.
\snippet qml/tablemodel/fruit-example-simpledelegate.qml file
TableModelColumn also has basic read-only support for complex rows. For more
information, see \l {Supported Row Data Structures}.
\note Most of the above concepts also apply to TreeModel, except in
TreeModel each row represents a node of the tree.
\section1 Supported Roles
TableModelColumn supports all of \l {Qt::ItemDataRole}{Qt's roles},
with the exception of \c Qt::InitialSortOrderRole.
Roles can be accessed by as listed below, e.g.
\code
text: display
required property string display
\endcode
\table
\row \li Qt::DisplayRole \li display
\row \li Qt::DecorationRole \li decoration
\row \li Qt::EditRole \li edit
\row \li Qt::ToolTipRole \li toolTip
\row \li Qt::StatusTipRole \li statusTip
\row \li Qt::WhatsThisRole \li whatsThis
\row \li Qt::FontRole \li font
\row \li Qt::TextAlignmentRole \li textAlignment
\row \li Qt::BackgroundRole \li background
\row \li Qt::ForegroundRole \li foreground
\row \li Qt::CheckStateRole \li checkState
\row \li Qt::AccessibleTextRole \li accessibleText
\row \li Qt::AccessibleDescriptionRole \li accessibleDescription
\row \li Qt::SizeHintRole \li sizeHintRoleNam
\endtable
\sa TableModel, TableView
|
6621 |
- |
| qqmltablemodelcolumn_p.h |
|
4507 |
- |
| qqmltreemodel.cpp |
!
\qmltype TreeModel
//! \nativetype QQmlTreeModel
\inqmlmodule Qt.labs.qmlmodels
\brief Encapsulates a simple tree model.
\since 6.10
The TreeModel type stores JavaScript/JSON objects as data for a tree
model that can be used with \l TreeView. It is intended to support
very simple models without requiring the creation of a custom
\l QAbstractItemModel subclass in C++.
\snippet qml/treemodel/treemodel-filesystem-basic.qml file
The model's initial data is set with either the \l rows property or by
calling \l appendRow(). Each column in the model is specified by declaring
a \l TableModelColumn instance, where the order of each instance determines
its column index. Once the model's \l Component::completed() signal has been
emitted, the columns and roles will have been established and are then
fixed for the lifetime of the model.
\section1 Supported Row Data Structures
Each row represents a node in the tree. Each node has the same type of
columns. The TreeModel is designed to work with JavaScript/JSON data so
each row is a list of simple key-value pairs:
\snippet qml/treemodel/treemodel-filesystem-basic.qml rows
A node can have child nodes and these will be stored in an array
associated with the "rows" key. "rows" is reserved for this purpose: only
the list of child nodes should be associated with this key.
The model is manipulated via \l {QModelIndex} {QModelIndices}. To access
a specific row/node, the \l getRow() function can be used. It's also
possible to access the model's JavaScript data directly via the \l rows
property, but it is not possible to modify the model data this way.
To add new rows, use \l appendRow(). To modify existing rows, use
\l setRow(), \l removeRow() and \l clear().
\section1 Using the TreeModel with External JSON Sources
While the intended use of the TreeModel is to define the JSON data in-place in
the QML file, you can use any JSON object with the model as long as
its structure matches the structure defined by the TreeModel. If all the rows
of the JSON object conform to the columns defined by the model, you can
assign it directly through the rows property.
The source of the JSON object can be a file. For example, if the model is
defined as
\snippet setRowsViaJSON.qml model
and the JSON object stored in the file and looks like
\snippet TreeData.js file
then this object can be provided by importing the JavaScript file as a
module
\snippet setRowsViaJSON.qml import
and then it can be assigned directly
\snippet setRowsViaJSON.qml assignment
\warning Ensure that the JSON data comes from a trusted source. Since the
model dynamically populates its rows based on the input, malformed or
untrusted JSON can lead to unexpected behavior or performance issues.
See \l TableModel for an another example where a JSON object is parsed
into and assigned as a JavaScript array.
\sa TableModelColumn, TreeView
|
26968 |
- |
| qqmltreemodel_p.h |
|
3061 |
- |
| qqmltreerow.cpp |
|
5548 |
- |
| qqmltreerow_p.h |
|
2194 |
- |