summaryrefslogtreecommitdiffstats
path: root/examples/widgets/doc/src/editabletreemodel.qdoc
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2023-05-26 18:05:27 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-06-28 23:54:11 +0000
commit604b2feca751c5eb43b20e180c175acc2a87099e (patch)
treecdf080d106a084ea542d43f523bda6213d6dfec6 /examples/widgets/doc/src/editabletreemodel.qdoc
parent7bad2902f84a44da00a8cbc8e3acbec3b26c6866 (diff)
Modernize EditableTreeModel
- Use unique_ptr instead of manual memory management - Improve consistenty in variable name with the simpletreemodel childrenNumber -> row, m_ prefix for member variables Change-Id: Iface30c2224c2b1db7c623a9e6fcbb449c556f3e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'examples/widgets/doc/src/editabletreemodel.qdoc')
-rw-r--r--examples/widgets/doc/src/editabletreemodel.qdoc33
1 files changed, 16 insertions, 17 deletions
diff --git a/examples/widgets/doc/src/editabletreemodel.qdoc b/examples/widgets/doc/src/editabletreemodel.qdoc
index 9616610758..4d2b9e2753 100644
--- a/examples/widgets/doc/src/editabletreemodel.qdoc
+++ b/examples/widgets/doc/src/editabletreemodel.qdoc
@@ -229,32 +229,30 @@
internal \c childItems member using the \c insertChildren() function
described later.
- The destructor ensures that each child added to the item is deleted
- when the item itself is deleted:
-
- \snippet itemviews/editabletreemodel/treeitem.cpp 1
+ The children are stored in std::unique_ptr to ensures that each child
+ added to the item is deleted when the item itself is deleted.
\target TreeItem::parent
Since each item stores a pointer to its parent, the \c parent() function
is trivial:
- \snippet itemviews/editabletreemodel/treeitem.cpp 9
+ \snippet itemviews/editabletreemodel/treeitem.cpp 8
\target TreeItem::child
Three functions provide information about the children of an item.
\c child() returns a specific child from the internal list of children:
- \snippet itemviews/editabletreemodel/treeitem.cpp 2
+ \snippet itemviews/editabletreemodel/treeitem.cpp 1
The \c childCount() function returns the total number of children:
- \snippet itemviews/editabletreemodel/treeitem.cpp 3
+ \snippet itemviews/editabletreemodel/treeitem.cpp 2
The \c childNumber() function is used to determine the index of the child
in its parent's list of children. It accesses the parent's \c childItems
member directly to obtain this information:
- \snippet itemviews/editabletreemodel/treeitem.cpp 4
+ \snippet itemviews/editabletreemodel/treeitem.cpp 3
The root item has no parent item; for this item, we return zero to be
consistent with the other items.
@@ -262,20 +260,20 @@
The \c columnCount() function simply returns the number of elements in
the internal \c itemData list of QVariant objects:
- \snippet itemviews/editabletreemodel/treeitem.cpp 5
+ \snippet itemviews/editabletreemodel/treeitem.cpp 4
\target TreeItem::data
Data is retrieved using the \c data() function, which accesses the
appropriate element in the \c itemData list:
- \snippet itemviews/editabletreemodel/treeitem.cpp 6
+ \snippet itemviews/editabletreemodel/treeitem.cpp 5
\target TreeItem::setData
Data is set using the \c setData() function, which only stores values
in the \c itemData list for valid list indexes, corresponding to column
values in the model:
- \snippet itemviews/editabletreemodel/treeitem.cpp 11
+ \snippet itemviews/editabletreemodel/treeitem.cpp 10
To make implementation of the model easier, we return true to indicate
that the data was set successfully.
@@ -285,20 +283,20 @@
in the model leads to the insertion of new child items in the corresponding
item, handled by the \c insertChildren() function:
- \snippet itemviews/editabletreemodel/treeitem.cpp 7
+ \snippet itemviews/editabletreemodel/treeitem.cpp 6
This ensures that new items are created with the required number of columns
and inserted at a valid position in the internal \c childItems list.
Items are removed with the \c removeChildren() function:
- \snippet itemviews/editabletreemodel/treeitem.cpp 10
+ \snippet itemviews/editabletreemodel/treeitem.cpp 9
As discussed above, the functions for inserting and removing columns are
used differently to those for inserting and removing child items because
they are expected to be called on every item in the tree. We do this by
recursively calling this function on each child of the item:
- \snippet itemviews/editabletreemodel/treeitem.cpp 8
+ \snippet itemviews/editabletreemodel/treeitem.cpp 7
\section1 TreeModel Class Definition
@@ -334,11 +332,12 @@
use with the model. Other models may be initialized with a ready-made
data structure, or use an API from a library that maintains its own data.
- The destructor only has to delete the root item, which will cause all child
- items to be recursively deleted.
-
\snippet itemviews/editabletreemodel/treemodel.cpp 1
+ The destructor only has to delete the root item, which will cause all child
+ items to be recursively deleted. This is done automatically by the default
+ destructor since the root item is stored inside an unique_ptr.
+
\target TreeModel::getItem
Since the model's interface to the other model/view components is based
on model indexes, and since the internal data structure is item-based,