ImportIndexWidget.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "ImportIndexWidget.h"
  2. #include <common/ProjectManager.h>
  3. #include <dbService/ClassSet.h>
  4. #include <dbService/CNodeDataService.h>
  5. #include <Widgets/Button.h>
  6. #include <QLabel>
  7. #include <QListWidget>
  8. #include <QBoxLayout>
  9. #include <QDebug>
  10. ImportIndexWidget::ImportIndexWidget(QWidget *parent) : QDialog(parent)
  11. {
  12. initWindow();
  13. initWidgets();
  14. initLayout();
  15. connectSignalsAndSlots();
  16. loadIndex();
  17. }
  18. void ImportIndexWidget::initWindow()
  19. {
  20. setWindowTitle("导入指标体系");
  21. // setWindowFlags(Qt::Window);
  22. // setWindowFlag(Qt::WindowMinMaxButtonsHint, false);
  23. setModal(true);
  24. setWindowFlags(Qt::Dialog);
  25. setWindowFlag(Qt::WindowContextHelpButtonHint, false);
  26. setFixedSize(400, 600);
  27. }
  28. void ImportIndexWidget::initWidgets()
  29. {
  30. m_title = new QLabel("选择已有项目的指标体系");
  31. m_tips = new QLabel("未找到指标体系!\n请重新创建");
  32. m_tips->setHidden(true);
  33. m_listWidget = new QListWidget();
  34. m_listWidget->setMinimumHeight(450);
  35. m_listWidget->setHidden(true);
  36. m_confirm = new PushButton("导入");
  37. m_cancel = new PushButton("取消");
  38. }
  39. void ImportIndexWidget::initLayout()
  40. {
  41. m_layout = new QVBoxLayout(this);
  42. m_layout->setMargin(20);
  43. m_layout->setAlignment(Qt::AlignTop);
  44. m_layout->addWidget(m_title);
  45. m_layout->addSpacing(10);
  46. m_layout->addWidget(m_tips);
  47. m_layout->addWidget(m_listWidget);
  48. m_layout->addSpacing(10);
  49. m_layout->addStretch();
  50. m_buttonLayout = new QHBoxLayout();
  51. m_layout->addLayout(m_buttonLayout);
  52. m_buttonLayout->addStretch();
  53. m_buttonLayout->addWidget(m_confirm);
  54. m_buttonLayout->addSpacing(10);
  55. m_buttonLayout->addWidget(m_cancel);
  56. }
  57. void ImportIndexWidget::connectSignalsAndSlots()
  58. {
  59. connect(m_confirm, &PushButton::clicked, this, &ImportIndexWidget::slotConfirm);
  60. connect(m_cancel, &PushButton::clicked, this, &ImportIndexWidget::slotCancel);
  61. connect(m_listWidget, &QListWidget::itemSelectionChanged, this, &ImportIndexWidget::slotCurrentChanged);
  62. }
  63. void ImportIndexWidget::showEvent(QShowEvent *)
  64. {
  65. loadIndex();
  66. }
  67. void ImportIndexWidget::loadIndex()
  68. {
  69. QList<ProjectInfo *> list;
  70. bool ret = ProjectManager::queryProjects(&list);
  71. bool hasProj = ret && list.size() > 0;
  72. m_tips->setHidden(hasProj);
  73. m_listWidget->setHidden(!hasProj);
  74. m_indexSysList.clear();
  75. for (ProjectInfo *proj : list) {
  76. QList<ProjectManager::IndexType> indexList = ProjectManager::indexList(*proj);
  77. for (ProjectManager::IndexType i : indexList) {
  78. QList<CNodeData> nodeList;
  79. bool indexRet = CNodeDataService().QueryAll(nodeList, proj->id, i);
  80. if (indexRet && nodeList.size() > 0) {
  81. IndexSystemInfo info = IndexSystemInfo { proj->id, i, proj->projectName };
  82. m_indexSysList.append(info);
  83. }
  84. }
  85. }
  86. showIndex();
  87. }
  88. void ImportIndexWidget::showIndex()
  89. {
  90. m_listWidget->clear();
  91. m_confirm->setEnabled(false);
  92. for (IndexSystemInfo info : m_indexSysList) {
  93. QListWidgetItem *item = new QListWidgetItem();
  94. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)info.indexType);
  95. item->setText(info.projName + "-" + indexName);
  96. m_listWidget->addItem(item);
  97. }
  98. }
  99. void ImportIndexWidget::slotConfirm()
  100. {
  101. IndexSystemInfo info = m_indexSysList[m_listWidget->currentRow()];
  102. emit sigImport(info.projId, info.indexType);
  103. }
  104. void ImportIndexWidget::slotCancel()
  105. {
  106. close();
  107. }
  108. void ImportIndexWidget::slotCurrentChanged()
  109. {
  110. m_confirm->setEnabled(m_indexSysList.size() > 0 && m_listWidget->selectedItems().size() >= 0);
  111. }