ProjectView.cpp 4.5 KB

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