Browse Source

删除数据

chengxr 1 năm trước cách đây
mục cha
commit
df848a9a36

+ 15 - 0
QFD/dbService/NodeMatrixService.cpp

@@ -640,6 +640,21 @@ bool NodeMatrixService::UpdateMeasureData(const NodeMatrixInfo &info)
     return ret;
 }
 
+bool NodeMatrixService::deleteMeasureData(int projId, QString index, QString uuid)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        t.deleteFrom("t_node_matrix_info")
+                .where("engineer_id = ? and table_msg = ? and str_uuid = ?", projId, index, uuid);
+        t.commit();
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
 bool NodeMatrixService::hasMeasureData(int projId, QString index)
 {
     QSqlDatabase db = SqlDBHelper::getDatabase();

+ 3 - 0
QFD/dbService/NodeMatrixService.h

@@ -71,6 +71,9 @@ public:
     /*修改节点值*/
     bool UpdateMeasureData(const NodeMatrixInfo &info);
 
+    /*删除实测数据*/
+    bool deleteMeasureData(int projId, QString index, QString uuid);
+
     /*查询是否已录入数据*/
     bool hasMeasureData(int projId, QString index);
     bool hasExpertData(int projId, QString index, int expertId);

+ 7 - 6
QFD/widgets/ConfigExpertDataWidget.cpp

@@ -194,6 +194,8 @@ void ConfigExpertDataWidget::loadNodeData()
         }
         m_nodeData[info->expertId].append(info);
     }
+    qDebug() << __FUNCTION__ << __LINE__ << m_nodeData.keys() << endl;
+
     refreshConfigList();
 }
 
@@ -222,13 +224,12 @@ void ConfigExpertDataWidget::selectConfig(UserConfig *config)
 QList<NodeMatrixInfo *> ConfigExpertDataWidget::selectedData()
 {
     QList<NodeMatrixInfo *> list;
-    if (m_nodeData.size() <= 0) {
-        return list;
-    }
 
-    int row     = m_configListWidget->currentRow();
-    QString key = QString("%1").arg(m_configList[row]->userId);
-    list        = m_nodeData[key];
+    int row = m_configListWidget->currentRow();
+    if (row >= 0 && row < m_configList.count()) {
+        QString key = QString("%1").arg(m_configList[row]->userId);
+        list        = m_nodeData[key];
+    }
 
     return list;
 }

+ 35 - 3
QFD/widgets/ConfigMeasureDataWidget.cpp

@@ -1,6 +1,7 @@
 #include "ConfigMeasureDataWidget.h"
 
 #include "ProjectManager.h"
+#include "common/QFDIcon.h"
 
 #include "dbService/SchemeInfoService.h"
 #include "dbService/NodeMatrixService.h"
@@ -73,12 +74,12 @@ void ConfigMeasureDataWidget::selectLast()
 
 QList<NodeMatrixInfo *> ConfigMeasureDataWidget::selectedData()
 {
-    if (m_uuidList.size() <= 0) {
+    int row = m_listWidget->currentRow();
+    if (m_uuidList.size() <= 0 || row < 0 || row >= m_uuidList.size()) {
         QList<NodeMatrixInfo *> list;
         return list;
     }
 
-    int row = m_listWidget->currentRow();
     return m_nodeData[m_uuidList[row]];
 }
 
@@ -152,9 +153,24 @@ 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;
-        item->setText(QString("数据%1").arg(i + 1));
         m_listWidget->addItem(item);
+        m_listWidget->setItemWidget(item, w);
     }
 }
 
@@ -183,6 +199,22 @@ 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();

+ 1 - 0
QFD/widgets/ConfigMeasureDataWidget.h

@@ -49,6 +49,7 @@ private:
 
 private slots:
     void slotAddDataClicked();
+    void slotRemoveDataClicked(int index);
     void slotCurrentRowChanged();
 
 private: