From 0efee7bfd33e0a875a0e14f9b8b2af089be2439f Mon Sep 17 00:00:00 2001 From: jiayulong Date: Mon, 22 Jun 2026 11:08:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=8Ejson=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=8A=A0=E8=BD=BD=E5=85=AC=E5=BC=8F=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logPlus/PropertyWidget.cpp | 28 +++--- logPlus/formhead.cpp | 166 ++++++++++++++++++++++++++++++++++-- logPlus/formhead.h | 4 +- logPlus/formmultiheads.cpp | 4 +- logPlus/formmultiheads.h | 2 +- logPlus/mainwindowcurve.cpp | 8 +- 6 files changed, 188 insertions(+), 24 deletions(-) diff --git a/logPlus/PropertyWidget.cpp b/logPlus/PropertyWidget.cpp index 7020afc..c75410d 100644 --- a/logPlus/PropertyWidget.cpp +++ b/logPlus/PropertyWidget.cpp @@ -2465,17 +2465,17 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant m_FormulaType = (FormualType)temp; //公式 - QString newFormulaText = ""; + QString strFormulaText = ""; QVariant vtFormula = m_item->data(Qt::UserRole+4); if (vtFormula.isValid()) { - newFormulaText = vtFormula.toString(); + strFormulaText = vtFormula.toString(); } else { - m_strFormulaText = ""; + strFormulaText = ""; } - //slf名、井次名 + //slf名 QString strSlfName = ""; QVariant vtSlfName = m_item->data(Qt::UserRole+5); if (vtSlfName.isValid()) { @@ -2485,7 +2485,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant { strSlfName = ""; } - // + //井次名 QString strWellName = ""; QVariant vtWellName = m_item->data(Qt::UserRole+6); if (vtWellName.isValid()) { @@ -2502,7 +2502,7 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant QString RecNo; bool isOk=false; //float value; - ParseFormualInfos(newFormulaText,TableName,FieldName,RecNo,DecNum,isOk); + ParseFormualInfos(strFormulaText,TableName,FieldName,RecNo,DecNum,isOk); if (!isOk) { return; @@ -2512,12 +2512,12 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant //qDebug() << "公式操作类型->改变 " << newFormulaText <<" "<-1) + !strFormulaText.isEmpty() && + strFormulaText.indexOf("=TABLE")>-1) { CMemRdWt mem; if(mem.Open(strSlfName.toStdString().c_str(), CLogIO::modeRead)) { - computeCellResult = ComputeCell(mem, newFormulaText); + computeCellResult = ComputeCell(mem, strFormulaText); mem.Close(); } } @@ -3362,7 +3362,15 @@ void PropertyWidget::initHeadProperty(FormHead *formHead, QTableWidget *tableWid _CreateVariantPropertyItem("单元格", "背景颜色", m_item->background().color(), QVariant::Color); - _CreateVariantPropertyItem("文本", "内容", item->text(), QVariant::String); + if(m_strFormulaText!="") + { + //使用公式内容 + _CreateVariantPropertyItem("文本", "内容", "", QVariant::String); + } + else + { + _CreateVariantPropertyItem("文本", "内容", item->text(), QVariant::String); + } _CreateVariantPropertyItem("文本", "字体", m_item->font(), QVariant::Font); //_CreateEnumPropertyItem("文本", "方向", 0, listDirection); _CreateVariantPropertyItem("文本", "字体颜色", m_item->foreground().color(), QVariant::Color); diff --git a/logPlus/formhead.cpp b/logPlus/formhead.cpp index 3d627c5..5790a32 100644 --- a/logPlus/formhead.cpp +++ b/logPlus/formhead.cpp @@ -12,6 +12,7 @@ #include "backgrounddelegate.h" #include "PropertyWidget.h" #include "geometryutils.h" +#include "qtprojectwidgets.h" //extern int g_iRows; //extern int g_iCols; @@ -25,6 +26,9 @@ int g_iFixedHeight=0;//30; int g_iColsWidth=100; int g_iRowsHight=40; extern double g_dPixelPerCm;//每厘米像素数 + +extern QtProjectWidgets *g_projectWidgets; //左侧工程区 + //画图头 FormHead::FormHead(QWidget *parent, QString indexID) : QWidget(parent), @@ -217,7 +221,7 @@ void FormHead::Init(int iRows, int iCols) } //更新 -void FormHead::updateJsonInfo(QJsonObject headObjInfo) +void FormHead::updateJsonInfo(QJsonObject headObjInfo, bool bMultiProject) { //展示其中一行 int iCols = 0; @@ -250,7 +254,7 @@ void FormHead::updateJsonInfo(QJsonObject headObjInfo) itemsArray = value.toArray(); //qDebug() << "tracksArray number:" << QString::number(itemsArray.size()); //展示所有单元格 - DisplayItems(itemsArray); + DisplayItems(itemsArray, bMultiProject); } } @@ -259,7 +263,7 @@ void FormHead::updateJsonInfo(QJsonObject headObjInfo) } //展示所有单元格 -void FormHead::DisplayItems(QJsonArray itemsArray) +void FormHead::DisplayItems(QJsonArray itemsArray, bool bMultiProject) { QMap mapItems; @@ -318,6 +322,7 @@ void FormHead::DisplayItems(QJsonArray itemsArray) //内容 if (itemObj.contains("text")) { + //暂时没有公式,可以先显示文字内容 QJsonValue value = itemObj.value("text"); if (value.isString()) { QString newText = value.toString(); @@ -415,6 +420,104 @@ void FormHead::DisplayItems(QJsonArray itemsArray) ChangHeadItemProperty(row, col, imagePath, colWidth_Img*g_dPixelPerCm, rowHeight_Img*g_dPixelPerCm); } + //公式 + QString strFormulaText = ""; + if (itemObj.contains("FormulaText")) + { + QJsonValue value = itemObj.value("FormulaText"); + if (value.isString()) { + strFormulaText = value.toString(); + //qDebug() << "FormulaText:" << strFormulaText; + item->setData(Qt::UserRole+4, strFormulaText); + } + } + + //slf名 + QString strSlfName = ""; + QString strWellName = ""; + //多井的打开工程,使用模板的井名和slf名 + if(bMultiProject) + { + if (itemObj.contains("SlfName")) + { + QJsonValue value = itemObj.value("SlfName"); + if (value.isString()) { + strSlfName = value.toString(); + //qDebug() << "SlfName:" << strSlfName; + item->setData(Qt::UserRole+5, strSlfName); + } + } + + //井次名 + if (itemObj.contains("WellName")) + { + QJsonValue value = itemObj.value("WellName"); + if (value.isString()) { + strWellName = value.toString(); + //qDebug() << "WellName:" << strWellName; + item->setData(Qt::UserRole+6, strWellName); + } + } + } + else + { + QString strLeft = g_projectWidgets->getLeftTreeString_Import(); + if(strLeft.length() > 0) + { + QStringList list = strLeft.split("#@@#");//QString字符串分割函数 + if (list.size() > 3) + { + strSlfName = list[0]; + strWellName = list[1]; + } + } + } + + //公式操作类型 + int iFormulaType = 0; + if (itemObj.contains("FormulaType")) + { + QJsonValue value = itemObj.value("FormulaType"); + if (value.isDouble()) { + iFormulaType = value.toInt(); + //qDebug() << "FormulaType:" << strWellName; + item->setData(Qt::UserRole+7, iFormulaType); + } + } + + if(strFormulaText!="") + { + PropertyService()->m_FormulaType = (PropertyWidget::FormualType)iFormulaType; + + //先判断公式有效性 + QString TableName,FieldName; + int DecNum,m_ValType=0; + QString RecNo; + bool isOk=false; + //float value; + PropertyService()->ParseFormualInfos(strFormulaText,TableName,FieldName,RecNo,DecNum,isOk); + if (!isOk) + { + return; + } + + //使用公式,组织数据 + //qDebug() << "公式操作类型->改变 " << newFormulaText <<" "<-1) + { + CMemRdWt mem; + if(mem.Open(strSlfName.toStdString().c_str(), CLogIO::modeRead)) { + computeCellResult = PropertyService()->ComputeCell(mem, strFormulaText); + mem.Close(); + } + } + //文字显示 + item->setText(computeCellResult); + } + //合并单元格 int rowSpan = 1; int colSpan = 1; @@ -557,6 +660,49 @@ QJsonObject FormHead::makeJson() my_rowHeight_Img = rowHeight_Img.toDouble(); } + //公式 + QString strFormulaText = ""; + QVariant vtFormula = item->data(Qt::UserRole+4); + if (vtFormula.isValid()) { + strFormulaText = vtFormula.toString(); + } + else + { + strFormulaText = ""; + } + + //slf名 + QString strSlfName = ""; + QVariant vtSlfName = item->data(Qt::UserRole+5); + if (vtSlfName.isValid()) { + strSlfName = vtSlfName.toString(); + } + else + { + strSlfName = ""; + } + //井次名 + QString strWellName = ""; + QVariant vtWellName = item->data(Qt::UserRole+6); + if (vtWellName.isValid()) { + strWellName = vtWellName.toString(); + } + else + { + strWellName = ""; + } + + //公式操作类型 + int iFormulaType = 0; + QVariant vtFormula_type = item->data(Qt::UserRole+7); + if (vtFormula_type.isValid()) { + iFormulaType = vtFormula_type.toInt(); + } + else + { + iFormulaType = 0; + } + //行高、列宽 my_colWidth = ui->tableWidget->columnWidth(col)/g_dPixelPerCm; my_rowHeight = ui->tableWidget->rowHeight(row)/g_dPixelPerCm; @@ -571,14 +717,24 @@ QJsonObject FormHead::makeJson() formHeadObj["colWidth_Img"] = my_colWidth_Img; formHeadObj["rowHeight_Img"] = my_rowHeight_Img; formHeadObj["backColor"] = item->background().color().name();//背景颜色 - formHeadObj["text"] = item->text(); + if(strFormulaText != "") + { + //使用公式计算文本 + formHeadObj["text"] = ""; + } + else{ + formHeadObj["text"] = item->text(); + } formHeadObj["Font"] = item->font().toString(); formHeadObj["FontColor"] = item->foreground().color().name(); formHeadObj["colWidth"] = my_colWidth; formHeadObj["rowHeight"] = my_rowHeight; formHeadObj["rowSpan"] = rowSpan; formHeadObj["columnSpan"] = columnSpan; - + formHeadObj["FormulaText"] = strFormulaText; + formHeadObj["SlfName"] = strSlfName; + formHeadObj["WellName"] = strWellName; + formHeadObj["FormulaType"] = iFormulaType; } subcaseArray.append(formHeadObj); } diff --git a/logPlus/formhead.h b/logPlus/formhead.h index 305d0ea..8795f78 100644 --- a/logPlus/formhead.h +++ b/logPlus/formhead.h @@ -43,9 +43,9 @@ public: void loadStyle(const QString &qssFile); void Init(int iRows, int iCols); //更新 - void updateJsonInfo(QJsonObject headObjInfo); + void updateJsonInfo(QJsonObject headObjInfo, bool bMultiProject); //展示所有单元格 - void DisplayItems(QJsonArray tracksArray); + void DisplayItems(QJsonArray tracksArray, bool bMultiProject); //图例 void ChangHeadItemProperty(int iRow, int iCol, QString imagePath, int colWidth, int rowHeight); diff --git a/logPlus/formmultiheads.cpp b/logPlus/formmultiheads.cpp index 732d670..9e4d456 100644 --- a/logPlus/formmultiheads.cpp +++ b/logPlus/formmultiheads.cpp @@ -242,7 +242,7 @@ QJsonArray FormMultiHeads::makeJsonArray() //展示所有图头/成果表 //Head代表图头, Tail代表成果表 -void FormMultiHeads::DisplayHeads(QJsonArray headsArray, QString strHeadOrTail) +void FormMultiHeads::DisplayHeads(QJsonArray headsArray, QString strHeadOrTail, bool bMultiProject) { QtCommonClass *qtCommon = new QtCommonClass(this); QMap mapHeads; @@ -343,7 +343,7 @@ void FormMultiHeads::DisplayHeads(QJsonArray headsArray, QString strHeadOrTail) widgetHead->Init(iRows, iCols); ui->tableWidget->setCellWidget(rowcount, 0, widgetHead); // - widgetHead->updateJsonInfo(headObjInfo); + widgetHead->updateJsonInfo(headObjInfo, bMultiProject); } } } diff --git a/logPlus/formmultiheads.h b/logPlus/formmultiheads.h index 24d6402..4a05175 100644 --- a/logPlus/formmultiheads.h +++ b/logPlus/formmultiheads.h @@ -37,7 +37,7 @@ public: //展示所有图头/成果表 //Head代表图头, Tail代表成果表 - void DisplayHeads(QJsonArray headsArray, QString strHeadOrTail); + void DisplayHeads(QJsonArray headsArray, QString strHeadOrTail, bool bMultiProject); //获取图头、结论的宽高,方便输出图 void getTableSize(int &iWidth, int &iHight); diff --git a/logPlus/mainwindowcurve.cpp b/logPlus/mainwindowcurve.cpp index 50f9e71..e30962b 100644 --- a/logPlus/mainwindowcurve.cpp +++ b/logPlus/mainwindowcurve.cpp @@ -4445,10 +4445,10 @@ void MainWindowCurve::_slotExport(QPrinter &printer, int IsBmp, QString pngName, QString strHeadOrTail = ""; //Head代表图头, Tail代表成果表 //展示所有图头 strHeadOrTail = "Head"; //Head代表图头, Tail代表成果表 - m_formMultiHeads->DisplayHeads(m_headsArray, strHeadOrTail); + m_formMultiHeads->DisplayHeads(m_headsArray, strHeadOrTail, m_bMultiProject); //展示所有成果表 strHeadOrTail = "Tail"; //Head代表图头, Tail代表成果表 - m_formMultiTails->DisplayHeads(m_tailsArray, strHeadOrTail); + m_formMultiTails->DisplayHeads(m_tailsArray, strHeadOrTail, m_bMultiProject); //是否正在加载json g_iLoadingJson = 0; @@ -5148,10 +5148,10 @@ void MainWindowCurve::s_showHeadTable() QString strHeadOrTail = ""; //Head代表图头, Tail代表成果表 //展示所有图头 strHeadOrTail = "Head"; //Head代表图头, Tail代表成果表 - m_formMultiHeads->DisplayHeads(m_headsArray, strHeadOrTail); + m_formMultiHeads->DisplayHeads(m_headsArray, strHeadOrTail, m_bMultiProject); //展示所有成果表 strHeadOrTail = "Tail"; //Head代表图头, Tail代表成果表 - m_formMultiTails->DisplayHeads(m_tailsArray, strHeadOrTail); + m_formMultiTails->DisplayHeads(m_tailsArray, strHeadOrTail, m_bMultiProject); //是否正在加载json g_iLoadingJson = 0;