qt5base-lts/examples/widgets/itemviews/simpledommodel/domitem.cpp
Lucie Gérard 05fc3aef53 Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Task-number: QTBUG-67283
Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-05-16 16:37:38 +02:00

63 lines
1.0 KiB
C++

// 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]