2025-03-14 15:07:39 +08:00
|
|
|
|
#include "CEventDeviceTreeItem.h"
|
|
|
|
|
|
|
|
|
|
|
|
CEventDeviceTreeItem::CEventDeviceTreeItem(const QString &data, CEventDeviceTreeItem *parent)
|
|
|
|
|
|
: m_tag(QString()),
|
|
|
|
|
|
m_parentItem(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(m_parentItem)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_parentItem->m_childItems.append(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_data = data;
|
|
|
|
|
|
m_checkState = Qt::Checked;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CEventDeviceTreeItem::~CEventDeviceTreeItem()
|
|
|
|
|
|
{
|
|
|
|
|
|
qDeleteAll(m_childItems);
|
|
|
|
|
|
m_childItems.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CEventDeviceTreeItem *CEventDeviceTreeItem::child(int row)
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_childItems.value(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CEventDeviceTreeItem *CEventDeviceTreeItem::parentItem()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_parentItem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CEventDeviceTreeItem::row() const
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_parentItem)
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_parentItem->m_childItems.indexOf(const_cast<CEventDeviceTreeItem*>(this));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CEventDeviceTreeItem::childCount() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_childItems.count();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CEventDeviceTreeItem::columnCount() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant CEventDeviceTreeItem::data(Qt::ItemDataRole role) const
|
|
|
|
|
|
{
|
|
|
|
|
|
if(Qt::DisplayRole == role)
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_data;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(Qt::UserRole == role)
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_tag;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(Qt::CheckStateRole == role)
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_checkState;
|
|
|
|
|
|
}
|
|
|
|
|
|
return QVariant();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CEventDeviceTreeItem::setData(const QVariant &value, Qt::ItemDataRole role)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(Qt::DisplayRole == role)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_data = value.toString();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(Qt::UserRole == role)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_tag = value.toString();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(Qt::CheckStateRole == role)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_checkState = (Qt::CheckState)value.toInt();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CEventDeviceTreeItem::removeChildren(int position, int count, int columns)
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_UNUSED(columns)
|
|
|
|
|
|
if (position < 0 || position + count > m_childItems.size())
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
for (int row = 0; row < count; ++row)
|
|
|
|
|
|
delete m_childItems.takeAt(position);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|