支持从json模板加载公式属性值
This commit is contained in:
parent
b5f6f2fec2
commit
0efee7bfd3
|
|
@ -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 <<" "<<strSlfName <<" "<<strWellName;
|
||||
QString computeCellResult = "";
|
||||
if(!strSlfName.isEmpty() &&
|
||||
!newFormulaText.isEmpty() &&
|
||||
newFormulaText.indexOf("=TABLE")>-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);
|
||||
|
|
|
|||
|
|
@ -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<int, int> 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 <<" "<<strSlfName <<" "<<strWellName;
|
||||
QString computeCellResult = "";
|
||||
if(!strSlfName.isEmpty() &&
|
||||
!strFormulaText.isEmpty() &&
|
||||
strFormulaText.indexOf("=TABLE")>-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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<int, int> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user