|
@@ -5,6 +5,8 @@
|
|
|
#include "ProjectManager.h"
|
|
|
#include <dbService/CNodeDataService.h>
|
|
|
#include <dbService/ClassSet.h>
|
|
|
+#include <dbService/UserService.h>
|
|
|
+#include <dbService/NodeMatrixService.h>
|
|
|
|
|
|
#include <Widgets/Button.h>
|
|
|
#include <QBoxLayout>
|
|
@@ -19,6 +21,8 @@
|
|
|
#include <QHeaderView>
|
|
|
#include <QApplication>
|
|
|
#include <QDesktopWidget>
|
|
|
+#include <QDateTime>
|
|
|
+#include <QFileDialog>
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
@@ -32,6 +36,11 @@ EXDataTableView::EXDataTableView(SchemePlanManager::SchemeProcessInfo process, Q
|
|
|
connectSignalsAndSlots();
|
|
|
|
|
|
m_comboDelegate = new EXDataTableComboDelegate(this);
|
|
|
+
|
|
|
+ m_user = new QFUser();
|
|
|
+ UserService().QueryUserInfoById(m_user, 62);
|
|
|
+
|
|
|
+ m_export = new QXlsx::Document(this);
|
|
|
}
|
|
|
|
|
|
SchemePlanManager::SchemeProcessInfo EXDataTableView::process() const
|
|
@@ -39,6 +48,11 @@ SchemePlanManager::SchemeProcessInfo EXDataTableView::process() const
|
|
|
return m_process;
|
|
|
}
|
|
|
|
|
|
+void EXDataTableView::setProjectInfo(ProjectInfo *proj)
|
|
|
+{
|
|
|
+ m_proj = proj;
|
|
|
+}
|
|
|
+
|
|
|
void EXDataTableView::initWidget()
|
|
|
{
|
|
|
m_dataTab = new QTabWidget(this);
|
|
@@ -46,6 +60,7 @@ void EXDataTableView::initWidget()
|
|
|
m_pageLab = new QLabel(this);
|
|
|
m_previous = new PushButton("上一级指标", this);
|
|
|
m_next = new PushButton("下一级指标", this);
|
|
|
+ m_save = new PushButton("保存", this);
|
|
|
}
|
|
|
|
|
|
void EXDataTableView::initLayout()
|
|
@@ -61,6 +76,7 @@ void EXDataTableView::initLayout()
|
|
|
m_pageLayout->addWidget(m_pageLab);
|
|
|
m_pageLayout->addWidget(m_next);
|
|
|
m_pageLayout->addStretch();
|
|
|
+ m_pageLayout->addWidget(m_save);
|
|
|
}
|
|
|
|
|
|
void EXDataTableView::connectSignalsAndSlots()
|
|
@@ -68,6 +84,7 @@ void EXDataTableView::connectSignalsAndSlots()
|
|
|
connect(m_previous, &PushButton::clicked, this, &EXDataTableView::slotPrevious);
|
|
|
connect(m_next, &PushButton::clicked, this, &EXDataTableView::slotNext);
|
|
|
connect(m_dataTab, &QTabWidget::currentChanged, this, &EXDataTableView::slotTabCurrentChanged);
|
|
|
+ connect(m_save, &PushButton::clicked, this, &EXDataTableView::slotSave);
|
|
|
}
|
|
|
|
|
|
void EXDataTableView::setupTabWidget()
|
|
@@ -77,7 +94,11 @@ void EXDataTableView::setupTabWidget()
|
|
|
/// 所以使用 m_isSettingTable 标记此过程, 以采取必要措施来规避一些异常操作
|
|
|
m_isSettingTable = true;
|
|
|
m_dataTab->clear();
|
|
|
- for (CNodeData n : m_mind1->nodesInLevel(m_currentPage)) {
|
|
|
+
|
|
|
+ QList<CNodeData> nodeList = m_mind1->nodesInLevel(m_currentPage);
|
|
|
+
|
|
|
+ for (int i = 0; i < nodeList.count(); i++) {
|
|
|
+ CNodeData n = nodeList[i];
|
|
|
QTableView *t = new QTableView(m_dataTab);
|
|
|
t->setAlternatingRowColors(m_mind2->nodeList().count() > 0);
|
|
|
t->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
@@ -88,9 +109,21 @@ void EXDataTableView::setupTabWidget()
|
|
|
|
|
|
m_dataTab->addTab(t, n.name);
|
|
|
|
|
|
- QStandardItemModel *model = new QStandardItemModel(t);
|
|
|
+ QList<QStandardItemModel *> modelList;
|
|
|
+ if (m_models.keys().contains(m_currentPage)) {
|
|
|
+ modelList = m_models[m_currentPage];
|
|
|
+ }
|
|
|
+ QStandardItemModel *model;
|
|
|
+ if (modelList.count() <= i) {
|
|
|
+ model = new QStandardItemModel(t);
|
|
|
+ modelList.append(model);
|
|
|
+ } else {
|
|
|
+ model = modelList[i];
|
|
|
+ }
|
|
|
+ m_models[m_currentPage] = modelList;
|
|
|
+
|
|
|
t->setModel(model);
|
|
|
- connect(t, &QTableView::clicked, this, &EXDataTableView::itemClicked);
|
|
|
+ connect(t, &QTableView::clicked, this, &EXDataTableView::slotItemClicked);
|
|
|
}
|
|
|
m_isSettingTable = false;
|
|
|
}
|
|
@@ -225,7 +258,6 @@ void EXDataTableView::updateCurrentTable()
|
|
|
for (int j = 0; j < hList.count(); j++) {
|
|
|
QStandardItem *item = new QStandardItem();
|
|
|
item->setData(Qt::AlignCenter, Qt::TextAlignmentRole);
|
|
|
- // item->setEditable(false);
|
|
|
model->setItem(i, j, item);
|
|
|
table->setItemDelegate(m_comboDelegate);
|
|
|
}
|
|
@@ -243,6 +275,68 @@ CMind *EXDataTableView::mind2() const
|
|
|
return m_mind2;
|
|
|
}
|
|
|
|
|
|
+void EXDataTableView::exportData()
|
|
|
+{
|
|
|
+ qDebug() << __FUNCTION__ << __LINE__ << endl;
|
|
|
+
|
|
|
+ //文件夹路径
|
|
|
+ QFileDialog::Options options;
|
|
|
+ options |= QFileDialog::DontUseNativeDialog;
|
|
|
+ QString filePath = QFileDialog::getExistingDirectory(nullptr, "导出资源包", "/", options);
|
|
|
+ if (filePath.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ QString fileName = m_user->userName + "-"
|
|
|
+ + ProjectManager::nameOfIndexType((ProjectManager::IndexType)m_process.indexType) + "-"
|
|
|
+ + m_proj->projectName;
|
|
|
+ // QString filePath = "";
|
|
|
+ // filePath = QCoreApplication::applicationDirPath();
|
|
|
+ QDir dirReportPath(filePath);
|
|
|
+ if (!dirReportPath.exists()) {
|
|
|
+ if (dirReportPath.mkpath(filePath)) {
|
|
|
+ filePath = filePath + "/" + fileName + tr(".xlsx");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ filePath = filePath + "/" + fileName + tr(".xlsx");
|
|
|
+ }
|
|
|
+ QFile file(fileName);
|
|
|
+ if (file.exists()) {
|
|
|
+ file.remove();
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 1; i < m_mind1->levels(); i++) {
|
|
|
+ if (m_models.keys().contains(i) == false) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ QList<CNodeData> nodes = m_mind1->nodesInLevel(i);
|
|
|
+
|
|
|
+ for (int j = 0; j < m_models[i].count(); j++) {
|
|
|
+ CNodeData node = nodes[j];
|
|
|
+ QStandardItemModel *model = m_models[i][j];
|
|
|
+ m_export->addSheet(node.name);
|
|
|
+ int row = model->rowCount();
|
|
|
+ int col = model->columnCount();
|
|
|
+
|
|
|
+ m_export->setColumnWidth(1, 20);
|
|
|
+ for (int c = 2; c < col + 2; c++) {
|
|
|
+ QStandardItem *head = model->horizontalHeaderItem(c - 2);
|
|
|
+ m_export->write(1, c, head->text());
|
|
|
+ m_export->setColumnWidth(c, head->text().size() == 0 ? 40 : head->text().size() * 4);
|
|
|
+ }
|
|
|
+ for (int r = 2; r < row + 2; r++) {
|
|
|
+ QStandardItem *head = model->verticalHeaderItem(r - 2);
|
|
|
+ m_export->write(r, 1, head->text());
|
|
|
+
|
|
|
+ for (int c = 2; c < col + 2; c++) {
|
|
|
+ QStandardItem *head = model->item(r - 2, c - 2);
|
|
|
+ m_export->write(r, c, head->text());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ m_export->saveAs(filePath);
|
|
|
+ }
|
|
|
+}
|
|
|
void EXDataTableView::editItemData(const QModelIndex &index, const QString &val)
|
|
|
{
|
|
|
int c = m_dataTab->currentIndex();
|
|
@@ -278,7 +372,7 @@ void EXDataTableView::slotTabCurrentChanged(int c)
|
|
|
updateCurrentTable();
|
|
|
}
|
|
|
|
|
|
-void EXDataTableView::itemClicked(const QModelIndex &index)
|
|
|
+void EXDataTableView::slotItemClicked(const QModelIndex &index)
|
|
|
{
|
|
|
if (index.row() >= index.column()) {
|
|
|
return;
|
|
@@ -309,3 +403,39 @@ void EXDataTableView::itemClicked(const QModelIndex &index)
|
|
|
}
|
|
|
scheme->move(p);
|
|
|
}
|
|
|
+
|
|
|
+void EXDataTableView::slotSave()
|
|
|
+{
|
|
|
+ return;
|
|
|
+ int c = m_dataTab->currentIndex();
|
|
|
+ QTableView *table = (QTableView *)m_dataTab->widget(c);
|
|
|
+ QStandardItemModel *model = (QStandardItemModel *)table->model();
|
|
|
+
|
|
|
+ QList<NodeMatrixInfo *> values;
|
|
|
+
|
|
|
+ if (m_process.type == SchemePlanManager::ImportWeightData) {
|
|
|
+ for (int i = 0; i < model->rowCount(); i++) {
|
|
|
+ QStandardItem *row = model->verticalHeaderItem(i);
|
|
|
+ for (int j = 0; j < model->columnCount(); j++) {
|
|
|
+ QStandardItem *col = model->horizontalHeaderItem(j);
|
|
|
+ QStandardItem *item = model->item(i, j);
|
|
|
+
|
|
|
+ NodeMatrixInfo *info = new NodeMatrixInfo();
|
|
|
+ info->expertName = m_user->userName;
|
|
|
+ info->expertId = QString("%1").arg(m_user->id);
|
|
|
+ info->engineerId = m_process.projectId;
|
|
|
+ info->mindId = m_process.dSource;
|
|
|
+ info->abscissa = col->text();
|
|
|
+ info->ordinate = row->text();
|
|
|
+ info->writeDate = QDateTime::currentDateTime();
|
|
|
+ info->mark = QString("%1").arg(m_currentPage);
|
|
|
+ info->nodeValue = item->text();
|
|
|
+ info->tableMsg = QString("%1").arg(m_process.indexType);
|
|
|
+
|
|
|
+ values.append(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ NodeMatrixService().AddNodeMatrixInfoList2(values);
|
|
|
+}
|