123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- #include "ProjectView.h"
- #include "ProjectListWidget.h"
- #include "RenameWidget.h"
- #include "ConfigExpertDataWidget.h"
- #include "IndexSystemWidget.h"
- #include "SchemePlanWidget.h"
- #include "DataCollectionWidget.h"
- #include "DataProcessingWidget.h"
- #include "common/ProjectManager.h"
- #include <dbService/ClassSet.h>
- #include <Widgets/Button.h>
- #include <Widgets/LineEdit.h>
- #include <Widgets/TreeView.h>
- #include <QBoxLayout>
- #include <QLabel>
- #include <QStackedWidget>
- #include <QDebug>
- ProjectView::ProjectView(ProjectInfo *proj, QWidget *parent) : QWidget(parent), m_proj(proj)
- {
- initWidgets();
- initLayout();
- connectSigalsAndSlots();
- if (m_tree->topLevelItemCount() > 0) {
- itemClicked(m_tree->topLevelItem(0), 0);
- }
- }
- void ProjectView::showEvent(QShowEvent *event)
- {
- QWidget::showEvent(event);
- }
- void ProjectView::hideEvent(QHideEvent *event)
- {
- QWidget::hideEvent(event);
- }
- ProjectInfo *ProjectView::proj() const
- {
- return m_proj;
- }
- void ProjectView::showEvalWidget(int eval, int task)
- {
- m_stack->setCurrentIndex(task);
- EvalWidget *w = (EvalWidget *)m_stack->widget(task);
- w->setType(eval);
- ProjectManager::EvalType type = (ProjectManager::EvalType)eval;
- qDebug() << __FUNCTION__ << __LINE__ << type;
- }
- void ProjectView::initWidgets()
- {
- m_title = new QLabel(this);
- m_title->setText(m_proj->projectName);
- QFont ft("Microsoft YaHei", 14);
- m_title->setFont(ft);
- m_close = new PushButton("关闭", this);
- m_close->setToolTip("关闭项目");
- m_tree = new TreeWidget(this);
- // 根据评估类型添加列表条目
- QList<ProjectManager::EvalType> types = ProjectManager::evalTypeList(*m_proj);
- for (int i = 0; i < types.count(); i++) {
- QString typeName = ProjectManager::nameOfEvalType(types[i]);
- QTreeWidgetItem *item = new QTreeWidgetItem({ typeName });
- Qt::ItemFlags f = item->flags() ^ Qt::ItemIsSelectable;
- item->setFlags(f); // 设置 topLevelItem 不可选中
- item->addChildren({ new QTreeWidgetItem({ "指标体系设计" }), new QTreeWidgetItem({ "评估方案规划" }),
- new QTreeWidgetItem({ "评估数据采集" }), new QTreeWidgetItem({ "评估数据处理" }) });
- m_tree->addTopLevelItem(item);
- }
- m_tree->expandAll();
- m_tree->setHeaderHidden(true);
- m_tree->setFixedWidth(200);
- // 分割线
- m_seperator = new QWidget(this);
- m_seperator->setFixedWidth(1);
- QPalette pal(m_seperator->palette());
- pal.setColor(QPalette::Background, QColor("#aaaaaa"));
- m_seperator->setAutoFillBackground(true);
- m_seperator->setPalette(pal);
- m_stack = new QStackedWidget(this);
- m_indexSystem = new IndexSystemWidget(m_proj, m_stack);
- m_schemeDesign = new SchemePlanWidget(m_proj, m_stack);
- m_dataCollection = new DataCollectionWidget(m_proj, m_stack);
- m_dataProcessing = new DataProcessingWidget(m_proj, m_stack);
- m_stack->addWidget(m_indexSystem);
- m_stack->addWidget(m_schemeDesign);
- m_stack->addWidget(m_dataCollection);
- m_stack->addWidget(m_dataProcessing);
- }
- void ProjectView::initLayout()
- {
- m_layout = new QVBoxLayout(this);
- m_headerLayout = new QHBoxLayout();
- m_layout->addLayout(m_headerLayout);
- m_contentLayout = new QHBoxLayout();
- m_layout->addLayout(m_contentLayout);
- m_headerLayout->addWidget(m_title);
- m_headerLayout->addSpacing(20);
- m_headerLayout->addWidget(m_close);
- m_headerLayout->addStretch();
- m_contentLayout->addWidget(m_tree);
- m_contentLayout->addWidget(m_seperator);
- m_contentLayout->addWidget(m_stack);
- }
- void ProjectView::connectSigalsAndSlots()
- {
- connect(m_close, &PushButton::clicked, this, &ProjectView::sigClose);
- connect(m_tree, &TreeWidget::itemClicked, this, &ProjectView::itemClicked);
- }
- void ProjectView::itemClicked(QTreeWidgetItem *item, int column)
- {
- Q_UNUSED(column)
- int typeIndex = m_tree->indexOfTopLevelItem(item); // 评估类型, 一级条目
- int taskIndex = -1; // 评估事项, 二级条目
- if (typeIndex < 0) {
- typeIndex = m_tree->indexOfTopLevelItem(item->parent());
- taskIndex = item->parent()->indexOfChild(item);
- }
- // 点击一级条目时, 选中其首个子条目
- if (taskIndex < 0) {
- taskIndex = 0;
- item->child(taskIndex)->setSelected(true);
- }
- ProjectManager::EvalType eval = ProjectManager::evalTypeList(*m_proj)[typeIndex];
- QString typeName = ProjectManager::nameOfEvalType(eval);
- showEvalWidget(eval, taskIndex);
- }
|