1 Star 0 Fork 1

廖昌海 / qt_excel

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
treeitem.cpp 2.45 KB
一键复制 编辑 原始数据 按行查看 历史
#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;
}
1
https://gitee.com/liaoch_top/qt_excel.git
git@gitee.com:liaoch_top/qt_excel.git
liaoch_top
qt_excel
qt_excel
master

搜索帮助