123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #include "ImportIndexWidget.h"
- #include <common/ProjectManager.h>
- #include <dbService/ClassSet.h>
- #include <dbService/CNodeDataService.h>
- #include <Widgets/Button.h>
- #include <QLabel>
- #include <QListWidget>
- #include <QBoxLayout>
- #include <QDebug>
- ImportIndexWidget::ImportIndexWidget(QWidget *parent) : QDialog(parent)
- {
- initWindow();
- initWidgets();
- initLayout();
- connectSignalsAndSlots();
- loadIndex();
- }
- void ImportIndexWidget::initWindow()
- {
- setWindowTitle("导入指标体系");
- // setWindowFlags(Qt::Window);
- // setWindowFlag(Qt::WindowMinMaxButtonsHint, false);
- setModal(true);
- setWindowFlags(Qt::Dialog);
- setWindowFlag(Qt::WindowContextHelpButtonHint, false);
- setFixedSize(400, 600);
- }
- void ImportIndexWidget::initWidgets()
- {
- m_title = new QLabel("选择已有项目的指标体系");
- m_tips = new QLabel("未找到指标体系!\n请重新创建");
- m_tips->setHidden(true);
- m_listWidget = new QListWidget();
- m_listWidget->setMinimumHeight(450);
- m_listWidget->setHidden(true);
- m_confirm = new PushButton("导入");
- m_cancel = new PushButton("取消");
- }
- void ImportIndexWidget::initLayout()
- {
- m_layout = new QVBoxLayout(this);
- m_layout->setMargin(20);
- m_layout->setAlignment(Qt::AlignTop);
- m_layout->addWidget(m_title);
- m_layout->addSpacing(10);
- m_layout->addWidget(m_tips);
- m_layout->addWidget(m_listWidget);
- m_layout->addSpacing(10);
- m_layout->addStretch();
- m_buttonLayout = new QHBoxLayout();
- m_layout->addLayout(m_buttonLayout);
- m_buttonLayout->addStretch();
- m_buttonLayout->addWidget(m_confirm);
- m_buttonLayout->addSpacing(10);
- m_buttonLayout->addWidget(m_cancel);
- }
- void ImportIndexWidget::connectSignalsAndSlots()
- {
- connect(m_confirm, &PushButton::clicked, this, &ImportIndexWidget::slotConfirm);
- connect(m_cancel, &PushButton::clicked, this, &ImportIndexWidget::slotCancel);
- connect(m_listWidget, &QListWidget::itemSelectionChanged, this, &ImportIndexWidget::slotCurrentChanged);
- }
- void ImportIndexWidget::showEvent(QShowEvent *)
- {
- loadIndex();
- }
- void ImportIndexWidget::loadIndex()
- {
- QList<ProjectInfo *> list;
- bool ret = ProjectManager::queryProjects(&list);
- bool hasProj = ret && list.size() > 0;
- m_tips->setHidden(hasProj);
- m_listWidget->setHidden(!hasProj);
- m_indexSysList.clear();
- for (ProjectInfo *proj : list) {
- QList<ProjectManager::IndexType> indexList = ProjectManager::indexList(*proj);
- for (ProjectManager::IndexType i : indexList) {
- QList<CNodeData> nodeList;
- bool indexRet = CNodeDataService().QueryAll(nodeList, proj->id, i);
- if (indexRet && nodeList.size() > 0) {
- IndexSystemInfo info = IndexSystemInfo { proj->id, i, proj->projectName };
- m_indexSysList.append(info);
- }
- }
- }
- showIndex();
- }
- void ImportIndexWidget::showIndex()
- {
- m_listWidget->clear();
- m_confirm->setEnabled(false);
- for (IndexSystemInfo info : m_indexSysList) {
- QListWidgetItem *item = new QListWidgetItem();
- QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)info.indexType);
- item->setText(info.projName + "-" + indexName);
- m_listWidget->addItem(item);
- }
- }
- void ImportIndexWidget::slotConfirm()
- {
- IndexSystemInfo info = m_indexSysList[m_listWidget->currentRow()];
- emit sigImport(info.projId, info.indexType);
- }
- void ImportIndexWidget::slotCancel()
- {
- close();
- }
- void ImportIndexWidget::slotCurrentChanged()
- {
- m_confirm->setEnabled(m_indexSysList.size() > 0 && m_listWidget->selectedItems().size() >= 0);
- }
|