#include "ProjectStateWidget.h" #include "common/ProjectManager.h" #include #include #include #include #include #include #include ProjectStateWidget::ProjectStateWidget(QWidget *parent) : QWidget(parent) { initialize(); initLayout(); } void ProjectStateWidget::showProjects(const QList &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列 ProjectInfo *proj = proList[i]; qDebug() << proj->projectName; QTableWidgetItem *item = new QTableWidgetItem(proj->projectName); setItem(row, 0, item, color); QList typeList = ProjectManager::evalTypeList(*proj); if (typeList.count() > 1) { m_projTableWidget->setSpan(row, 0, typeList.count(), 1); } // 指标体系,第1列 for (int j = 0; j < typeList.count(); j++) { ProjectManager::EvalType indexType = typeList[j]; QString typeName = ProjectManager::nameOfEvalType(indexType); QTableWidgetItem *item = new QTableWidgetItem(typeName); setItem(row + j, 1, item, color); } row += typeList.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(const QList &list) { int count = 0; for (ProjectInfo *proj : list) { count += ProjectManager::evalTypeList(*proj).count(); } m_projTableWidget->setRowCount(count); } void ProjectStateWidget::setItem(int row, int column, QTableWidgetItem *item, const 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); }