123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- #include "IndexSystemWidget.h"
- #include "EditNodeWidget.h"
- #include <dbService/ClassSet.h>
- #include <dbService/CNodeDataService.h>
- #include <dbService/NodeMatrixService.h>
- #include <dbService/UserConfigService.h>
- #include <CMindView.h>
- #include <CMind.h>
- #include <CNodeItem.h>
- #include <Widgets/Menu.h>
- #include <QLayout>
- #include <QMenu>
- #include <QContextMenuEvent>
- #include <QTabWidget>
- #include <QDebug>
- 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<CNodeData> 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<UserConfig *> 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<CNodeData> 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);
- }
- }
|