#include "IndexSystemWidget.h" #include "EditNodeWidget.h" #include #include #include #include #include #include #include #include #include #include #include #include #include IndexSystemWidget::IndexSystemWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent) { setTitle("指标体系设计"); initWidgets(); initLayout(); connectSignalsAndSlots(); } void IndexSystemWidget::setType(int type) { EvalWidget::setType(type); setupTabWidget(); } void IndexSystemWidget::contextMenuEvent(QContextMenuEvent *event) { RoundMenu *menu = new RoundMenu(); CMindView *m = (CMindView *)m_tab->currentWidget(); if (m->root() == nullptr) { QAction *act3 = new QAction("创建根节点"); menu->addAction(act3); connect(act3, &QAction::triggered, this, &IndexSystemWidget::slotCreateRootNode); menu->exec(event->globalPos() + QPoint(-40, -20)); } else { // QAction *act2 = new QAction("清空"); // menu->addAction(act2); // connect(act2, &QAction::triggered, this, &IndexSystemWidget::slotClearAllNodes); } QWidget::contextMenuEvent(event); } void IndexSystemWidget::setupTabWidget() { m_tab->clear(); for (int i : indexList()) { CMindView *m = new CMindView(this); ProjectManager::IndexType t = (ProjectManager::IndexType)i; QString s = ProjectManager::nameOfIndexType(t); m_tab->addTab(m, s); QList list; bool ret = CNodeDataService().QueryAll(list, proj()->id, t); if (ret) { m->setNodeList(list); } connect(m, &CMindView::sigEditNode, this, &IndexSystemWidget::slotEditNode); connect(m, &CMindView::sigAddSubNode, this, &IndexSystemWidget::slotAddSubNode); connect(m->mind(), &CMind::sigRemoveNode, this, &IndexSystemWidget::slotRemoveNode); connect(m, &CMindView::sigNodeChanged, this, &IndexSystemWidget::slotUpdateNode); } } void IndexSystemWidget::initWidgets() { m_editNode = new EditNodeWidget(this); } void IndexSystemWidget::initLayout() { } void IndexSystemWidget::connectSignalsAndSlots() { connect(m_tab, &QTabWidget::currentChanged, this, &IndexSystemWidget::slotTabCurrentChanged); connect(m_editNode, &EditNodeWidget::sigSaveNode, this, &IndexSystemWidget::slotNodeEdited); } void IndexSystemWidget::addNode(CNodeData node) { CMindView *m = (CMindView *)m_tab->currentWidget(); if (m->mind()->canAddNode(node)) { int id = CNodeDataService().AddCNodeData(node); if (id >= 0) { node.id = id; m->addNode(node); } } } bool IndexSystemWidget::hasData(QString indexName) const { bool ret = NodeMatrixService().hasMeasureData(m_proj->id, indexName); if (ret == true) { return true; } QList cfgList; ret = UserConfigService().QueryUserConfigListInfoByEngineerId(&cfgList, m_proj->id); if (ret == false) { return false; } for (UserConfig *cfg : cfgList) { ret = NodeMatrixService().hasExpertData(m_proj->id, indexName, cfg->userId); if (ret) { return true; } } return false; } void IndexSystemWidget::slotTabCurrentChanged(int c) { bool ret = hasData(m_tab->tabText(c)); CMindView *m = (CMindView *)m_tab->currentWidget(); if (m != nullptr) { m->setAllowEdit(!ret); QList list = m->mind()->nodeList(); m->setNodeList(list); } } void IndexSystemWidget::slotSelectAllNodes() { } void IndexSystemWidget::slotClearAllNodes() { CMindView *m = (CMindView *)m_tab->currentWidget(); m->clear(); } void IndexSystemWidget::slotCreateRootNode() { int t = indexList()[m_tab->currentIndex()]; CNodeData n = CNodeData(m_proj->id, t, 0); n.name = m_proj->projectName; addNode(n); } void IndexSystemWidget::slotEditNode(CNodeData n) { m_editNode->setNode(n); m_editNode->show(); } void IndexSystemWidget::slotAddSubNode(int pNumber) { if (pNumber < 0) { return; } CMindView *m = (CMindView *)m_tab->currentWidget(); CNodeData data = m->root()->data(); CNodeData n = CNodeData(data.projectId, data.indexType, m->mind()->maxNumber() + 1, pNumber); addNode(n); } void IndexSystemWidget::slotUpdateNode(CNodeData node) { CNodeDataService().UpdateCNodeData(node); } void IndexSystemWidget::slotRemoveNode(int id) { CNodeDataService().DeleteCNodeDataById(id); } void IndexSystemWidget::slotNodeEdited(CNodeData node) { // 在弹窗中编辑节点后, 先保存数据库, 再更新界面 bool ret = CNodeDataService().UpdateCNodeData(node); if (ret) { CMindView *m = (CMindView *)m_tab->currentWidget(); m->updateNode(node); } }