Преглед на файлове

物元分析法支持闭区间。

Ulric преди 3 седмици
родител
ревизия
af44049d4d

+ 45 - 24
QFD/widgets/MatterElementConfigWidget.cpp

@@ -194,6 +194,8 @@ void MatterElementConfigWidget::initConfigItems()
             d.name        = sub.name;
             d.leftValues  = QVector<double>(m_domainLevel + 1, 0);
             d.rightValues = QVector<double>(m_domainLevel + 1, 0);
+            d.leftCloses  = QVector<bool>(m_domainLevel + 1, false);
+            d.rightCloses = QVector<bool>(m_domainLevel + 1, false);
             children.append(d);
         }
         MEConfigItem i;
@@ -217,9 +219,11 @@ void MatterElementConfigWidget::initConfigItems()
                         gii.gradeIndexName  = configItem.childs.at(c).name;
                         gii.gradeParentName = configItem.parentName;
                         gii.gradeLevel      = domain + 1;
-                        gii.gradeIndexValue = QString("(%1, %2)")
+                        gii.gradeIndexValue = QString("%1%2, %3%4")
+                                                      .arg(configItem.childs.at(c).leftCloses.at(domain) ? "[" : "(")
                                                       .arg(configItem.childs.at(c).leftValues.at(domain))
-                                                      .arg(configItem.childs.at(c).rightValues.at(domain));
+                                                      .arg(configItem.childs.at(c).rightValues.at(domain))
+                                                      .arg(configItem.childs.at(c).rightCloses.at(domain) ? "]" : ")");
                         if (!GradeIndexInfoService().AddGradeIndexInfo(gii)) {
                             QMessageBox::warning(this, "警告", "数据库访问失败");
                         }
@@ -235,11 +239,13 @@ void MatterElementConfigWidget::initConfigItems()
                             // 默认指标名具有唯一性
                             if (gindex->gradeIndexName == configItem.childs[c].name
                                 && gindex->gradeLevel == domain + 1) {
-                                QStringList list = gindex->gradeIndexValue.mid(1, gindex->gradeIndexValue.size() - 2)
-                                                           .replace(" ", "")
-                                                           .split(",");
+                                QString indexValue = gindex->gradeIndexValue.trimmed();
+                                QStringList list = indexValue.mid(1, indexValue.size() - 2).replace(" ", "").split(",");
+
                                 configItem.childs[c].leftValues[domain]  = list.at(0).toDouble();
                                 configItem.childs[c].rightValues[domain] = list.at(1).toDouble();
+                                configItem.childs[c].leftCloses[domain]  = indexValue[0] == "[";
+                                configItem.childs[c].rightCloses[domain] = indexValue.right(1) == "]";
                                 found                                    = true;
                             }
                         }
@@ -252,9 +258,12 @@ void MatterElementConfigWidget::initConfigItems()
                             gii.gradeIndexName  = configItem.childs[c].name;
                             gii.gradeParentName = configItem.parentName;
                             gii.gradeLevel      = domain + 1;
-                            gii.gradeIndexValue = QString("(%1, %2)")
-                                                          .arg(configItem.childs[c].leftValues.at(domain))
-                                                          .arg(configItem.childs[c].rightValues.at(domain));
+                            gii.gradeIndexValue =
+                                    QString("%1%2, %3%4")
+                                            .arg(configItem.childs.at(c).leftCloses.at(domain) ? "[" : "(")
+                                            .arg(configItem.childs.at(c).leftValues.at(domain))
+                                            .arg(configItem.childs.at(c).rightValues.at(domain))
+                                            .arg(configItem.childs.at(c).rightCloses.at(domain) ? "]" : ")");
                             if (!GradeIndexInfoService().AddGradeIndexInfo(gii)) {
                                 QMessageBox::warning(this, "警告", "数据库访问失败");
                             }
@@ -347,9 +356,11 @@ void MatterElementConfigWidget::initDomainTable()
                 s->setTextAlignment(Qt::AlignCenter);
 
                 if (r < m_domainLevel) {
-                    s->setText(QString("(%1, %2)")
+                    s->setText(QString("%1%2, %3%4")
+                                       .arg(m_allConfigItems[pindex].childs[k].leftCloses[r] ? "[" : "(")
                                        .arg(m_allConfigItems[pindex].childs[k].leftValues[r])
-                                       .arg(m_allConfigItems[pindex].childs[k].rightValues[r]));
+                                       .arg(m_allConfigItems[pindex].childs[k].rightValues[r])
+                                       .arg(m_allConfigItems[pindex].childs[k].rightCloses[r] ? "]" : ")"));
                     tModel->setItem(k, r * 4 + 3, s);
                 }
             }
