123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #include "ConfigMeasureDataWidget.h"
- #include "ProjectManager.h"
- #include "common/QFDIcon.h"
- #include "dbService/SchemeInfoService.h"
- #include "dbService/NodeMatrixService.h"
- #include <Widgets/Button.h>
- #include <Common/Icon.h>
- #include <QLabel>
- #include <QListWidget>
- #include <QBoxLayout>
- #include <QDebug>
- 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<NodeMatrixInfo *> 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<NodeMatrixInfo *>();
- }
- 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<NodeMatrixInfo *> ConfigMeasureDataWidget::selectedData()
- {
- int row = m_listWidget->currentRow();
- if (m_uuidList.size() <= 0 || row < 0 || row >= m_uuidList.size()) {
- QList<NodeMatrixInfo *> 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();
- }
|