GreyClusteringSampleTable.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. #include "GreyClusteringItemDelegate.h"
  2. #include "GreyClusteringSampleTable.h"
  3. #include "MultiLevelHeaderView.h"
  4. #include "CMind.h"
  5. #include "dbService/GradeInfoService.h"
  6. #include "dbService/EffectIndexInfoService.h"
  7. #include "dbService/SchemeInfoService.h"
  8. #include "dbService/MindWeightService.h"
  9. #include "dbService/EffectResultService.h"
  10. #include "algorithm/GreyClusterEvaluation.h"
  11. #include "ProjectManager.h"
  12. #include <QHeaderView>
  13. #include <QDebug>
  14. #include <QMessageBox>
  15. #include <QtMath>
  16. /**
  17. * example
  18. * QVector<GreyClusteringItem> gcItems;
  19. gcItems << GreyClusteringItem { "火力", 0, 0, 9, 1, nullptr };
  20. QSharedPointer<GreyClusteringValue> sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  21. sg->units = "m";
  22. sg->weiget = 2;
  23. sg->greyRanges << GreyRange { "较差类", true, 85, true, 100 };
  24. sg->greyRanges << GreyRange { "一般类", true, 100, true, 115 };
  25. sg->greyRanges << GreyRange { "较好类", true, 115, true, 125 };
  26. sg->leftExtension = 70;
  27. sg->rightExtension = 140;
  28. sg->oldValue = 0;
  29. sg->newValue = 0;
  30. gcItems << GreyClusteringItem { "火炮口径", 0, 1, 1, 2, sg };
  31. gcItems << GreyClusteringItem { "初速", 1, 1, 3, 1, nullptr };
  32. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  33. sg->units = "m";
  34. sg->weiget = 4;
  35. sg->greyRanges << GreyRange { "较差类", true, 1600, true, 1300 };
  36. sg->greyRanges << GreyRange { "一般类", true, 1600, true, 1900 };
  37. sg->greyRanges << GreyRange { "较好类", true, 1600, true, 1900 };
  38. sg->leftExtension = 500;
  39. sg->rightExtension = 220;
  40. sg->oldValue = 0;
  41. sg->newValue = 0;
  42. gcItems << GreyClusteringItem { "穿甲弹", 1, 2, 1, 1, sg };
  43. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  44. sg->units = "m";
  45. sg->weiget = 4;
  46. sg->greyRanges << GreyRange { "较差类", true, 1000, true, 1200 };
  47. sg->greyRanges << GreyRange { "一般类", true, 1200, true, 1400 };
  48. sg->greyRanges << GreyRange { "较好类", true, 1200, true, 1400 };
  49. sg->leftExtension = 600;
  50. sg->rightExtension = 1700;
  51. sg->oldValue = 0;
  52. sg->newValue = 0;
  53. gcItems << GreyClusteringItem { "破甲弹", 2, 2, 1, 1, sg };
  54. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  55. sg->units = "m";
  56. sg->weiget = 4;
  57. sg->greyRanges << GreyRange { "较差类", true, 500, false, 650 };
  58. sg->greyRanges << GreyRange { "一般类", true, 650, false, 800 };
  59. sg->greyRanges << GreyRange { "较好类", true, 800, false, 1000 };
  60. sg->leftExtension = 400;
  61. sg->rightExtension = 1100;
  62. sg->oldValue = 0;
  63. sg->newValue = 0;
  64. gcItems << GreyClusteringItem { "榴弹", 3, 2, 1, 1, sg };
  65. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  66. sg->units = "";
  67. sg->weiget = 5;
  68. sg->greyRanges << GreyRange { "较差类", true, 0.5, false, 0.65 };
  69. sg->greyRanges << GreyRange { "一般类", true, 0.65, false, 0.75 };
  70. sg->greyRanges << GreyRange { "较好类", true, 0.75, false, 0.9 };
  71. sg->leftExtension = 0.45;
  72. sg->rightExtension = 0.95;
  73. sg->oldValue = 0;
  74. sg->newValue = 0;
  75. gcItems << GreyClusteringItem { "首发命中", 4, 1, 1, 2, sg };
  76. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  77. sg->units = "m";
  78. sg->weiget = 5;
  79. sg->greyRanges << GreyRange { "较差类", true, 800, false, 1200 };
  80. sg->greyRanges << GreyRange { "一般类", true, 1200, false, 1600 };
  81. sg->greyRanges << GreyRange { "较好类", true, 1600, false, 2200 };
  82. sg->leftExtension = 500;
  83. sg->rightExtension = 2500;
  84. sg->oldValue = 0;
  85. sg->newValue = 0;
  86. gcItems << GreyClusteringItem { "直射距离", 5, 1, 1, 2, sg };
  87. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  88. sg->units = "发";
  89. sg->weiget = 3;
  90. sg->greyRanges << GreyRange { "较差类", true, 30, false, 40 };
  91. sg->greyRanges << GreyRange { "一般类", true, 40, false, 50 };
  92. sg->greyRanges << GreyRange { "较好类", true, 50, false, 65 };
  93. sg->leftExtension = 28;
  94. sg->rightExtension = 70;
  95. sg->oldValue = 0;
  96. sg->newValue = 0;
  97. gcItems << GreyClusteringItem { "弹药基数", 6, 1, 1, 2, sg };
  98. gcItems << GreyClusteringItem { "时间", 7, 1, 2, 1, nullptr };
  99. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  100. sg->units = "s";
  101. sg->weiget = 3;
  102. sg->greyRanges << GreyRange { "较差类", true, 11, false, 10 };
  103. sg->greyRanges << GreyRange { "一般类", true, 10, false, 7 };
  104. sg->greyRanges << GreyRange { "较好类", true, 7, false, 4 };
  105. sg->leftExtension = 12;
  106. sg->rightExtension = 3;
  107. sg->oldValue = 0;
  108. sg->newValue = 0;
  109. gcItems << GreyClusteringItem { "静对静", 7, 2, 1, 1, sg };
  110. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  111. sg->units = "s";
  112. sg->weiget = 3;
  113. sg->greyRanges << GreyRange { "较差类", true, 14, false, 12 };
  114. sg->greyRanges << GreyRange { "一般类", true, 12, false, 10 };
  115. sg->greyRanges << GreyRange { "较好类", true, 10, false, 7 };
  116. sg->leftExtension = 15;
  117. sg->rightExtension = 5;
  118. sg->oldValue = 0;
  119. sg->newValue = 0;
  120. gcItems << GreyClusteringItem { "静对动", 8, 2, 1, 1, sg };
  121. GreyClusteringSampleTable gcst(gcItems, 3, 9);
  122. gcst.resize(1200, 800);
  123. gcst.refreshTableView();
  124. gcst.show();
  125. */
  126. GreyClusteringSampleTable::GreyClusteringSampleTable(CMind *mind, int grayNumber, QWidget *parent)
  127. : QTableView(parent), m_mind(mind), m_nodeDepth(2), m_grayNumber(grayNumber)
  128. {
  129. m_model = new QStandardItemModel();
  130. connect(m_model, &QStandardItemModel::itemChanged, this, &GreyClusteringSampleTable::itemChanged);
  131. this->setModel(m_model);
  132. init();
  133. refreshData();
  134. }
  135. void GreyClusteringSampleTable::refreshData()
  136. {
  137. loadData();
  138. loadSchemeData();
  139. initClusteringItems();
  140. refreshTableView();
  141. }
  142. void GreyClusteringSampleTable::refreshTableView()
  143. {
  144. m_isFillingData = true;
  145. m_model->clear();
  146. if (m_greyClusterings.size() == 0) {
  147. m_isFillingData = false;
  148. return;
  149. }
  150. QStringList greyNames; // 灰数
  151. for (auto &item : m_greyClusterings) {
  152. if (!item.value.isNull()) {
  153. for (const auto &s : item.value->greyRanges) {
  154. greyNames << s.name;
  155. }
  156. break;
  157. }
  158. }
  159. int colCount = m_nodeDepth + 6 + greyNames.size();
  160. // 设置表头
  161. {
  162. // if (m_tableHeaderInitialized == false) {
  163. // m_tableHeaderInitialized = true;
  164. MultiLevelHeaderView *hHeader = dynamic_cast<MultiLevelHeaderView *>(horizontalHeader());
  165. if (hHeader == nullptr) {
  166. hHeader = new MultiLevelHeaderView(Qt::Horizontal, 2, colCount, this);
  167. hHeader->setSectionResizeMode(QHeaderView::Stretch);
  168. this->setHorizontalHeader(hHeader);
  169. hHeader->setCellSpan(0, 0, 2, m_nodeDepth); // 指标占位
  170. for (int n = 0; n < 2 + greyNames.size(); ++n) { // 单位+权重+灰度级占位
  171. hHeader->setCellSpan(0, m_nodeDepth + n, 2, 1);
  172. }
  173. hHeader->setCellSpan(0, m_nodeDepth + 2 + greyNames.size(), 1, 2); // 延拓值占位
  174. hHeader->setCellSpan(1, m_nodeDepth + 2 + greyNames.size(), 1, 1);
  175. hHeader->setCellSpan(1, m_nodeDepth + 2 + greyNames.size() + 1, 1, 1);
  176. hHeader->setCellSpan(0, m_nodeDepth + 4 + greyNames.size(), 1, 2); // 实现值占位
  177. hHeader->setCellSpan(1, m_nodeDepth + 4 + greyNames.size(), 1, 1);
  178. hHeader->setCellSpan(1, m_nodeDepth + 4 + greyNames.size() + 1, 1, 1);
  179. }
  180. // 一级
  181. hHeader->setCellText(0, 0, QString("指标"));
  182. hHeader->setCellText(0, m_nodeDepth, QString("单位"));
  183. hHeader->setCellText(0, m_nodeDepth + 1, QString("权重"));
  184. for (int i = 0; i < greyNames.size(); ++i) {
  185. hHeader->setCellText(0, m_nodeDepth + 2 + i, greyNames.at(i));
  186. }
  187. hHeader->setCellText(0, m_nodeDepth + 2 + greyNames.size(), QString("延拓值"));
  188. hHeader->setCellText(0, m_nodeDepth + 4 + greyNames.size(), QString("实现值"));
  189. // 二级
  190. hHeader->setCellText(1, m_nodeDepth + 2 + greyNames.size(), "左");
  191. hHeader->setCellText(1, m_nodeDepth + 3 + greyNames.size(), "右");
  192. hHeader->setCellText(1, m_nodeDepth + 4 + greyNames.size(), "建设前");
  193. hHeader->setCellText(1, m_nodeDepth + 5 + greyNames.size(), "建设后");
  194. // }
  195. }
  196. m_model->setColumnCount(colCount);
  197. m_model->setRowCount(m_rowCount);
  198. for (const auto &item : m_greyClusterings) {
  199. // 第一步,设置指标名
  200. auto s = new QStandardItem(item.indexName);
  201. s->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
  202. s->setTextAlignment(Qt::AlignCenter);
  203. s->setToolTip(item.indexName);
  204. m_model->setItem(item.row, item.col, s);
  205. if (item.rowSpan > 1 || item.colSpan > 1) {
  206. this->setSpan(item.row, item.col, item.rowSpan, item.colSpan);
  207. }
  208. // 第二步,查看当前指标下是否附带值
  209. if (!item.value.isNull()) {
  210. int offset = item.colSpan;
  211. m_model->setItem(item.row, item.col + offset, new QStandardItem(item.value->units)); // 单位
  212. ++offset;
  213. m_model->setItem(item.row, item.col + offset,
  214. new QStandardItem(QString::number(item.value->weiget))); // 权重
  215. ++offset;
  216. for (auto &range : item.value->greyRanges) { // 灰度级
  217. QString r;
  218. r += range.leftClose ? "[" : "(";
  219. r += QString("%1, %2").arg(range.leftValue).arg(range.rightValue);
  220. r += range.rightClose ? "]" : ")";
  221. m_model->setItem(item.row, item.col + offset, new QStandardItem(r));
  222. ++offset;
  223. }
  224. m_model->setItem(item.row, item.col + offset,
  225. new QStandardItem(QString::number(item.value->leftExtension))); // 延拓值左
  226. ++offset;
  227. m_model->setItem(item.row, item.col + offset,
  228. new QStandardItem(QString::number(item.value->rightExtension))); // 延拓值右
  229. ++offset;
  230. QStandardItem *oldValue = new QStandardItem;
  231. if (m_schemeData.keys().contains("建设前")) {
  232. oldValue->setText(m_schemeData["建设前"][item.indexName]);
  233. }
  234. m_model->setItem(item.row, item.col + offset, oldValue); // 实现值前
  235. ++offset;
  236. QStandardItem *newValue = new QStandardItem;
  237. if (m_schemeData.keys().contains("建设后")) {
  238. newValue->setText(m_schemeData["建设后"][item.indexName]);
  239. }
  240. m_model->setItem(item.row, item.col + offset, newValue); // 实现值后
  241. ++offset;
  242. for (int c = item.colSpan; c < offset - 2; ++c) {
  243. m_model->item(item.row, item.col + c)->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
  244. m_model->item(item.row, item.col + c)->setTextAlignment(Qt::AlignCenter);
  245. }
  246. for (int c = offset - 2; c < offset; ++c) {
  247. m_model->item(item.row, item.col + c)->setTextAlignment(Qt::AlignCenter);
  248. this->setItemDelegateForColumn(item.col + c, new GreyClusteringItemSpinDelegate(this));
  249. }
  250. }
  251. }
  252. m_isFillingData = false;
  253. }
  254. void GreyClusteringSampleTable::itemChanged(QStandardItem *item)
  255. {
  256. if (m_isFillingData) {
  257. return;
  258. }
  259. if (horizontalHeader()->model()->rowCount() < 2 || horizontalHeader()->model()->columnCount() <= item->column()) {
  260. return;
  261. }
  262. QModelIndex hIndex = horizontalHeader()->model()->index(1, item->column());
  263. QString hTitle = horizontalHeader()->model()->data(hIndex).toString();
  264. QStringList valueStrList;
  265. for (int r = 0; r < m_model->rowCount(); ++r) {
  266. QString vTitle = m_model->item(r, 1)->text();
  267. QString value = m_model->item(r, item->column())->text();
  268. QString valueStr = vTitle + ":" + value;
  269. valueStrList.append(valueStr);
  270. }
  271. QString v = valueStrList.join(";");
  272. SchemaEval scheme;
  273. scheme.engineerId = m_mind->root().projectId;
  274. scheme.name = hTitle;
  275. scheme.valueStr = v;
  276. scheme.type = 2;
  277. bool ret = SchemeInfoService().addUniqueGCEData(scheme);
  278. qDebug() << __FUNCTION__ << __LINE__ << ret << endl;
  279. }
  280. void GreyClusteringSampleTable::compute()
  281. {
  282. GCEMat mat;
  283. GCERangeMat ranges;
  284. QVector<GCEmat> samples;
  285. int colCount = m_nodeDepth + 4 + m_grayNumber;
  286. for (int r = 0; r < m_rowCount; ++r) {
  287. samples << GCEmat { m_model->item(r, colCount)->text().toDouble(),
  288. m_model->item(r, colCount + 1)->text().toDouble() };
  289. }
  290. mat = samples;
  291. // 指标
  292. for (const auto &item : m_greyClusterings) {
  293. if (!item.value.isNull()) {
  294. QVector<GCERange> rg;
  295. QSet<double> fullSet;
  296. fullSet << item.value->leftExtension;
  297. for (const auto &grange : item.value->greyRanges) {
  298. fullSet << grange.leftValue << grange.rightValue;
  299. }
  300. fullSet << item.value->rightExtension;
  301. QList<double> full = fullSet.toList();
  302. std::sort(full.begin(), full.end());
  303. for (int i = 0; i < item.value->greyRanges.size(); ++i) {
  304. double left;
  305. double right;
  306. int lloc = full.indexOf(item.value->greyRanges.at(i).leftValue);
  307. int rloc = full.indexOf(item.value->greyRanges.at(i).rightValue);
  308. if (lloc == 0) {
  309. left = full[0];
  310. } else {
  311. left = full[lloc - 1];
  312. }
  313. if (rloc == full.size() - 1) {
  314. right = full.last();
  315. } else {
  316. right = full[rloc + 1];
  317. }
  318. rg << GCERange { i, left, item.value->greyRanges.at(i).leftValue,
  319. item.value->greyRanges.at(i).rightValue, right };
  320. }
  321. ranges << rg;
  322. }
  323. }
  324. QScopedPointer<GreyClusterEvaluation> gc(new GreyClusterEvaluation(mat, ranges));
  325. MindWeightInfo info;
  326. bool ret = MindWeightService().queryWeightData(&info, m_mind->root().projectId, ProjectManager::EfficiencyIndex);
  327. if (ret == false) {
  328. return;
  329. }
  330. if (info.id < 0) {
  331. qDebug() << __FUNCTION__ << __LINE__ << "未找到指标权重数据" << endl;
  332. return;
  333. }
  334. QMap<QString, double> weightData;
  335. QStringList weightList = info.weight.split(";");
  336. for (QString keyValueStr : weightList) {
  337. QStringList keyValue = keyValueStr.split(":");
  338. if (keyValue.size() == 2) {
  339. weightData[keyValue.first()] = keyValue.last().toDouble();
  340. }
  341. }
  342. QVector<double> weights;
  343. QList<CNodeData> indexList = m_mind->leaves();
  344. for (int i = 0; i < indexList.size(); ++i) {
  345. weights.append(weightData[indexList[i].name]);
  346. }
  347. gc->evaluate(weights);
  348. gc->getBestIndex();
  349. QVector<GCEmat> rangeWeights = gc->getRangeWeights();
  350. QVector<GCEMat> rangeCvt = gc->getRangeCVT();
  351. QList<EffectResult> resultData;
  352. QList<int> schemeIdList = { -2, -1 };
  353. QList<QString> schemeNameList = { "建设前", "建设后" };
  354. for (int scheme = 0; scheme < 2; ++scheme) {
  355. EffectResult overall;
  356. overall.projectId = m_mind->root().projectId;
  357. overall.schemeId = schemeIdList[scheme];
  358. overall.schemeName = schemeNameList[scheme];
  359. overall.algType = 1;
  360. overall.indexName = "综合";
  361. QStringList strList;
  362. for (int v = 0; v < rangeWeights.size(); ++v) {
  363. if (scheme == 0) {
  364. strList.append(QString("%1").arg(rangeWeights[v].front_val));
  365. } else {
  366. strList.append(QString("%1").arg(rangeWeights[v].back_val));
  367. }
  368. }
  369. overall.value = strList.join(",");
  370. resultData.append(overall);
  371. for (int index = 0; index < indexList.size(); ++index) {
  372. EffectResult result;
  373. result.projectId = indexList[index].projectId;
  374. result.schemeId = schemeIdList[scheme];
  375. result.schemeName = schemeNameList[scheme];
  376. result.algType = 1;
  377. result.indexName = indexList[index].name;
  378. QStringList strList;
  379. for (int v = 0; v < rangeWeights.size(); ++v) {
  380. if (scheme == 0) {
  381. strList.append(QString("%1").arg(rangeCvt[index][v].front_val));
  382. } else {
  383. strList.append(QString("%1").arg(rangeCvt[index][v].back_val));
  384. }
  385. }
  386. result.value = strList.join(",");
  387. resultData.append(result);
  388. }
  389. }
  390. bool saveRet = EffectResultService().addDataList(resultData);
  391. qDebug() << __FUNCTION__ << __LINE__ << saveRet << endl;
  392. }
  393. void GreyClusteringSampleTable::init()
  394. {
  395. setAlternatingRowColors(false);
  396. horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
  397. horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  398. verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  399. verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
  400. setSelectionMode(QAbstractItemView::SingleSelection);
  401. }
  402. void GreyClusteringSampleTable::loadData()
  403. {
  404. QList<GradeInfo *> gradeInfoList;
  405. QMap<QString, QString> grayLevelMaps;
  406. int projectId = m_mind->root().projectId;
  407. if (!GradeInfoService().QueryGradeByProjectIdAndType(&gradeInfoList, projectId, 1)) {
  408. QMessageBox::warning(this, "警告", "数据库访问失败");
  409. } else {
  410. if (gradeInfoList.size() == 0) {
  411. for (int lvl = 0; lvl < m_grayNumber; ++lvl) {
  412. grayLevelMaps.insert(QString("级别 %1:").arg(lvl + 1), QString("E%1").arg(lvl + 1));
  413. GradeInfo ginfo;
  414. ginfo.projectId = projectId;
  415. ginfo.gradeName = QString("级别 %1").arg(lvl + 1);
  416. ginfo.gradeValue = QString("灰类%1级").arg(lvl + 1);
  417. ginfo.type = 1;
  418. if (!GradeInfoService().AddGradeInfo(ginfo)) {
  419. QMessageBox::warning(this, "警告", "数据库访问失败");
  420. }
  421. }
  422. } else {
  423. for (const auto &gi : gradeInfoList) {
  424. grayLevelMaps.insert(gi->gradeName, gi->gradeValue);
  425. if (grayLevelMaps.size() >= m_grayNumber) {
  426. break;
  427. }
  428. }
  429. // 缺少再补
  430. for (int lvl = grayLevelMaps.size(); lvl < m_grayNumber; ++lvl) {
  431. grayLevelMaps.insert(QString("级别 %1:").arg(lvl + 1), QString("E%1").arg(lvl + 1));
  432. GradeInfo ginfo;
  433. ginfo.projectId = projectId;
  434. ginfo.gradeName = QString("级别 %1").arg(lvl + 1);
  435. ginfo.gradeValue = QString("灰类%1级").arg(lvl + 1);
  436. ginfo.type = 1;
  437. if (!GradeInfoService().AddGradeInfo(ginfo)) {
  438. QMessageBox::warning(this, "警告", "数据库访问失败");
  439. }
  440. }
  441. m_grayNames = grayLevelMaps.values();
  442. }
  443. }
  444. qDeleteAll(gradeInfoList);
  445. }
  446. void GreyClusteringSampleTable::loadSchemeData()
  447. {
  448. m_schemeData.clear();
  449. QList<SchemaEval *> schemeList;
  450. bool ret = SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_mind->root().projectId, 2);
  451. if (ret == false) {
  452. return;
  453. }
  454. for (SchemaEval *scheme : schemeList) {
  455. if (m_schemeData.keys().contains(scheme->name) == false) {
  456. m_schemeData[scheme->name] = QMap<QString, QString>();
  457. }
  458. QStringList valueStrList = scheme->valueStr.split(";");
  459. for (QString valueStr : valueStrList) {
  460. QStringList keyValue = valueStr.split(":");
  461. if (keyValue.size() == 2) {
  462. m_schemeData[scheme->name][keyValue.first()] = keyValue.last();
  463. }
  464. }
  465. }
  466. }
  467. void GreyClusteringSampleTable::initClusteringItems()
  468. {
  469. // 脑图层级 < 2 时无效
  470. if (m_mind->levels() < 2) {
  471. return;
  472. }
  473. m_greyClusterings.clear();
  474. // 使用倒数第二层节点及其子节点
  475. int row = 0;
  476. for (CNodeData n : m_mind->nodesInLevel(m_mind->levels() - 1)) {
  477. GreyClusteringItem parentItem = { n.name, row, 0, 1, 1, nullptr };
  478. QList<CNodeData> subNodes = m_mind->subNodes(n);
  479. parentItem.colSpan = subNodes.size() == 0 ? 2 : 1; // 没有子节点,占两列,否则占一列
  480. parentItem.rowSpan = subNodes.size() == 0 ? 1 : subNodes.size(); // 没有子节点,占一行,否则占子节点数目行
  481. if (subNodes.size() == 0) { // 没有子节点,需要录入值
  482. GreyClusteringValue *sg = new GreyClusteringValue;
  483. sg->units = n.dimension;
  484. sg->weiget = 0;
  485. for (const auto &gname : m_grayNames) {
  486. sg->greyRanges << GreyRange { gname, true, 0, true, 0 };
  487. }
  488. sg->leftExtension = 0;
  489. sg->rightExtension = 0;
  490. sg->oldValue = 0;
  491. sg->newValue = 0;
  492. parentItem.value.reset(sg);
  493. }
  494. m_greyClusterings.append(parentItem);
  495. int subRow = row;
  496. // 子节点
  497. for (const CNodeData &sub : subNodes) {
  498. // 因为已有父节点,所以在第2列
  499. GreyClusteringItem childItem = { sub.name, subRow, 1, 1, 1, nullptr };
  500. GreyClusteringValue *sg = new GreyClusteringValue;
  501. sg->units = sub.dimension;
  502. sg->weiget = 0;
  503. for (const auto &gname : m_grayNames) {
  504. sg->greyRanges << GreyRange { gname, true, 0, true, 0 };
  505. }
  506. sg->leftExtension = 0;
  507. sg->rightExtension = 0;
  508. sg->oldValue = 0;
  509. sg->newValue = 0;
  510. childItem.value.reset(sg);
  511. m_greyClusterings.append(childItem);
  512. subRow++;
  513. }
  514. row += parentItem.rowSpan;
  515. }
  516. m_rowCount = row;
  517. // 更新
  518. QList<EffectIndexInfo *> effectIndexInfoList;
  519. int projectid = m_mind->root().projectId;
  520. if (!EffectIndexInfoService().QueryEffectIndexInfoByProjectId(&effectIndexInfoList, projectid)) {
  521. QMessageBox::warning(this, "警告", "数据库访问失败");
  522. return;
  523. }
  524. if (effectIndexInfoList.size() > 0) {
  525. for (auto &item : m_greyClusterings) {
  526. if (item.value.isNull()) {
  527. continue;
  528. }
  529. for (const auto &effInfo : effectIndexInfoList) {
  530. if (effInfo->effectIndexName == item.indexName) {
  531. if (effInfo->effectIndexUnit.length() > 0) {
  532. // item.value->units = effInfo->effectIndexUnit;
  533. }
  534. item.value->leftExtension = effInfo->extendLeft.toDouble();
  535. item.value->rightExtension = effInfo->extendRight.toDouble();
  536. //[0:0],[0:0],[0:0]
  537. QStringList valueList;
  538. if (effInfo->effectIndexValue.length() > 0) {
  539. valueList = effInfo->effectIndexValue.split(",");
  540. }
  541. int align = qMin(valueList.size(), item.value->greyRanges.size());
  542. for (int str = 0; str < align; str++) {
  543. //[0:0]
  544. QStringList lr = valueList.at(str).mid(1, valueList.at(str).size() - 2).split(":");
  545. item.value->greyRanges[str].leftValue = lr.at(0).toDouble();
  546. item.value->greyRanges[str].leftClose = valueList.at(str)[0] == "[";
  547. item.value->greyRanges[str].rightValue = lr.at(1).toDouble();
  548. item.value->greyRanges[str].rightClose = valueList.at(str).right(1) == "]";
  549. }
  550. }
  551. }
  552. }
  553. }
  554. qDeleteAll(effectIndexInfoList);
  555. }