#include "ConfigMeasureDataWidget.h" #include "ProjectManager.h" #include "common/QFDIcon.h" #include "dbService/SchemeInfoService.h" #include "dbService/NodeMatrixService.h" #include #include #include #include #include #include ConfigMeasureDataWidget::ConfigMeasureDataWidget(QWidget *parent) : QWidget(parent) { initWidget(); initLayout(); connectSignalsAndSlots(); } void ConfigMeasureDataWidget::setProcess(SchemePlanManager::SchemeProcessInfo process) { m_process = process; reloadData(); } void ConfigMeasureDataWidget::reloadData() { /// 从数据库拉取数据 m_nodeData.clear(); m_uuidList.clear(); m_listWidget->clear(); QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)m_process.indexType); QList dataList; bool ret = NodeMatrixService().QueryMeaureDataByProjectAndIndex(&dataList, indexName, m_process.projectId); if (ret == false) { return; } /// 使用 uuid 整理数据 for (NodeMatrixInfo *info : dataList) { if (m_uuidList.contains(info->strUuid) == false) { m_uuidList.append(info->strUuid); m_nodeData[info->strUuid] = QList(); } m_nodeData[info->strUuid].append(info); } refreshList(); } void ConfigMeasureDataWidget::selectFirst() { if (m_listWidget->count() <= 0) { return; } m_listWidget->setCurrentRow(0); } void ConfigMeasureDataWidget::selectLast() { if (m_listWidget->count() <= 0) { return; } m_listWidget->setCurrentRow(m_listWidget->count() - 1); } QList ConfigMeasureDataWidget::selectedData() { int row = m_listWidget->currentRow(); if (m_uuidList.size() <= 0 || row < 0 || row >= m_uuidList.size()) { QList list; return list; } return m_nodeData[m_uuidList[row]]; } void ConfigMeasureDataWidget::updateNodeValue(NodeMatrixInfo *node) { for (auto key : m_nodeData.keys()) { for (int i = 0; i < m_nodeData[key].size(); i++) { NodeMatrixInfo *exist = m_nodeData[key][i]; if (exist->strUuid == node->strUuid && exist->abscissa == node->abscissa) { if (exist->ordinate.length() > 0 && exist->ordinate != node->ordinate) { continue; } m_nodeData[key][i]->nodeValue = node->nodeValue; return; } } } } void ConfigMeasureDataWidget::initWidget() { m_titleLabel = new QLabel("添加实测数据", this); m_titleLabel->setObjectName("titleLabel"); m_titleLabel->setFixedHeight(50); m_titleLabel->setContentsMargins(10, 0, 0, 0); m_listTitleLabel = new QLabel("数据列表", this); m_listTitleLabel->setObjectName("listTitleLabel"); m_tipsLabel = new QLabel("已导入的数据将会显示在这里", this); m_tipsLabel->setObjectName("tipsLabel"); m_tipsLabel->setHidden(true); m_addButton = new QPushButton(NEWFLICON(FluentIcon, ADD)->icon(), "", this); m_addButton->setToolTip("添加数据"); m_listWidget = new QListWidget(this); setStyleSheet("#titleLabel {color:#333333; font-size:16px}" "#listTitleLabel {color:#333333; font-size:12px}" "QPushButton {border: 0;background-color: qlineargradient(x1: 0, y1: 0, x2: " "0, y2: 1,stop: 0 #f8f8f8, stop: 1 #f8f8f8);}" "QPushButton::hover {border: 1px solid rgba(0, 0, 0, 0.073);}" "QPushButton::pressed {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, " "stop: 1 #f6f7fa);}" "QListWidget {border: 1px solid rgba(0, 0, 0, 0.073);}" "QListView::item {height:44;}"); } void ConfigMeasureDataWidget::initLayout() { m_layout = new QVBoxLayout(this); m_layout->setMargin(0); m_layout->setSpacing(0); m_layout->addWidget(m_titleLabel); m_headerLayout = new QHBoxLayout(); m_layout->addLayout(m_headerLayout); m_layout->addSpacing(10); m_layout->addWidget(m_tipsLabel); m_layout->addWidget(m_listWidget); m_headerLayout->addWidget(m_listTitleLabel); m_headerLayout->addStretch(); m_headerLayout->addWidget(m_addButton); } void ConfigMeasureDataWidget::connectSignalsAndSlots() { connect(m_addButton, &PushButton::clicked, this, &ConfigMeasureDataWidget::slotAddDataClicked); connect(m_listWidget, &QListWidget::itemSelectionChanged, this, &ConfigMeasureDataWidget::slotCurrentRowChanged); } void ConfigMeasureDataWidget::refreshList() { m_listWidget->clear(); for (int i = 0; i < m_uuidList.size(); i++) { QLabel *title = new QLabel; title->setText(QString("数据%1").arg(i + 1)); QPushButton *remove = new QPushButton(NEWFLICON(QFDIcon, Minus)->icon(), "", this); remove->setFixedSize(QSize(25, 25)); remove->setIconSize(QSize(10, 10)); remove->setToolTip("删除"); connect(remove, &QPushButton::clicked, [this, i](int) { slotRemoveDataClicked(i); }); QWidget *w = new QWidget; QHBoxLayout *lay = new QHBoxLayout(w); lay->addWidget(title); lay->addStretch(); lay->addWidget(remove); QListWidgetItem *item = new QListWidgetItem; m_listWidget->addItem(item); m_listWidget->setItemWidget(item, w); } } void ConfigMeasureDataWidget::slotAddDataClicked() { emit sigAddData(); } void ConfigMeasureDataWidget::slotRemoveDataClicked(int index) { QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)m_process.indexType); QString uuid = m_uuidList[index]; bool ret = NodeMatrixService().deleteMeasureData(m_process.projectId, indexName, uuid); if (ret) { m_uuidList.removeOne(uuid); m_nodeData.remove(uuid); refreshList(); if (m_uuidList.size() > 0) { selectFirst(); } } } void ConfigMeasureDataWidget::slotCurrentRowChanged() { emit sigCurrentRowChanged(); }