176 lines
5.4 KiB
C++
176 lines
5.4 KiB
C++
#include <QMessageBox>
|
||
#include "itemPropertyDlg.h"
|
||
#include "propertyContentDlg.h"
|
||
#include "dataManager.h"
|
||
#include "graphicsItem/graphicsBaseItem.h"
|
||
#include "ui_itemPropertyDlg.h"
|
||
#include "baseContentDlg.h"
|
||
#include "baseInfoDlg.h"
|
||
//#include "topologyManager.h"
|
||
#include "basePropertyManager.h"
|
||
#include "baseProperty.h"
|
||
#include "ptExtraInfoDlg.h"
|
||
#include "ctExtraInfoDlg.h"
|
||
#include "bayInfoDlg.h"
|
||
|
||
ItemPropertyDlg::ItemPropertyDlg(QWidget *parent)
|
||
: QDialog(parent)
|
||
, ui(new Ui::itemPropertyDlg)
|
||
,layout_(nullptr)
|
||
,btnGroup_(nullptr)
|
||
,_curItem(nullptr)
|
||
,_curModelController(nullptr)
|
||
{
|
||
ui->setupUi(this);
|
||
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
||
initial();
|
||
}
|
||
|
||
ItemPropertyDlg::~ItemPropertyDlg()
|
||
{
|
||
delete ui;
|
||
}
|
||
|
||
void ItemPropertyDlg::initial()
|
||
{
|
||
layout_ = new QVBoxLayout(ui->widget_button);
|
||
btnGroup_ = new QButtonGroup(this);
|
||
connect(ui->btn_ok,&QPushButton::clicked,this,&ItemPropertyDlg::onOkClicked);
|
||
connect(ui->btn_cancel,&QPushButton::clicked,this,&ItemPropertyDlg::onCancelClicked);
|
||
}
|
||
|
||
void ItemPropertyDlg::loadGroupButton(QMap<QString,groupStateInfo> map)
|
||
{
|
||
groupInfo_ = map;
|
||
for(auto &info:map)
|
||
{
|
||
QPushButton* btn = new QPushButton(ui->widget_button);
|
||
btn->setText(info.groupName);
|
||
btn->setCheckable(true);
|
||
btnGroup_->addButton(btn);
|
||
btnMap_.insert(info.groupName, btn);
|
||
if(info.isPublic) //公共属性组置顶
|
||
layout_->insertWidget(0,btn);
|
||
else
|
||
layout_->addWidget(btn);
|
||
|
||
connect(btn, &QAbstractButton::clicked, [this, info](){
|
||
onGroupSelected(info.groupName);
|
||
});
|
||
}
|
||
layout_->addStretch();
|
||
}
|
||
|
||
void ItemPropertyDlg::onOkClicked()
|
||
{
|
||
//todo:将属性页中的值读取到当前uuid对象
|
||
if(_curItem)
|
||
{
|
||
if(_curItem->getProperty() == nullptr)
|
||
{
|
||
//todo:弹出输入框输入名称
|
||
QMessageBox::information(NULL, QString("提示"), QString::fromWCharArray(L"对象未命名"));
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
curUuid_ = _curItem->getProperty()->uuid(); //使用数据uuid,数据唯一,item不唯一
|
||
}
|
||
}
|
||
QMap<QString, QWidget*>::Iterator iter;
|
||
BaseProperty* pPro = BasePropertyManager::instance().findEntityData(curUuid_);
|
||
for(iter = groupViews_.begin();iter != groupViews_.end();++iter)
|
||
{
|
||
BaseContentDlg* pDlg = qobject_cast<BaseContentDlg*>(iter.value());
|
||
QMap<QString,propertyStateInfo> mapPro = pDlg->getPropertyValue(pPro);
|
||
if(!mapPro.empty())
|
||
DataManager::instance().updateModelData(_curModel,curUuid_,iter.key(),mapPro);
|
||
}
|
||
hide();
|
||
}
|
||
|
||
void ItemPropertyDlg::onCancelClicked()
|
||
{
|
||
hide();
|
||
}
|
||
|
||
void ItemPropertyDlg::onGroupSelected(const QString& str)
|
||
{
|
||
if (!groupViews_.contains(str)) {
|
||
createGroupView(str);
|
||
}
|
||
|
||
BaseContentDlg* pDlg = qobject_cast<BaseContentDlg*>(groupViews_[str]);
|
||
if(pDlg)
|
||
{
|
||
QMap<QString,propertyStateInfo> valueMap;
|
||
BaseProperty* pPro = BasePropertyManager::instance().findEntityData(curUuid_);
|
||
if(str != QString("component") && str != QString("bay"))
|
||
{
|
||
if(groupValue_[str].mapInfo.contains(curUuid_))
|
||
valueMap = groupValue_[str].mapInfo[curUuid_];
|
||
else //没有值时使用默认值
|
||
valueMap = groupInfo_[str].info;
|
||
pDlg->setPropertyValue(QVariant::fromValue(valueMap));
|
||
}
|
||
else{
|
||
pDlg->setPropertyValue(QVariant::fromValue(static_cast<void*>(pPro)));
|
||
}
|
||
}
|
||
|
||
ui->stackedWidget->setCurrentWidget(groupViews_[str]);
|
||
}
|
||
|
||
|
||
void ItemPropertyDlg::createGroupView(const QString& str)
|
||
{
|
||
//todo:基础信息、间隔信息、动态界面在此分支
|
||
BaseContentDlg* contentDlg = nullptr;
|
||
BaseProperty* pPro = BasePropertyManager::instance().findEntityData(curUuid_);
|
||
if(str == QString("component") || str == QString::fromWCharArray(L"基本信息")){
|
||
contentDlg = new BaseInfoDlg(ui->stackedWidget);
|
||
}
|
||
else if(str == "base_extend" || str == QString::fromWCharArray(L"扩展信息")){
|
||
if(pPro->type() == 4)
|
||
contentDlg = new CtExtraInfoDlg(ui->stackedWidget);
|
||
else if(pPro->type() == 5)
|
||
contentDlg = new PtExtraInfoDlg(ui->stackedWidget);
|
||
else
|
||
contentDlg = new PropertyContentDlg(ui->stackedWidget);
|
||
}
|
||
else if(str == "bay" || str == QString::fromWCharArray(L"间隔信息")){
|
||
contentDlg = new BayInfoDlg(ui->stackedWidget);
|
||
}
|
||
else{
|
||
contentDlg = new PropertyContentDlg(ui->stackedWidget);
|
||
}
|
||
|
||
if(contentDlg)
|
||
{
|
||
contentDlg->createGroupView(groupInfo_[str]);
|
||
}
|
||
|
||
contentDlg->setModelController(_curModelController); //传递modelControl
|
||
groupViews_.insert(str, contentDlg);
|
||
ui->stackedWidget->addWidget(contentDlg);
|
||
}
|
||
|
||
void ItemPropertyDlg::showDlg(modelDataInfo dataInfo,QUuid uuid,GraphicsProjectModelItem* pItem)
|
||
{
|
||
groupValue_ = dataInfo.groupInfo;
|
||
curUuid_ = uuid;
|
||
_curModel = dataInfo.modelName;
|
||
_curItem = pItem;
|
||
|
||
QString str;
|
||
auto btn = dynamic_cast<QPushButton*>(btnGroup_->checkedButton());
|
||
if(btn == nullptr){
|
||
str = groupInfo_.constBegin().key(); //打开默认显示第一个属性组
|
||
}
|
||
else{
|
||
str = btn->text();
|
||
}
|
||
onGroupSelected(str);
|
||
show();
|
||
}
|