@@ -494,10 +505,12 @@ void MatterElementConfigWidget::onSaveBtnClick()
         int indexNumber = m_allConfigItems.at(pindex).childs.size();
         for (int r = 0; r < m_domainLevel + 1; ++r) {
             for (int k = 0; k < indexNumber; ++k) {
-                QString txt      = tModel->item(k, r * 4 + 3)->text().trimmed();
-                QStringList list = txt.mid(1, txt.size() - 2).replace(" ", "").split(",");
+                QString itemTxt  = tModel->item(k, r * 4 + 3)->text();
+                QStringList list = itemTxt.mid(1, itemTxt.size() - 2).replace(" ", "").split(",");
                 m_allConfigItems[pindex].childs[k].leftValues[r]  = list.at(0).toDouble();
                 m_allConfigItems[pindex].childs[k].rightValues[r] = list.at(1).toDouble();
+                m_allConfigItems[pindex].childs[k].leftCloses[r]  = itemTxt[0] == "[";
+                m_allConfigItems[pindex].childs[k].rightCloses[r] = itemTxt.right(1) == "]";
                 qDebug() << r << k << list;
             }
         }
@@ -517,9 +530,12 @@ void MatterElementConfigWidget::onSaveBtnClick()
                         gii.gradeIndexName  = configItem.childs[c].name;
                         gii.gradeParentName = configItem.parentName;
                         gii.gradeLevel      = domain + 1;
-                        gii.gradeIndexValue = QString("(%1, %2)")
+                        gii.gradeIndexValue = QString("%1%2, %3%4")
+                                                      .arg(configItem.childs[c].leftCloses.at(domain) ? "[" : "(")
                                                       .arg(configItem.childs[c].leftValues.at(domain))
-                                                      .arg(configItem.childs[c].rightValues.at(domain));
+                                                      .arg(configItem.childs[c].rightValues.at(domain))
+                                                      .arg(configItem.childs[c].rightCloses.at(domain) ? "]" : ")");
+
                         if (!GradeIndexInfoService().AddGradeIndexInfo(gii)) {
                             QMessageBox::warning(this, "警告", "数据库访问失败");
                         }
