123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- #include "EXProjectView.h"
- #include "EXIndexView.h"
- #include "EXDataView.h"
- #include "ProjectManager.h"
- #include <dbService/ClassSet.h>
- #include <common/QFDIcon.h>
- #include <Widgets/Button.h>
- #include <Widgets/LineEdit.h>
- #include <Widgets/TreeView.h>
- #include <QBoxLayout>
- #include <QLabel>
- #include <QStackedWidget>
- #include <QPushButton>
- #include <QDebug>
- EXProjectView::EXProjectView(ProjectInfo *proj, QWidget *parent) : QWidget(parent), m_proj(proj)
- {
- initWidgets();
- initLayout();
- connectSigalsAndSlots();
- if (m_tree->topLevelItemCount() > 0) {
- itemClicked(m_tree->topLevelItem(0), 0);
- }
- }
- void EXProjectView::showEvent(QShowEvent *event)
- {
- QWidget::showEvent(event);
- }
- void EXProjectView::hideEvent(QHideEvent *event)
- {
- QWidget::hideEvent(event);
- }
- ProjectInfo *EXProjectView::proj() const
- {
- return m_proj;
- }
- void EXProjectView::showEvalWidget(int eval, int task)
- {
- m_stack->setCurrentIndex(task);
- m_export->setVisible(task == 1);
- EXEvalView *w = (EXEvalView *)m_stack->widget(task);
- w->setType(eval);
- ProjectManager::EvalType type = (ProjectManager::EvalType)eval;
- qDebug() << __FUNCTION__ << __LINE__ << type;
- }
- void EXProjectView::initWidgets()
- {
- m_title = new QLabel(this);
- m_title->setText(m_proj->projectName);
- QFont ft("Microsoft YaHei", 14);
- m_title->setFont(ft);
- 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({ "数据采集" }) });
- 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 EXIndexView(m_proj, m_stack);
- m_dataCollection = new EXDataView(m_proj, m_stack);
- m_stack->addWidget(m_indexSystem);
- m_stack->addWidget(m_dataCollection);
- m_export = new PushButton("导出", this);
- m_user = new PushButton("user");
- m_user->setHidden(true);
- }
- void EXProjectView::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->addStretch();
- m_headerLayout->addWidget(m_export);
- m_headerLayout->addWidget(m_user);
- m_contentLayout->addWidget(m_tree);
- m_contentLayout->addWidget(m_seperator);
- m_contentLayout->addWidget(m_stack);
- }
- void EXProjectView::connectSigalsAndSlots()
- {
- connect(m_tree, &TreeWidget::itemClicked, this, &EXProjectView::itemClicked);
- connect(m_export, &PushButton::clicked, m_dataCollection, &EXDataView::slotExportData);
- connect(m_dataCollection, &EXDataView::signalCompleteStateChanged, this, &EXProjectView::slotCompleteStateChanged);
- }
- void EXProjectView::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);
- }
- void EXProjectView::slotCompleteStateChanged(bool complete)
- {
- m_export->setEnabled(complete);
- m_export->setToolTip(complete ? "导出评估数据" : "请将该评估类型的数据补充完整后再导出");
- }
|