You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.0 KiB
67 lines
2.0 KiB
#include "viewmodel/tree/TreeItem.h"
|
|
|
|
/*************************************************************************************************/
|
|
TreeItem::TreeItem(QVariantList data)
|
|
: _itemData(std::move(data)), _parentItem(nullptr)
|
|
{
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void TreeItem::appendChild(std::unique_ptr<TreeItem>&& child)
|
|
{
|
|
child->_parentItem = this;
|
|
_childItems.push_back(std::move(child));
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
TreeItem* TreeItem::child(int row)
|
|
{
|
|
return row >= 0 && row < childCount() ? _childItems.at(size_t(row)).get() : nullptr;
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
int TreeItem::childCount() const
|
|
{
|
|
return int(_childItems.size());
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
int TreeItem::row() const
|
|
{
|
|
if(_parentItem == nullptr)
|
|
{
|
|
return 0;
|
|
}
|
|
const auto it = std::find_if(_parentItem->_childItems.cbegin(),
|
|
_parentItem->_childItems.cend(),
|
|
[this](const std::unique_ptr<TreeItem>& treeItem) {
|
|
return treeItem.get() == this;
|
|
});
|
|
|
|
if(it != _parentItem->_childItems.cend())
|
|
{
|
|
return static_cast<int>(std::distance(_parentItem->_childItems.cbegin(), it));
|
|
}
|
|
|
|
Q_ASSERT(false); //should not happen
|
|
|
|
return -1;
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
int TreeItem::columnCount() const
|
|
{
|
|
return int(_itemData.count());
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
QVariant TreeItem::data(int column) const
|
|
{
|
|
return _itemData.value(column);
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
TreeItem* TreeItem::parentItem()
|
|
{
|
|
return _parentItem;
|
|
}
|
|
|