EXProjectView.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include "EXProjectView.h"
  2. #include "EXIndexView.h"
  3. #include "EXDataView.h"
  4. #include "ProjectManager.h"
  5. #include <dbService/ClassSet.h>
  6. #include <common/QFDIcon.h>
  7. #include <Widgets/Button.h>
  8. #include <Widgets/LineEdit.h>
  9. #include <Widgets/TreeView.h>
  10. #include <QBoxLayout>
  11. #include <QLabel>
  12. #include <QStackedWidget>
  13. #include <QPushButton>
  14. #include <QDebug>
  15. EXProjectView::EXProjectView(ProjectInfo *proj, QWidget *parent) : QWidget(parent), m_proj(proj)
  16. {
  17. initWidgets();
  18. initLayout();
  19. connectSigalsAndSlots();
  20. if (m_tree->topLevelItemCount() > 0) {
  21. itemClicked(m_tree->topLevelItem(0), 0);
  22. }
  23. }
  24. void EXProjectView::showEvent(QShowEvent *event)
  25. {
  26. QWidget::showEvent(event);
  27. }
  28. void EXProjectView::hideEvent(QHideEvent *event)
  29. {
  30. QWidget::hideEvent(event);
  31. }
  32. ProjectInfo *EXProjectView::proj() const
  33. {
  34. return m_proj;
  35. }
  36. void EXProjectView::showEvalWidget(int eval, int task)
  37. {
  38. m_stack->setCurrentIndex(task);
  39. m_export->setVisible(task == 1);
  40. EXEvalView *w = (EXEvalView *)m_stack->widget(task);
  41. w->setType(eval);
  42. ProjectManager::EvalType type = (ProjectManager::EvalType)eval;
  43. qDebug() << __FUNCTION__ << __LINE__ << type;
  44. }
  45. void EXProjectView::initWidgets()
  46. {
  47. m_title = new QLabel(this);
  48. m_title->setText(m_proj->projectName);
  49. QFont ft("Microsoft YaHei", 14);
  50. m_title->setFont(ft);
  51. m_tree = new TreeWidget(this);
  52. // 根据评估类型添加列表条目
  53. QList<ProjectManager::EvalType> types = ProjectManager::evalTypeList(*m_proj);
  54. for (int i = 0; i < types.count(); i++) {
  55. QString typeName = ProjectManager::nameOfEvalType(types[i]);
  56. QTreeWidgetItem *item = new QTreeWidgetItem({ typeName });
  57. Qt::ItemFlags f = item->flags() ^ Qt::ItemIsSelectable;
  58. item->setFlags(f); // 设置 topLevelItem 不可选中
  59. item->addChildren({ new QTreeWidgetItem({ "指标体系" }), new QTreeWidgetItem({ "数据采集" }) });
  60. m_tree->addTopLevelItem(item);
  61. }
  62. m_tree->expandAll();
  63. m_tree->setHeaderHidden(true);
  64. m_tree->setFixedWidth(200);
  65. // 分割线
  66. m_seperator = new QWidget(this);
  67. m_seperator->setFixedWidth(1);
  68. QPalette pal(m_seperator->palette());
  69. pal.setColor(QPalette::Background, QColor("#aaaaaa"));
  70. m_seperator->setAutoFillBackground(true);
  71. m_seperator->setPalette(pal);
  72. m_stack = new QStackedWidget(this);
  73. m_indexSystem = new EXIndexView(m_proj, m_stack);
  74. m_dataCollection = new EXDataView(m_proj, m_stack);
  75. m_stack->addWidget(m_indexSystem);
  76. m_stack->addWidget(m_dataCollection);
  77. m_export = new PushButton("导出", this);
  78. m_user = new PushButton("user");
  79. m_user->setHidden(true);
  80. }
  81. void EXProjectView::initLayout()
  82. {
  83. m_layout = new QVBoxLayout(this);
  84. m_headerLayout = new QHBoxLayout();
  85. m_layout->addLayout(m_headerLayout);
  86. m_contentLayout = new QHBoxLayout();
  87. m_layout->addLayout(m_contentLayout);
  88. m_headerLayout->addWidget(m_title);
  89. m_headerLayout->addSpacing(20);
  90. m_headerLayout->addStretch();
  91. m_headerLayout->addWidget(m_export);
  92. m_headerLayout->addWidget(m_user);
  93. m_contentLayout->addWidget(m_tree);
  94. m_contentLayout->addWidget(m_seperator);
  95. m_contentLayout->addWidget(m_stack);
  96. }
  97. void EXProjectView::connectSigalsAndSlots()
  98. {
  99. connect(m_tree, &TreeWidget::itemClicked, this, &EXProjectView::itemClicked);
  100. connect(m_export, &PushButton::clicked, m_dataCollection, &EXDataView::slotExportData);
  101. connect(m_dataCollection, &EXDataView::signalCompleteStateChanged, this, &EXProjectView::slotCompleteStateChanged);
  102. }
  103. void EXProjectView::itemClicked(QTreeWidgetItem *item, int column)
  104. {
  105. Q_UNUSED(column)
  106. int typeIndex = m_tree->indexOfTopLevelItem(item); // 评估类型, 一级条目
  107. int taskIndex = -1; // 评估事项, 二级条目
  108. if (typeIndex < 0) {
  109. typeIndex = m_tree->indexOfTopLevelItem(item->parent());
  110. taskIndex = item->parent()->indexOfChild(item);
  111. }
  112. // 点击一级条目时, 选中其首个子条目
  113. if (taskIndex < 0) {
  114. taskIndex = 0;
  115. item->child(taskIndex)->setSelected(true);
  116. }
  117. ProjectManager::EvalType eval = ProjectManager::evalTypeList(*m_proj)[typeIndex];
  118. QString typeName = ProjectManager::nameOfEvalType(eval);
  119. showEvalWidget(eval, taskIndex);
  120. }
  121. void EXProjectView::slotCompleteStateChanged(bool complete)
  122. {
  123. m_export->setEnabled(complete);
  124. m_export->setToolTip(complete ? "导出评估数据" : "请将该评估类型的数据补充完整后再导出");
  125. }