You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.8 KiB
C++

#include "FITKTreeWidget.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
namespace Comp
{
FITKTreeWidget::FITKTreeWidget(QWidget* parent /*= nullptr*/)
:QTreeWidget(parent)
{
//关联类内槽函数
connect(this, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(slot_itemClicked(QTreeWidgetItem*, int)));
connect(this, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(slot_itemDoubleClicked(QTreeWidgetItem*, int)));
connect(this, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slot_itemStateChanged(QTreeWidgetItem*, int)));
}
QTreeWidgetItem* FITKTreeWidget::CreateTreeRootItem(QTreeWidget* parent, const QString & text, int type /*= 0*/, const QString& icon /*= ""*/, int state /*= -1*/)
{
//创建新的对象
QTreeWidgetItem* item = new QTreeWidgetItem(parent, type);
//设置参数
item->setText(0, text);
item->setIcon(0, QIcon(icon));
if (state != -1)
item->setCheckState(0, (state ? Qt::CheckState::Checked : Qt::CheckState::Unchecked));
if (parent)
parent->addTopLevelItem(item);
return item;
}
QTreeWidgetItem* FITKTreeWidget::CreateTreeItem(QTreeWidgetItem* parent, const QString & text, int type /*= 0*/, const QString& icon /*= ""*/, int state /* = -1*/)
{
//创建新的对象
QTreeWidgetItem* item = new QTreeWidgetItem(parent, type);
//设置参数
item->setText(0, text);
item->setIcon(0, QIcon(icon));
if (state != -1)
item->setCheckState(0, (state ? Qt::CheckState::Checked : Qt::CheckState::Unchecked));
if(parent)
parent->addChild(item);
return item;
}
Core::FITKAbstractOperator* FITKTreeWidget::GetOperator(const QString& operName)
{
//从操作器仓库获取
return Core::FITKOperatorRepo::getInstance()->getOperator(operName);
}
void FITKTreeWidget::on_itemClicked(QTreeWidgetItem *item, int column)
{
//虚函数
}
void FITKTreeWidget::on_itemDoubleClicked(QTreeWidgetItem *item, int column)
{
//虚函数
}
void FITKTreeWidget::on_itemStateChanged(QTreeWidgetItem *item, bool state, int column)
{
//虚函数
}
void FITKTreeWidget::slot_itemClicked(QTreeWidgetItem *item, int column)
{
//虚函数实现
this->on_itemClicked(item, column);
}
void FITKTreeWidget::slot_itemDoubleClicked(QTreeWidgetItem *item, int column)
{
//虚函数实现
this->on_itemDoubleClicked(item, column);
}
void FITKTreeWidget::slot_itemStateChanged(QTreeWidgetItem *item, int column)
{
bool state = item->checkState(column) == Qt::CheckState::Checked;
this->on_itemStateChanged(item, state, column);
}
}