2025-11-11 09:02:49 +08:00
|
|
|
|
#include "formmultiheads.h"
|
|
|
|
|
|
#include "ui_formmultiheads.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
#include <QMenu>
|
2026-02-11 16:11:45 +08:00
|
|
|
|
#include <QFile>
|
2025-11-11 09:02:49 +08:00
|
|
|
|
#include "newheaddialog.h"
|
|
|
|
|
|
#include "formhead.h"
|
2026-02-04 15:30:08 +08:00
|
|
|
|
#include "qtcommonclass.h"
|
2025-11-11 09:02:49 +08:00
|
|
|
|
|
|
|
|
|
|
extern int g_iRows;
|
|
|
|
|
|
extern int g_iCols;
|
|
|
|
|
|
extern int g_iColsWidth;
|
|
|
|
|
|
extern int g_iRowsHight;
|
2025-11-12 16:56:33 +08:00
|
|
|
|
extern int g_iFixedWidth;
|
|
|
|
|
|
extern int g_iFixedHeight;
|
2026-02-06 15:30:26 +08:00
|
|
|
|
extern double g_dPixelPerCm;//每厘米像素数
|
2025-11-11 09:02:49 +08:00
|
|
|
|
|
|
|
|
|
|
FormMultiHeads::FormMultiHeads(QWidget *parent) :
|
|
|
|
|
|
QWidget(parent),
|
|
|
|
|
|
ui(new Ui::FormMultiHeads)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
2026-02-11 16:11:45 +08:00
|
|
|
|
//加载样式
|
|
|
|
|
|
loadStyle(":/qrc/qss/flatgray.css");
|
|
|
|
|
|
|
2025-11-11 09:02:49 +08:00
|
|
|
|
//-------------------------------------
|
2026-02-05 11:46:33 +08:00
|
|
|
|
// 强制使用Qt渲染引擎
|
|
|
|
|
|
//QApplication::setAttribute(Qt::AA_UseStyleSheetPropagationInWidgetStyles, true);
|
|
|
|
|
|
//取消全局样式表
|
|
|
|
|
|
// ui->tableWidget->setStyleSheet("");
|
|
|
|
|
|
// ui->tableWidget->setAutoFillBackground(true);
|
|
|
|
|
|
|
2025-11-11 09:02:49 +08:00
|
|
|
|
//ui->tableWidget->hide();
|
|
|
|
|
|
//隐藏网格线
|
|
|
|
|
|
ui->tableWidget->setShowGrid(false);
|
2026-02-05 11:46:33 +08:00
|
|
|
|
// //设置样式表,不显示竖直边框
|
|
|
|
|
|
// ui->tableWidget->setStyleSheet( "QTableView::item {border-left: 0px solid black;} \
|
|
|
|
|
|
// QTableView::item:selected {border-left: 0px solid black;}\
|
|
|
|
|
|
// QTableView::item {border-right: 0px solid black;} \
|
|
|
|
|
|
// QTableView::item:selected {border-right: 0px solid black;}");
|
2025-11-11 09:02:49 +08:00
|
|
|
|
//
|
2026-02-04 15:30:08 +08:00
|
|
|
|
ui->tableWidget->verticalHeader()->hide(); //行
|
|
|
|
|
|
ui->tableWidget->horizontalHeader()->hide(); //列
|
|
|
|
|
|
ui->tableWidget->verticalHeader()->setFixedWidth(0);//标题栏宽度
|
|
|
|
|
|
ui->tableWidget->horizontalHeader()->setFixedHeight(0);//标题栏高度
|
2025-11-11 09:02:49 +08:00
|
|
|
|
ui->tableWidget->setColumnCount(1); //动态设置列数
|
|
|
|
|
|
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);//最后一列铺满最后
|
|
|
|
|
|
//标题
|
|
|
|
|
|
QTableWidgetItem *headerItem = new QTableWidgetItem("");
|
|
|
|
|
|
ui->tableWidget->setHorizontalHeaderItem(0, headerItem);
|
|
|
|
|
|
//我们让一列也可以滑动
|
|
|
|
|
|
ui->tableWidget->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
|
|
|
|
|
|
ui->tableWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
|
|
|
|
|
// 设置右键菜单策略
|
|
|
|
|
|
ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotContextMenu(QPoint)));
|
|
|
|
|
|
// 在窗口构造函数中
|
|
|
|
|
|
//ui->tableWidget->installEventFilter(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FormMultiHeads::~FormMultiHeads()
|
|
|
|
|
|
{
|
|
|
|
|
|
delete ui;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-11 16:11:45 +08:00
|
|
|
|
void FormMultiHeads::loadStyle(const QString &qssFile)
|
|
|
|
|
|
{
|
|
|
|
|
|
//加载样式表
|
|
|
|
|
|
QString qss;
|
|
|
|
|
|
QFile file(qssFile);
|
|
|
|
|
|
if (file.open(QFile::ReadOnly)) {
|
|
|
|
|
|
//用QTextStream读取样式文件不用区分文件编码 带bom也行
|
|
|
|
|
|
QStringList list;
|
|
|
|
|
|
QTextStream in(&file);
|
|
|
|
|
|
//in.setCodec("utf-8");
|
|
|
|
|
|
while (!in.atEnd()) {
|
|
|
|
|
|
QString line;
|
|
|
|
|
|
in >> line;
|
|
|
|
|
|
list << line;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
|
|
qss = list.join("\n");
|
|
|
|
|
|
QString paletteColor = qss.mid(20, 7);
|
|
|
|
|
|
this->setPalette(QPalette(paletteColor));
|
|
|
|
|
|
//用时主要在下面这句
|
|
|
|
|
|
this->setStyleSheet(qss);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-11 09:02:49 +08:00
|
|
|
|
void FormMultiHeads::slotContextMenu(QPoint pos)
|
2026-02-06 15:30:26 +08:00
|
|
|
|
{
|
2026-02-04 15:30:08 +08:00
|
|
|
|
//
|
2026-02-05 16:14:09 +08:00
|
|
|
|
QString strMenu= "";
|
|
|
|
|
|
if(m_strHeadOrTail == "Head")
|
|
|
|
|
|
{
|
|
|
|
|
|
strMenu= "新建图头";
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
strMenu= "新建成果表";
|
|
|
|
|
|
}
|
2025-11-11 09:02:49 +08:00
|
|
|
|
QMenu menu(ui->tableWidget);
|
2026-02-05 16:14:09 +08:00
|
|
|
|
QAction *newAction = menu.addAction(strMenu);
|
2025-11-11 09:02:49 +08:00
|
|
|
|
// 弹出菜单
|
|
|
|
|
|
QAction *selectedAction = menu.exec(ui->tableWidget->mapToGlobal(pos));
|
|
|
|
|
|
if (selectedAction == newAction) {
|
|
|
|
|
|
NewHeadDialog *dlg = new NewHeadDialog(this);
|
|
|
|
|
|
//
|
|
|
|
|
|
dlg->setAttribute(Qt::WA_DeleteOnClose);//关闭时,自动删除窗口对象
|
|
|
|
|
|
int result = dlg->exec();//模态对话框
|
|
|
|
|
|
if (result == QDialog::Accepted) {
|
|
|
|
|
|
// 处理用户点击了确定按钮的逻辑
|
|
|
|
|
|
qDebug() << "Accepted=";
|
2026-02-06 15:30:26 +08:00
|
|
|
|
AddHead();
|
2025-11-11 09:02:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (result == QDialog::Rejected) {
|
|
|
|
|
|
// 处理用户点击了取消按钮的逻辑
|
|
|
|
|
|
qDebug() << "Rejected=";
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
// 处理其他情况的逻辑
|
|
|
|
|
|
qDebug() << "other=";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-02-04 15:30:08 +08:00
|
|
|
|
}
|
2025-11-11 09:02:49 +08:00
|
|
|
|
|
2026-02-06 15:30:26 +08:00
|
|
|
|
//添加图头
|
|
|
|
|
|
void FormMultiHeads::AddHead()
|
|
|
|
|
|
{
|
|
|
|
|
|
int rowcount = ui->tableWidget->rowCount(); //总行数
|
|
|
|
|
|
//增加1行
|
|
|
|
|
|
ui->tableWidget->setRowCount(rowcount+1);
|
|
|
|
|
|
//行标题
|
|
|
|
|
|
QTableWidgetItem *headerItem = new QTableWidgetItem("");
|
|
|
|
|
|
ui->tableWidget->setVerticalHeaderItem(rowcount, headerItem);
|
|
|
|
|
|
|
|
|
|
|
|
int colWidth = g_iCols*g_iColsWidth+g_iFixedWidth+8;
|
|
|
|
|
|
int rowHight = g_iRows*g_iRowsHight+g_iFixedHeight+8;
|
|
|
|
|
|
//设置行高度
|
|
|
|
|
|
ui->tableWidget->setRowHeight(rowcount, rowHight);
|
|
|
|
|
|
if(rowcount==0)
|
|
|
|
|
|
{
|
|
|
|
|
|
//设置列宽
|
|
|
|
|
|
ui->tableWidget->setColumnWidth(0, colWidth);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
int iWidth=ui->tableWidget->columnWidth(0);
|
|
|
|
|
|
if(iWidth<g_iCols*g_iColsWidth)//列宽变大,以最大列宽为准
|
|
|
|
|
|
{
|
|
|
|
|
|
//设置列宽
|
|
|
|
|
|
ui->tableWidget->setColumnWidth(0, colWidth);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//
|
|
|
|
|
|
QtCommonClass *qtCommon = new QtCommonClass(this);
|
|
|
|
|
|
QString strUuid = qtCommon->getUUid();
|
|
|
|
|
|
FormHead *widgetHead = new FormHead(this, strUuid);
|
|
|
|
|
|
widgetHead->Init(g_iRows, g_iCols);
|
|
|
|
|
|
ui->tableWidget->setCellWidget(rowcount, 0, widgetHead);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-09 11:26:15 +08:00
|
|
|
|
void FormMultiHeads::resizeItem(QString indexID, double colWidth, double rowHight, bool bDelete)
|
2026-02-04 15:30:08 +08:00
|
|
|
|
{
|
|
|
|
|
|
//
|
|
|
|
|
|
int rowCount = ui->tableWidget->rowCount();//总行数
|
|
|
|
|
|
for(int i=0; i<rowCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if( ui->tableWidget->cellWidget(i, 0) != nullptr )
|
|
|
|
|
|
{
|
|
|
|
|
|
auto myWidget = ui->tableWidget->cellWidget(i, 0);
|
|
|
|
|
|
if(myWidget)
|
|
|
|
|
|
{
|
|
|
|
|
|
//
|
|
|
|
|
|
FormHead *widgetHead = (FormHead*)myWidget;//获得widget
|
|
|
|
|
|
if(widgetHead)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(widgetHead->m_indexID == indexID)
|
|
|
|
|
|
{
|
2026-02-09 11:26:15 +08:00
|
|
|
|
if(bDelete)
|
2026-02-04 15:30:08 +08:00
|
|
|
|
{
|
2026-02-09 11:26:15 +08:00
|
|
|
|
//删除1行
|
|
|
|
|
|
ui->tableWidget->removeRow(i);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
//设置行高度
|
|
|
|
|
|
ui->tableWidget->setRowHeight(i, rowHight+8);
|
|
|
|
|
|
|
|
|
|
|
|
int iWidth=ui->tableWidget->columnWidth(0);
|
|
|
|
|
|
if(iWidth<colWidth+8)//列宽变大,以最大列宽为准
|
|
|
|
|
|
{
|
|
|
|
|
|
//设置列宽
|
|
|
|
|
|
ui->tableWidget->setColumnWidth(0, colWidth+8);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-04 15:30:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-11 09:02:49 +08:00
|
|
|
|
}
|
2026-02-05 18:02:39 +08:00
|
|
|
|
|
2026-02-06 15:30:26 +08:00
|
|
|
|
QJsonArray FormMultiHeads::makeJsonArray()
|
2026-02-05 18:02:39 +08:00
|
|
|
|
{
|
2026-02-06 15:30:26 +08:00
|
|
|
|
//列宽
|
|
|
|
|
|
double colWidth = ui->tableWidget->columnWidth(0)/g_dPixelPerCm;
|
|
|
|
|
|
double rowHeight = 0;
|
2026-02-05 18:02:39 +08:00
|
|
|
|
|
|
|
|
|
|
// 创建JSON数组并填充数据
|
|
|
|
|
|
QJsonArray subcaseArray;
|
|
|
|
|
|
//
|
2026-02-06 15:30:26 +08:00
|
|
|
|
int rowCount = ui->tableWidget->rowCount();//总行数
|
|
|
|
|
|
for(int i=0; i<rowCount; i++)
|
2026-02-05 18:02:39 +08:00
|
|
|
|
{
|
2026-02-06 15:30:26 +08:00
|
|
|
|
//行高
|
|
|
|
|
|
rowHeight = ui->tableWidget->rowHeight(i)/g_dPixelPerCm;
|
|
|
|
|
|
|
2026-02-05 18:02:39 +08:00
|
|
|
|
QJsonObject formHeadObj;
|
|
|
|
|
|
formHeadObj["id"] = i;
|
2026-02-06 15:30:26 +08:00
|
|
|
|
formHeadObj["colWidth"] = colWidth;
|
|
|
|
|
|
formHeadObj["rowHeight"] = rowHeight;
|
|
|
|
|
|
|
2026-02-05 18:02:39 +08:00
|
|
|
|
if( ui->tableWidget->cellWidget(i, 0) != nullptr )
|
|
|
|
|
|
{
|
|
|
|
|
|
auto myWidget = ui->tableWidget->cellWidget(i, 0);
|
|
|
|
|
|
FormHead *widgetHead = qobject_cast<FormHead*>(myWidget);
|
|
|
|
|
|
if(widgetHead)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject jobj = widgetHead->makeJson();
|
|
|
|
|
|
formHeadObj["headinfo"] = jobj;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
subcaseArray.append(formHeadObj);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 15:30:26 +08:00
|
|
|
|
return subcaseArray;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//展示所有图头/成果表
|
|
|
|
|
|
//Head代表图头, Tail代表成果表
|
|
|
|
|
|
void FormMultiHeads::DisplayHeads(QJsonArray headsArray, QString strHeadOrTail)
|
|
|
|
|
|
{
|
|
|
|
|
|
QtCommonClass *qtCommon = new QtCommonClass(this);
|
|
|
|
|
|
QMap<int, int> mapHeads;
|
|
|
|
|
|
double colWidth = 0;
|
|
|
|
|
|
double rowHeight = 0;
|
|
|
|
|
|
|
|
|
|
|
|
int id = 0;
|
|
|
|
|
|
int iCount = headsArray.size();
|
|
|
|
|
|
for(int i=0; i<iCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonValue headValue = headsArray[i];
|
|
|
|
|
|
|
|
|
|
|
|
QJsonObject headObj = headValue.toObject();
|
|
|
|
|
|
//
|
|
|
|
|
|
if (headObj.contains("id"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonValue value = headObj.value("id");
|
|
|
|
|
|
if (value.isDouble()) {
|
|
|
|
|
|
id = value.toInt();
|
|
|
|
|
|
qDebug() << "id:" << QString::number(id);
|
|
|
|
|
|
//
|
|
|
|
|
|
mapHeads.insert(id, i);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(int id=0; id<iCount; id++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(mapHeads.contains(id))
|
|
|
|
|
|
{
|
|
|
|
|
|
int iNum = mapHeads.value(id);
|
|
|
|
|
|
//按照id顺序,展示井
|
|
|
|
|
|
QJsonValue headValue = headsArray[iNum];
|
|
|
|
|
|
QJsonObject headObj = headValue.toObject();
|
|
|
|
|
|
//
|
|
|
|
|
|
if(id==0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (headObj.contains("colWidth"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonValue value = headObj.value("colWidth");
|
|
|
|
|
|
if (value.isDouble()) {
|
|
|
|
|
|
colWidth = value.toDouble();
|
|
|
|
|
|
qDebug() << "colWidth:" << QString::number(colWidth);
|
|
|
|
|
|
//设置列宽
|
|
|
|
|
|
ui->tableWidget->setColumnWidth(0, colWidth);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (headObj.contains("rowHeight"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonValue value = headObj.value("rowHeight");
|
|
|
|
|
|
if (value.isDouble()) {
|
|
|
|
|
|
rowHeight = value.toDouble();
|
|
|
|
|
|
qDebug() << "rowHeight:" << QString::number(rowHeight);
|
|
|
|
|
|
//设置行高度
|
|
|
|
|
|
ui->tableWidget->setRowHeight(id, rowHeight);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int rowcount = ui->tableWidget->rowCount(); //总行数
|
|
|
|
|
|
//增加1行
|
|
|
|
|
|
ui->tableWidget->setRowCount(rowcount+1);
|
|
|
|
|
|
//行标题
|
|
|
|
|
|
QTableWidgetItem *headerItem = new QTableWidgetItem("");
|
|
|
|
|
|
ui->tableWidget->setVerticalHeaderItem(rowcount, headerItem);
|
|
|
|
|
|
|
|
|
|
|
|
if (headObj.contains("headinfo"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonValue value = headObj.value("headinfo");
|
|
|
|
|
|
if (value.isObject()) {
|
|
|
|
|
|
QJsonObject headObjInfo = value.toObject();
|
|
|
|
|
|
//展示其中一行
|
|
|
|
|
|
int iCols = 0;
|
|
|
|
|
|
int iRows = 0;
|
|
|
|
|
|
//
|
|
|
|
|
|
if (headObjInfo.contains("iCols"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonValue value = headObjInfo.value("iCols");
|
|
|
|
|
|
if (value.isDouble()) {
|
|
|
|
|
|
iCols = value.toInt();
|
|
|
|
|
|
qDebug() << "iCols:" << QString::number(iCols);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//
|
|
|
|
|
|
if (headObjInfo.contains("iRows"))
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonValue value = headObjInfo.value("iRows");
|
|
|
|
|
|
if (value.isDouble()) {
|
|
|
|
|
|
iRows = value.toInt();
|
|
|
|
|
|
qDebug() << "iRows:" << QString::number(iRows);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
QString strUuid = qtCommon->getUUid();
|
|
|
|
|
|
FormHead *widgetHead = new FormHead(this, strUuid);
|
|
|
|
|
|
widgetHead->Init(iRows, iCols);
|
|
|
|
|
|
ui->tableWidget->setCellWidget(rowcount, 0, widgetHead);
|
|
|
|
|
|
//
|
|
|
|
|
|
widgetHead->updateJsonInfo(headObjInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-02-05 18:02:39 +08:00
|
|
|
|
}
|
2026-04-02 17:47:35 +08:00
|
|
|
|
|
|
|
|
|
|
//获取图头、结论的宽高,方便输出图
|
|
|
|
|
|
void FormMultiHeads::getTableSize(int &iWidth, int &iHight)
|
|
|
|
|
|
{
|
|
|
|
|
|
//获取可视视图大小 tableWidget
|
|
|
|
|
|
iHight = 0;
|
|
|
|
|
|
iWidth = 0;
|
|
|
|
|
|
for(int i=0; i<ui->tableWidget->rowCount(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
//高度
|
|
|
|
|
|
iHight += ui->tableWidget->rowHeight(i);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(int j=0; j<ui->tableWidget->columnCount(); j++)
|
|
|
|
|
|
{
|
|
|
|
|
|
//高度
|
|
|
|
|
|
iWidth += ui->tableWidget->columnWidth(j);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|