|
@@ -1,9 +1,13 @@
|
|
|
#include "GreyClusteringItemDelegate.h"
|
|
|
#include "GreyClusteringSampleTable.h"
|
|
|
#include "MultiLevelHeaderView.h"
|
|
|
+#include "CMind.h"
|
|
|
+#include "dbService/GradeInfoService.h"
|
|
|
+#include "dbService/EffectIndexInfoService.h"
|
|
|
|
|
|
#include <QHeaderView>
|
|
|
#include <QDebug>
|
|
|
+#include <QMessageBox>
|
|
|
|
|
|
/**
|
|
|
* example
|
|
@@ -126,14 +130,16 @@
|
|
|
gcst.show();
|
|
|
*/
|
|
|
|
|
|
-GreyClusteringSampleTable::GreyClusteringSampleTable(const QVector<GreyClusteringItem> &gcItems, int nodeDepth,
|
|
|
- int rowNodes, QWidget *parent)
|
|
|
- : QTableView(parent), m_greyClusterings(gcItems), m_nodeDepth(nodeDepth), m_rowNodes(rowNodes)
|
|
|
+GreyClusteringSampleTable::GreyClusteringSampleTable(CMind *mind, int grayNumber, QWidget *parent)
|
|
|
+ : QTableView(parent), m_mind(mind), m_nodeDepth(2), m_grayNumber(grayNumber)
|
|
|
{
|
|
|
m_model = new QStandardItemModel();
|
|
|
this->setModel(m_model);
|
|
|
|
|
|
init();
|
|
|
+ initClusteringItems();
|
|
|
+
|
|
|
+ refreshTableView();
|
|
|
}
|
|
|
|
|
|
void GreyClusteringSampleTable::refreshTableView()
|
|
@@ -192,7 +198,7 @@ void GreyClusteringSampleTable::refreshTableView()
|
|
|
}
|
|
|
|
|
|
m_model->setColumnCount(colCount);
|
|
|
- m_model->setRowCount(m_rowNodes);
|
|
|
+ m_model->setRowCount(m_rowCount);
|
|
|
|
|
|
for (const auto &item : m_greyClusterings) {
|
|
|
// 第一步,设置指标名
|
|
@@ -257,4 +263,138 @@ void GreyClusteringSampleTable::init()
|
|
|
verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
|
|
|
verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
|
|
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
+
|
|
|
+ QList<GradeInfo *> gradeInfoList;
|
|
|
+ QMap<QString, QString> grayLevelMaps;
|
|
|
+ int projectId = m_mind->root().projectId;
|
|
|
+ if (!GradeInfoService().QueryGradeByProjectIdAndType(&gradeInfoList, projectId, 1)) {
|
|
|
+ QMessageBox::warning(this, "警告", "数据库访问失败");
|
|
|
+ } else {
|
|
|
+ if (gradeInfoList.size() == 0) {
|
|
|
+ for (int lvl = 0; lvl < m_grayNumber; ++lvl) {
|
|
|
+ grayLevelMaps.insert(QString("级别 %1:").arg(lvl + 1), QString("E%1").arg(lvl + 1));
|
|
|
+ GradeInfo ginfo;
|
|
|
+ ginfo.projectId = projectId;
|
|
|
+ ginfo.gradeName = QString("级别 %1").arg(lvl + 1);
|
|
|
+ ginfo.gradeValue = QString("灰类%1级").arg(lvl + 1);
|
|
|
+ ginfo.type = 1;
|
|
|
+ if (!GradeInfoService().AddGradeInfo(ginfo)) {
|
|
|
+ QMessageBox::warning(this, "警告", "数据库访问失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (const auto &gi : gradeInfoList) {
|
|
|
+ grayLevelMaps.insert(gi->gradeName, gi->gradeValue);
|
|
|
+ if (grayLevelMaps.size() >= m_grayNumber) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 缺少再补
|
|
|
+ for (int lvl = grayLevelMaps.size(); lvl < m_grayNumber; ++lvl) {
|
|
|
+ grayLevelMaps.insert(QString("级别 %1:").arg(lvl + 1), QString("E%1").arg(lvl + 1));
|
|
|
+ GradeInfo ginfo;
|
|
|
+ ginfo.projectId = projectId;
|
|
|
+ ginfo.gradeName = QString("级别 %1").arg(lvl + 1);
|
|
|
+ ginfo.gradeValue = QString("灰类%1级").arg(lvl + 1);
|
|
|
+ ginfo.type = 1;
|
|
|
+ if (!GradeInfoService().AddGradeInfo(ginfo)) {
|
|
|
+ QMessageBox::warning(this, "警告", "数据库访问失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ m_grayNames = grayLevelMaps.values();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ qDeleteAll(gradeInfoList);
|
|
|
+}
|
|
|
+
|
|
|
+void GreyClusteringSampleTable::initClusteringItems()
|
|
|
+{
|
|
|
+ // 脑图层级 < 2 时无效
|
|
|
+ if (m_mind->levels() < 2) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ m_greyClusterings.clear();
|
|
|
+
|
|
|
+ // 使用倒数第二层节点及其子节点
|
|
|
+ int row = 0;
|
|
|
+ for (CNodeData n : m_mind->nodesInLevel(m_mind->levels() - 1)) {
|
|
|
+ GreyClusteringItem parentItem = { n.name, row, 0, 1, 1, nullptr };
|
|
|
+ QList<CNodeData> subNodes = m_mind->subNodes(n);
|
|
|
+ parentItem.colSpan = subNodes.size() == 0 ? 2 : 1; // 没有子节点,占两列,否则占一列
|
|
|
+ parentItem.rowSpan = subNodes.size() == 0 ? 1 : subNodes.size(); // 没有子节点,占一行,否则占子节点数目行
|
|
|
+
|
|
|
+ if (subNodes.size() == 0) { // 没有子节点,需要录入值
|
|
|
+ GreyClusteringValue *sg = new GreyClusteringValue;
|
|
|
+ sg->units = "";
|
|
|
+ sg->weiget = 0;
|
|
|
+ for (const auto &gname : m_grayNames) {
|
|
|
+ sg->greyRanges << GreyRange { gname, true, 0, true, 0 };
|
|
|
+ }
|
|
|
+ sg->leftExtension = 0;
|
|
|
+ sg->rightExtension = 0;
|
|
|
+ sg->oldValue = 0;
|
|
|
+ sg->newValue = 0;
|
|
|
+ parentItem.value.reset(sg);
|
|
|
+ }
|
|
|
+ m_greyClusterings.append(parentItem);
|
|
|
+
|
|
|
+ int subRow = row;
|
|
|
+ // 子节点
|
|
|
+ for (const CNodeData &sub : subNodes) {
|
|
|
+ // 因为已有父节点,所以在第2列
|
|
|
+ GreyClusteringItem childItem = { sub.name, subRow, 1, 1, 1, nullptr };
|
|
|
+ GreyClusteringValue *sg = new GreyClusteringValue;
|
|
|
+ sg->units = "";
|
|
|
+ sg->weiget = 0;
|
|
|
+ for (const auto &gname : m_grayNames) {
|
|
|
+ sg->greyRanges << GreyRange { gname, true, 0, true, 0 };
|
|
|
+ }
|
|
|
+ sg->leftExtension = 0;
|
|
|
+ sg->rightExtension = 0;
|
|
|
+ sg->oldValue = 0;
|
|
|
+ sg->newValue = 0;
|
|
|
+ childItem.value.reset(sg);
|
|
|
+ m_greyClusterings.append(childItem);
|
|
|
+ subRow++;
|
|
|
+ }
|
|
|
+
|
|
|
+ row += parentItem.rowSpan;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_rowCount = row;
|
|
|
+
|
|
|
+ // 更新
|
|
|
+ QList<EffectIndexInfo *> effectIndexInfoList;
|
|
|
+ int projectid = m_mind->root().projectId;
|
|
|
+ if (!EffectIndexInfoService().QueryEffectIndexInfoByProjectId(&effectIndexInfoList, projectid)) {
|
|
|
+ QMessageBox::warning(this, "警告", "数据库访问失败");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (effectIndexInfoList.size() > 0) {
|
|
|
+ for (auto &item : m_greyClusterings) {
|
|
|
+ if (item.value.isNull()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (const auto &effInfo : effectIndexInfoList) {
|
|
|
+ if (effInfo->effectIndexName == item.indexName) {
|
|
|
+ item.value->units = effInfo->effectIndexUnit;
|
|
|
+ item.value->leftExtension = effInfo->extendLeft.toDouble();
|
|
|
+ item.value->rightExtension = effInfo->extendRight.toDouble();
|
|
|
+ //[0:0],[0:0],[0:0]
|
|
|
+ QStringList valueList = effInfo->effectIndexValue.split(",");
|
|
|
+ int align = qMin(valueList.size(), item.value->greyRanges.size());
|
|
|
+ for (int str = 0; str < align; str++) {
|
|
|
+ //[0:0]
|
|
|
+ QStringList lr = valueList.at(str).mid(1, valueList.at(str).size() - 2).split(":");
|
|
|
+ item.value->greyRanges[str].leftValue = lr.at(0).toDouble();
|
|
|
+ item.value->greyRanges[str].rightValue = lr.at(1).toDouble();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ qDeleteAll(effectIndexInfoList);
|
|
|
}
|