ProjectStateWidget.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "ProjectStateWidget.h"
  2. #include "common/ProjectManager.h"
  3. #include <dbService/ClassSet.h>
  4. #include <QTableWidget>
  5. #include <QHeaderView>
  6. #include <QBoxLayout>
  7. #include <QDateTime>
  8. #include <math.h>
  9. #include <QDebug>
  10. ProjectStateWidget::ProjectStateWidget(QWidget *parent) : QWidget(parent)
  11. {
  12. initialize();
  13. initLayout();
  14. }
  15. void ProjectStateWidget::showProjects(const QList<ProjectInfo *> &proList)
  16. {
  17. m_projTableWidget->clearContents();
  18. m_projTableWidget->clearSpans();
  19. setRowCount(proList);
  20. int row = 0;
  21. for (int i = 0; i < proList.count(); i++) {
  22. QColor color = i % 2 ? QColor(238, 238, 255) : QColor(255, 255, 255);
  23. // 工程名,第0列
  24. ProjectInfo *proj = proList[i];
  25. qDebug() << proj->projectName;
  26. QTableWidgetItem *item = new QTableWidgetItem(proj->projectName);
  27. setItem(row, 0, item, color);
  28. QList<ProjectManager::EvalType> typeList = ProjectManager::evalTypeList(*proj);
  29. if (typeList.count() > 1) {
  30. m_projTableWidget->setSpan(row, 0, typeList.count(), 1);
  31. }
  32. // 指标体系,第1列
  33. for (int j = 0; j < typeList.count(); j++) {
  34. ProjectManager::EvalType indexType = typeList[j];
  35. QString typeName = ProjectManager::nameOfEvalType(indexType);
  36. QTableWidgetItem *item = new QTableWidgetItem(typeName);
  37. setItem(row + j, 1, item, color);
  38. }
  39. row += typeList.count();
  40. }
  41. }
  42. void ProjectStateWidget::initialize()
  43. {
  44. m_vBoxLayout = new QVBoxLayout(this);
  45. m_projTableWidget = new QTableWidget(this);
  46. m_projTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
  47. m_projTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
  48. m_projTableWidget->setSelectionMode(QAbstractItemView::NoSelection);
  49. m_projTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
  50. m_projTableWidget->verticalHeader()->setVisible(false);
  51. const QStringList headers = { "项目名", "项目类型" };
  52. m_projTableWidget->setColumnCount(headers.count());
  53. m_projTableWidget->setHorizontalHeaderLabels(headers);
  54. // m_projTableWidget->setAlternatingRowColors(true);
  55. m_projTableWidget->setStyleSheet(
  56. "QTableWidget {border: 1px solid rgba(0, 0, 0, 0.073);background: rgb(244, 244, "
  57. "255);alternate-background-color: rgb(255, 255, 255);}"
  58. // "QTableWidget::item{border:1px outset red;}"
  59. // "QHeaderView::section{font-size: 14px;font:bold;font-family: 'Microsoft YaHei UI';}"
  60. "QHeaderView::section {"
  61. "background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,"
  62. "stop:0 #616161, stop: 0.5 #505050,"
  63. "stop: 0.6 #434343, stop:1 #656565);"
  64. "color: white;"
  65. "padding-left: 4px;"
  66. "border: 1px solid #6c6c6c;"
  67. "}");
  68. }
  69. void ProjectStateWidget::initLayout()
  70. {
  71. layout()->addWidget(m_projTableWidget);
  72. }
  73. void ProjectStateWidget::setRowCount(const QList<ProjectInfo *> &list)
  74. {
  75. int count = 0;
  76. for (ProjectInfo *proj : list) {
  77. count += ProjectManager::evalTypeList(*proj).count();
  78. }
  79. m_projTableWidget->setRowCount(count);
  80. }
  81. void ProjectStateWidget::setItem(int row, int column, QTableWidgetItem *item, const QColor &bgColor)
  82. {
  83. item->setBackgroundColor(bgColor);
  84. item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
  85. item->setTextAlignment(Qt::AlignCenter);
  86. m_projTableWidget->setItem(row, column, item);
  87. m_projTableWidget->setRowHeight(row, 50);
  88. }