123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- #include "ProjectStateWidget.h"
- #include <dbService/ClassSet.h>
- #include <QTableWidget>
- #include <QHeaderView>
- #include <QBoxLayout>
- #include <QDateTime>
- #include <math.h>
- #include <QDebug>
- int ProjectStateWidget::rowCount(EngineerInfo *proj)
- {
- int expertCount = proj->configs.count();
- int rowProj = std::max(proj->indexList().count(), proj->indexList().count() * expertCount);
- return rowProj;
- }
- ProjectStateWidget::ProjectStateWidget(QWidget *parent) : QWidget(parent)
- {
- initialize();
- initLayout();
- }
- void ProjectStateWidget::showProjects(QList<EngineerInfo *> proList)
- {
- m_projTableWidget->clearContents();
- m_projTableWidget->clearSpans();
- setRowCount(proList);
- int row = 0;
- for (int i = 0; i < proList.count(); i++) {
- QColor color = i % 2 ? QColor(238, 238, 255) : QColor(255, 255, 255);
- // 工程名,第0列
- EngineerInfo *proj = proList[i];
- QTableWidgetItem *item = new QTableWidgetItem(proj->engineerName);
- setItem(row, 0, item, color);
- int rowProj = rowCount(proj);
- if (rowProj > 1) {
- m_projTableWidget->setSpan(row, 0, rowProj, 1);
- }
- // 指标体系,第1列
- for (int j = 0; j < proj->indexList().count(); j++) {
- EngineerInfo::IndexType indexType = proj->indexList()[j];
- QString indexName = EngineerInfo::nameOFIndexType(indexType);
- QTableWidgetItem *item = new QTableWidgetItem(indexName);
- setItem(row, 1, item, color);
- if (proj->configs.count() > 1) {
- m_projTableWidget->setSpan(row, 1, proj->configs.count(), 1);
- }
- // 专家数据,第2、3列
- // 未配置专家时,添加一个空的专家配置来填充表格
- QList<UserConfig *> configs = proj->configs;
- if (configs.count() <= 0) {
- configs.append(new UserConfig());
- }
- for (int k = 0; k < configs.count(); k++) {
- UserConfig *config = configs[k];
- QTableWidgetItem *expItem = new QTableWidgetItem(config->id >= 0 ? config->userName : "无");
- setItem(row + k, 2, expItem, color);
- unsigned seed = QDateTime::currentDateTime().toTime_t() + pow(row + k, 4);
- srand(seed);
- bool loaded = (rand() % 4) == 0;
- QTableWidgetItem *loadItem = new QTableWidgetItem(loaded && config->id >= 0 ? "已录入" : "未录入");
- setItem(row + k, 3, loadItem, color);
- }
- row += configs.count();
- }
- }
- }
- void ProjectStateWidget::initialize()
- {
- m_vBoxLayout = new QVBoxLayout(this);
- m_projTableWidget = new QTableWidget(this);
- m_projTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
- m_projTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
- m_projTableWidget->setSelectionMode(QAbstractItemView::NoSelection);
- m_projTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
- m_projTableWidget->verticalHeader()->setVisible(false);
- const QStringList headers = { "工程名", "工程类型", "专家信息", "评估状态" };
- m_projTableWidget->setColumnCount(headers.count());
- m_projTableWidget->setHorizontalHeaderLabels(headers);
- // m_projTableWidget->setAlternatingRowColors(true);
- m_projTableWidget->setStyleSheet(
- "QTableWidget {border: 1px solid rgba(0, 0, 0, 0.073);background: rgb(244, 244, "
- "255);alternate-background-color: rgb(255, 255, 255);}"
- // "QTableWidget::item{border:1px outset red;}"
- // "QHeaderView::section{font-size: 14px;font:bold;font-family: 'Microsoft YaHei UI';}"
- "QHeaderView::section {"
- "background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,"
- "stop:0 #616161, stop: 0.5 #505050,"
- "stop: 0.6 #434343, stop:1 #656565);"
- "color: white;"
- "padding-left: 4px;"
- "border: 1px solid #6c6c6c;"
- "}");
- }
- void ProjectStateWidget::initLayout()
- {
- layout()->addWidget(m_projTableWidget);
- }
- void ProjectStateWidget::setRowCount(QList<EngineerInfo *> list)
- {
- int count = 0;
- for (EngineerInfo *proj : list) {
- int rowProj = rowCount(proj);
- count += rowProj;
- }
- m_projTableWidget->setRowCount(count);
- }
- void ProjectStateWidget::setItem(int row, int column, QTableWidgetItem *item, QColor bgColor)
- {
- item->setBackgroundColor(bgColor);
- item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
- item->setTextAlignment(Qt::AlignCenter);
- m_projTableWidget->setItem(row, column, item);
- m_projTableWidget->setRowHeight(row, 50);
- }
|