diff options
Diffstat (limited to 'tests/manual/examples/widgets/itemviews/simpledommodel/domitem.cpp')
-rw-r--r-- | tests/manual/examples/widgets/itemviews/simpledommodel/domitem.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/manual/examples/widgets/itemviews/simpledommodel/domitem.cpp b/tests/manual/examples/widgets/itemviews/simpledommodel/domitem.cpp new file mode 100644 index 0000000000..b3e197b3db --- /dev/null +++ b/tests/manual/examples/widgets/itemviews/simpledommodel/domitem.cpp @@ -0,0 +1,62 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "domitem.h" + +#include <QtXml> + +//! [0] +DomItem::DomItem(const QDomNode &node, int row, DomItem *parent) + : domNode(node), +//! [0] + // Record the item's location within its parent. +//! [1] + parentItem(parent), + rowNumber(row) +{} +//! [1] + +//! [2] +DomItem::~DomItem() +{ + qDeleteAll(childItems); +} +//! [2] + +//! [3] +QDomNode DomItem::node() const +{ + return domNode; +} +//! [3] + +//! [4] +DomItem *DomItem::parent() +{ + return parentItem; +} +//! [4] + +//! [5] +DomItem *DomItem::child(int i) +{ + DomItem *childItem = childItems.value(i); + if (childItem) + return childItem; + + // if child does not yet exist, create it + if (i >= 0 && i < domNode.childNodes().count()) { + QDomNode childNode = domNode.childNodes().item(i); + childItem = new DomItem(childNode, i, this); + childItems[i] = childItem; + } + return childItem; +} +//! [5] + +//! [6] +int DomItem::row() const +{ + return rowNumber; +} +//! [6] |