@@ -530,17 +546,19 @@ void MatterElementConfigWidget::onSaveBtnClick()
             for (const auto &configItem : m_allConfigItems) {
                 for (int c = 0; c < configItem.childs.size(); c++) {
                     bool found = false;
+
                     for (auto &gindex : gradeIndexInfoList) {
                         for (int domain = 0; domain < m_domainLevel + 1; ++domain) {
                             if ((gindex->gradeIndexName == configItem.childs[c].name)
                                 && (gindex->gradeLevel == domain + 1)) {
-                                if (gindex->gradeIndexValue
-                                    != QString("(%1, %2)")
-                                               .arg(configItem.childs[c].leftValues.at(domain))
-                                               .arg(configItem.childs[c].rightValues.at(domain))) {
-                                    gindex->gradeIndexValue = QString("(%1, %2)")
-                                                                      .arg(configItem.childs[c].leftValues.at(domain))
-                                                                      .arg(configItem.childs[c].rightValues.at(domain));
+                                QString indexValue =
+                                        QString("%1%2, %3%4")
+                                                .arg(configItem.childs[c].leftCloses.at(domain) ? "[" : "(")
+                                                .arg(configItem.childs[c].leftValues.at(domain))
+                                                .arg(configItem.childs[c].rightValues.at(domain))
+                                                .arg(configItem.childs[c].rightCloses.at(domain) ? "]" : ")");
+                                if (gindex->gradeIndexValue != indexValue) {
+                                    gindex->gradeIndexValue = indexValue;
                                     if (!GradeIndexInfoService().UpdateGradeIndexInfo(*gindex)) {
                                         QMessageBox::warning(this, "警告", "数据库访问失败");
                                     }
@@ -551,14 +569,17 @@ void MatterElementConfigWidget::onSaveBtnClick()
                     }
                     if (!found) {
                         for (int domain = 0; domain < m_domainLevel + 1; ++domain) {
+                            QString indexValue = QString("%1%2, %3%4")
+                                                         .arg(configItem.childs[c].leftCloses.at(domain) ? "[" : "(")
+                                                         .arg(configItem.childs[c].leftValues.at(domain))
+                                                         .arg(configItem.childs[c].rightValues.at(domain))
+                                                         .arg(configItem.childs[c].rightCloses.at(domain) ? "]" : ")");
                             GradeIndexInfo gii;
                             gii.projectId       = projectId;
                             gii.gradeIndexName  = configItem.childs[c].name;
                             gii.gradeParentName = configItem.parentName;
                             gii.gradeLevel      = c + 1;
-                            gii.gradeIndexValue = QString("(%1, %2)")
-                                                          .arg(configItem.childs[c].leftValues.at(domain))
-                                                          .arg(configItem.childs[c].rightValues.at(domain));
+                            gii.gradeIndexValue = indexValue;
                             if (!GradeIndexInfoService().AddGradeIndexInfo(gii)) {
                                 QMessageBox::warning(this, "警告", "数据库访问失败");
                             }

+ 2 - 0
QFD/widgets/MatterElementConfigWidget.h

@@ -12,6 +12,8 @@ struct MEDomain
     QString name;
     QVector<double> leftValues;   // 与阈值相关 size == m_domainLevel+1
     QVector<double> rightValues;  // 与阈值相关 size == m_domainLevel+1
+    QVector<bool> leftCloses;
+    QVector<bool> rightCloses;
 };
 
 struct MEConfigItem

+ 7 - 3
QFD/widgets/MatterElementItemDelegate.cpp

@@ -81,7 +81,7 @@ QWidget *MatterElementItemRangeDelegate::createEditor(QWidget *parent, const QSt
                                                       const QModelIndex & /*index*/) const
 {
     RangeWidget *editor = new RangeWidget(m_originItems, parent);
-    editor->setMinimumSize(100, 60);
+    editor->setMinimumSize(180, 60);
     return editor;
 }
 
@@ -100,7 +100,11 @@ void MatterElementItemRangeDelegate::setEditorData(QWidget *editor, const QModel
         if (id2 != -1) {
             tmp[1] = m_originItems.at(id2);
         }
-        rw->setValue(tmp.at(0), tmp.at(1));
+
+        bool leftClosed  = value[0] == "[";
+        bool rightClosed = value.right(1) == "]";
+
+        rw->setValue(tmp.at(0), tmp.at(1), leftClosed, rightClosed);
     } else {
         rw->setValue(m_originItems.at(0), m_originItems.at(1));
     }
@@ -139,7 +143,7 @@ void MatterElementItemRangeDelegate::setModelData(QWidget *editor, QAbstractItem
         t2 = m_originValues.at(id2);
     }
 
-    QString value = QString("(%1, %2)").arg(t1).arg(t2);
+    QString value = QString("%1%2, %3%4").arg(list.at(2)).arg(t1).arg(t2).arg(list.at(3));
     model->setData(index, value, Qt::EditRole);
 }
 

+ 33 - 3
QFD/widgets/MatterElementItemDelegate.h

@@ -5,6 +5,8 @@
 #include <QFormLayout>
 #include <QDoubleSpinBox>
 #include <QComboBox>
+#include <QCheckBox>
+#include <QLabel>
 
 class InsideWidget : public QFrame
 {
@@ -109,6 +111,19 @@ class RangeWidget : public QFrame
 public:
     RangeWidget(const QStringList &items, QWidget *parent = nullptr) : QFrame(parent)
     {
+        QHBoxLayout *hLayout = new QHBoxLayout;
+        setStyleSheet("RangeSpin{background-color:gray} QLabel{color:white}");
+        hLayout->setMargin(0);
+        hLayout->setSpacing(0);
+        QLabel *minLabel = new QLabel("左");
+        QLabel *maxLabel = new QLabel("右");
+        m_leftChb        = new QCheckBox;
+        m_leftChb->setCheckable(true);
+        m_leftChb->setChecked(true);
+        m_rightChb = new QCheckBox;
+        m_rightChb->setCheckable(true);
+        m_rightChb->setChecked(true);
+
         QFormLayout *layout = new QFormLayout;
         setStyleSheet("RangeWidget{background-color:gray}");
         layout->setMargin(10);
@@ -126,21 +141,36 @@ public:
         layout->addRow("左:", m_leftCombInput);
         layout->addRow("右:", m_rightCombInput);
 
-        setLayout(layout);
+        hLayout->addWidget(minLabel);
+        hLayout->addWidget(m_leftChb);
+        hLayout->addLayout(layout);
+        hLayout->addWidget(m_rightChb);
+        hLayout->addWidget(maxLabel);
+        setLayout(hLayout);
     }
     virtual ~RangeWidget() { }
 
-    QStringList result() { return { m_leftCombInput->currentText(), m_rightCombInput->currentText() }; }
+    QStringList result()
+    {
+        QString leftClosed  = m_leftChb->isChecked() ? "[" : "(";
+        QString rightClosed = m_rightChb->isChecked() ? "]" : ")";
+        return { m_leftCombInput->currentText(), m_rightCombInput->currentText(), leftClosed, rightClosed };
+    }
 
-    void setValue(const QString &lValue, const QString &rValue)
+    void setValue(const QString &lValue, const QString &rValue, const bool leftClosed = false,
+                  const bool rightClosed = false)
     {
         m_leftCombInput->setCurrentText(lValue);
         m_rightCombInput->setCurrentText(rValue);
+        m_leftChb->setChecked(leftClosed);
+        m_rightChb->setChecked(rightClosed);
     }
 
 private:
     QComboBox *m_leftCombInput;
     QComboBox *m_rightCombInput;
+    QCheckBox *m_leftChb;
+    QCheckBox *m_rightChb;
 };
 
 class MatterElementItemRangeDelegate : public QStyledItemDelegate