代码拉取完成,页面将自动刷新
#include "treeitem.h"
//TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
TreeItem::TreeItem(const QString &data, TreeItem *parent)
{
m_parentItem = parent;
m_itemData = data;
}
//A pointer to each of the child items belonging to this item will be stored in the childItems private member variable. When the class's destructor is called, it must delete each of these to ensure that their memory is reused:
TreeItem::~TreeItem()
{
qDeleteAll(m_childItems);
}
//Since each of the child items are constructed when the model is initially populated with data, the function to add child items is straightforward:
void TreeItem::appendChild(TreeItem *item)
{
m_childItems.append(item);
}
//Each item is able to return any of its child items when given a suitable row number. For example, in the above diagram, the item marked with the letter "A" corresponds to the child of the root item with row = 0, the "B" item is a child of the "A" item with row = 1, and the "C" item is a child of the root item with row = 1.
//The child() function returns the child that corresponds to the specified row number in the item's list of child items:
TreeItem *TreeItem::child(int row)
{
return m_childItems.value(row);
}
//The number of child items held can be found with childCount():
int TreeItem::childCount() const
{
return m_childItems.count();
}
//The TreeModel uses this function to determine the number of rows that exist for a given parent item.
//The row() function reports the item's location within its parent's list of items:
int TreeItem::row() const
{
if (m_parentItem)
return m_parentItem->m_childItems.indexOf(const_cast<TreeItem*>(this));
return 0;
}
//Note that, although the root item (with no parent item) is automatically assigned a row number of 0, this information is never used by the model.
//The number of columns of data in the item is trivially returned by the columnCount() function.
//int TreeItem::columnCount() const
//{
// return m_itemData.count();
//}
//Column data is returned by the data() function, taking advantage of QList's ability to provide sensible default values if the column number is out of range:
//QVariant TreeItem::data(int column) const
//{
// return m_itemData.value(column);
//}
QString TreeItem::data() const
{
return m_itemData;
}
void TreeItem::setData(const QString &data)
{
m_itemData = data;
}
//The item's parent is found with parent():
TreeItem *TreeItem::parentItem()
{
return m_parentItem;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。