diff --git a/logPlus/PropertyWidget.cpp b/logPlus/PropertyWidget.cpp index e4be294..7020afc 100644 --- a/logPlus/PropertyWidget.cpp +++ b/logPlus/PropertyWidget.cpp @@ -2429,11 +2429,101 @@ void PropertyWidget::SlotPropertyChanged( QtProperty *pProperty, const QVariant m_item->setData(Qt::UserRole+5, strSlfName); m_item->setData(Qt::UserRole+6, strWellName); - //qDebug() << "公式->改变 " << newFormulaText <<" "<m_bRefresh=false; -// m_item->setText(newText); + //使用公式,组织数据 + //qDebug() << "公式->改变 " << newFormulaText <<" "<-1) + { + CMemRdWt mem; + if(mem.Open(strSlfName.toStdString().c_str(), CLogIO::modeRead)) { + computeCellResult = ComputeCell(mem, newFormulaText); + mem.Close(); + } + } + //文字显示 + m_formHead->m_bRefresh=false; + m_item->setText(computeCellResult); + } + else if("公式操作类型" == m_propertyData[pProperty]) + { + int temp = variant.value(); + m_item->setData(Qt::UserRole+7, temp); // 公式操作类型 + m_FormulaType = (FormualType)temp; + + //公式 + QString newFormulaText = ""; + QVariant vtFormula = m_item->data(Qt::UserRole+4); + if (vtFormula.isValid()) { + newFormulaText = vtFormula.toString(); + } + else + { + m_strFormulaText = ""; + } + + //slf名、井次名 + QString strSlfName = ""; + QVariant vtSlfName = m_item->data(Qt::UserRole+5); + if (vtSlfName.isValid()) { + strSlfName = vtSlfName.toString(); + } + else + { + strSlfName = ""; + } + // + QString strWellName = ""; + QVariant vtWellName = m_item->data(Qt::UserRole+6); + if (vtWellName.isValid()) { + strWellName = vtWellName.toString(); + } + else + { + strWellName = ""; + } + + //先判断公式有效性 + QString TableName,FieldName; + int DecNum,m_ValType=0; + QString RecNo; + bool isOk=false; + //float value; + ParseFormualInfos(newFormulaText,TableName,FieldName,RecNo,DecNum,isOk); + if (!isOk) + { + return; + } + + //使用公式,组织数据 + //qDebug() << "公式操作类型->改变 " << newFormulaText <<" "<-1) + { + CMemRdWt mem; + if(mem.Open(strSlfName.toStdString().c_str(), CLogIO::modeRead)) { + computeCellResult = ComputeCell(mem, newFormulaText); + mem.Close(); + } + } + //文字显示 + m_formHead->m_bRefresh=false; + m_item->setText(computeCellResult); } } else if(m_strCurrentProperty == PL_OBJECT_PROPERTY) // 频率统计图 @@ -3251,6 +3341,21 @@ void PropertyWidget::initHeadProperty(FormHead *formHead, QTableWidget *tableWid m_strFormulaText = ""; } + //公式操作类型 + QVariant vtFormula_type = m_item->data(Qt::UserRole+7); + if (vtFormula_type.isValid()) { + m_FormulaType = (FormualType)vtFormula_type.toInt(); + } + else + { + m_FormulaType = PropertyWidget::Compute; + } + + QStringList enumNames; + enumNames << tr("计算") << tr("连接")<=2) + { + isOK=false; + int k=0; + for (int i=0;i2 + }// end Cell + cs=sCompute; + + if (!isConcat) + { + cs=QString::number(dCompute,'f',ratin.toInt()); + bool isOk=false; + double tryDouble=cs.toDouble(&isOk); + if (isOk) + { +// if(tryDouble==0) cs=""; +// QRegExp reg("(\\.0*|0+)$"); +// cs=cs.replace(reg,""); + } + } + else { + int len=cs.length(); + if(len&&(cs.at(len-1)==sSplitBr.at(0)||cs.at(len-1)==sSplitSpace.at(0))) + { + cs=cs.remove(len-1,1); + } + } + if(GetFormualType() == PropertyWidget::ComputeSpace) { + if(cs.size()&&cs.at(0).isDigit()&&cs.toFloat()==0.0) cs=""; + } + else if(GetFormualType() == PropertyWidget::ComputeCLearZero) { + cs=toString(cs); + if(cs.size()&&cs.at(0).isDigit()&&cs.toFloat()==0.0) cs=""; + } + if(dec&&GetFormualType() == PropertyWidget::LetterAndNumber) cs=setdec(cs,dec,1); +// pCell->SetText(cs); + return cs; +} + +double PropertyWidget::ComputeValue(double d1,double d2,const QString &symbolTag) +{ + double value; + if (symbolTag == QString("+")) + { + value=d1 + d2; + } + + if(symbolTag == QString("-")) + { + value=d1 - d2; + } + + if(symbolTag == QString("*")) + { + value=d1 * d2; + } + + if(symbolTag == QString("/")) + { + value=d1 / d2; + } + + return value; +} + +double PropertyWidget::CanConvertToDouble(const QString &value,int ratin,bool &canOk) +{ + double dValue; + QString convertValue; + bool isOk; + + dValue=value.toDouble(&isOk); + if(isOk) + { + convertValue=QString::number(dValue,'f',ratin); + dValue=convertValue.toDouble(); + } + canOk=isOk; + return dValue; +} + +QStringList PropertyWidget::ReadFormulaValues(CMemRdWt &mem,const QStringList &formulaList) +{ + int count=formulaList.size(); + QString formual,slfTableValue; + QStringList values; + for (int i=0;i=0) + { + //读取数据 + char buf[513]; + memset(buf,0,513); + mem.GetTableFieldData(iIndex,colIndex-1,buf,recordNo); + if(strlen(buf)>512) + { + buf[512]=0; + } + fieldValue=toString(buf); + } + mem.CloseTable(iIndex); + return fieldValue; +} + +QString ReadWellMessageData3( CMemRdWt &logio ,int colIndex,int RecNo) +{ + QList tableData; + QString readResult; + QStringList rowData; + Slf_FILE_MESSAGE msg; + logio.GetFileMessage(msg); +// logio.Close(); + + + QList valueList; + //////////////////////////////////////1//////////////////////////////////// + QStringList partRow; + partRow <i) + { + rowList=valueList.at(i); + ////////////////////////////////////////////////////////////////////////// + for (int j=0;j=RecNo) + { + readResult=tableData[RecNo-1][colIndex-1]; + } + //readResult=tableData[RecNo][colIndex]; + + return readResult; +} + +QString PropertyWidget::ReadSlfTableValue(CMemRdWt &mem, const QString &formula) +{ + QString cs=""; + //if(mem.mFile) { + //if (!SLFFileName.isEmpty()) + { + QString TableName,FieldName; + int decNum,m_ValType=0; + bool isOk=false; + QString RecNo; + double value; + ParseFormualInfos(formula,TableName,FieldName,RecNo,decNum,isOk); + + if (!isOk) + { + return cs; + } + if (TableName == QString("QString")) + { +// if(FieldName.compare("SUM",Qt::CaseInsensitive)==0||FieldName.compare("AGE",Qt::CaseInsensitive)==0||FieldName.compare("FST",Qt::CaseInsensitive)==0||FieldName.compare("END",Qt::CaseInsensitive)==0) +// { +// if(m_FormulaPos<1) return "0"; +// int ncol=-1,nrow=-1; +// for (int i=0;i=0) +// { +// double val=0; +// for (int i=m_FormulaPos-1;itext.toDouble(); +// } +// if(FieldName.compare("AGE",Qt::CaseInsensitive)==0) { +// if((nrow-m_FormulaPos+1)>0) val=val/(nrow-m_FormulaPos+1); +// } +// cs=QString::number(val); +// } +// else cs="0"; +// } +// else cs=FieldName; + }else if (TableName == QString("测井信息表")) + { + QRegExp regNum("\\d+"); + int begin=regNum.indexIn(FieldName); + int end=regNum.lastIndexIn(FieldName); + int colIndex= FieldName.mid(begin,end-begin+1).toInt(); + int rec=RecNo.toInt(); + if(rec<1) rec=1; + cs=ReadLogWellMapFieldValue(mem,TableName,colIndex,rec); + + }else if(TableName=="CARD") + { + + //int i; + int iIndex=mem.OpenStream(FieldName.toStdString().c_str()); + if (iIndex>-1){ + int numrec=mem.GetStreamLength(iIndex); + if(numrec>0) { + int len=mem.GetStreamLength(iIndex); + char *buf=new char[len+1]; + DWORD lpb=0; + mem.ReadStream(iIndex,len,&lpb,buf); + buf[len]=0; + cs=buf; + delete buf; + } + mem.CloseStream(iIndex); + } + + m_ValType=1; + + } + else if(TableName=="Well_Message") + { + char buf[1000]; + //QStringList MsgFields; + QRegExp regNum("\\d+"); + int begin=regNum.indexIn(FieldName); + int end=regNum.lastIndexIn(FieldName); + int colIndex= FieldName.mid(begin,end-begin+1).toInt(); + int rec=RecNo.toInt(); + if(rec<1) rec=1; + cs=ReadWellMessageData3(mem,colIndex,rec); + m_ValType=1; + } + else + { + char buf[1000]; + int rec=1; + if(RecNo.compare("SUM",Qt::CaseInsensitive)==0||RecNo.compare("AGE",Qt::CaseInsensitive)==0) { + float yy=0; + double total=0; + int index=mem.OpenTable((char *)TableName.toStdString().c_str()); + if(index>-1) rec=mem.GetTableRecordCount(index); + else return "0"; + for(int i=0;i-1) rec=mem.GetTableRecordCount(index); + m_ValType=mem.GetTableFieldData( + index, + (char *)FieldName.toStdString().c_str(), + buf, + rec + ); + cs=buf; + } + else { + rec=RecNo.toInt(); + if(rec<1) rec=1; + float yy=0; + m_ValType=mem.GetTableFieldData( + (char *)TableName.toStdString().c_str(), + (char *)FieldName.toStdString().c_str(), + buf, + yy, + rec + ); + if(m_ValType==6) { + cs=buf; + } + else cs=QString::number(yy,'f',8); + } + } + value=cs.toDouble(&isOk); + if (isOk) + { + cs=QString::number(value+0.0001,'f',decNum); + } + } + return cs; +} + +PropertyWidget::FormualType PropertyWidget::GetFormualType() +{ + if (m_FormulaType == 0) + { + m_FormulaType=PropertyWidget::Compute; + } + return m_FormulaType; +} + +void PropertyWidget::ParseFormualInfos(const QString &formual, + QString &TableName, QString &FieldName, + QString &RecordNo, int &DecNum, bool &isSuccess) +{ + isSuccess=false; + QString Formula=formual; + int i0=Formula.indexOf("("); + if(i0<0) return ; + Formula=Formula.mid(i0+1); + int i1=Formula.indexOf(":");//TableName + if(i1<0) return ; + TableName=Formula.left(i1); + Formula=Formula.mid(i1+1); + int i2=Formula.indexOf(":");//FieldName + if(i2<0) i2=0; + FieldName=Formula.left(i2); + Formula=Formula.mid(i2+1); + int i3=Formula.indexOf(".");//Rec No + if(i3<0) i3=0; + QString Rec=Formula.left(i3); + Formula=Formula.mid(i3+1); + int i4=Formula.indexOf(")");//dec number + if(i4<0) i4=0; + QString Dec=Formula.left(i4); + RecordNo=Rec;//.toInt(); + if(RecordNo.isEmpty()) RecordNo="1"; + //保留小数位数 + DecNum=Dec.toInt(); + isSuccess=true; +} diff --git a/logPlus/PropertyWidget.h b/logPlus/PropertyWidget.h index c5bb415..5ed8dfe 100644 --- a/logPlus/PropertyWidget.h +++ b/logPlus/PropertyWidget.h @@ -106,7 +106,27 @@ public: PropertyWidget(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); ~PropertyWidget(); -private: +public: + typedef enum _FormualType + { + // 计算 + Compute=0, + // 连接 + Connect, + // 换行连接 + ConnectEnter, + // 换行连接显行线 + ConnectEnterRowLine, + // 空格连接 + ConnectSpace, + ComputeSpace, + ComputeCLearZero, + ComputeNODIGEqueSPACE, + TailConnectEnterRowLine, + LetterAndNumber + } FormualType; + +private: QtTreePropertyBrowser *m_pPropertyBrowser; QtVariantPropertyManager *m_pVariantManager; QtColorSchemeComboBoxPropertyManager * m_pColorSchemeManager; @@ -146,8 +166,12 @@ public: //图头, 图例宽高 double m_colWidth_Img = 1; double m_rowHeight_Img = 1; + //公式 QString m_strFormulaText = ""; + // 公式操作符类型 + FormualType m_FormulaType; + //图头, 行高、列宽 double m_colWidth = 1; double m_rowHeight = 1; @@ -186,10 +210,24 @@ public: void _CreateEnumPropertyItem(QString strGroup, QString strPropertyCaption, QVariant vtPropertyValue, QStringList listValue); QtProperty* _CreateColorSchemePropertyItem(QString strGroup, QString strPropertyCaption, QVariant vtPropertyValue, int nclr); + QtProperty* _CreateFormulaPropertyItem(QString strGroup, QString strPropertyCaption, QVariant vtPropertyValue); //读取图头公式 void ReadWellRoundDataToFormula(); + //获取表格的公式计算结果 + QString ComputeCell(CMemRdWt &mem, QString formulaStr); + double ComputeValue(double d1,double d2,const QString &symbolTag); + //解析公式字段 + QStringList ParseCellFormula(QString formulaStr, QStringList &symbolList, QStringList &reatinList); + double CanConvertToDouble(const QString &value,int ratin,bool &canOk); + QStringList ReadFormulaValues(CMemRdWt &mem,const QStringList &formulaList); + QString ReadSlfTableValue(CMemRdWt &mem, const QString &formula); + PropertyWidget::FormualType GetFormualType(); + void ParseFormualInfos(const QString &formual, + QString &TableName, QString &FieldName, + QString &RecordNo, int &DecNum, bool &isSuccess); + // void InitCurrentViewInfo(bool bAll = true); //初始化属性,清空 void initWidgetProperty(QString strUuid, int iScale); //可视解释整体属性 //井 diff --git a/logPlus/mainwindowcurve.cpp b/logPlus/mainwindowcurve.cpp index 31debfc..50f9e71 100644 --- a/logPlus/mainwindowcurve.cpp +++ b/logPlus/mainwindowcurve.cpp @@ -4349,6 +4349,8 @@ void MainWindowCurve::_slotExport(QPrinter &printer, int IsBmp, QString pngName, PropertyService()->initWidgetProperty(m_strUuid, m_iScale); //取消所有选中单元格 emit CallManage::getInstance()->sig_Raise(m_strUuid, "", "", "", "", 0, ""); + //取消其他表格的选中状态(图头、成果表) + emit CallManage::getInstance()->sig_UnSelectTableItem(""); //默认选中-竖屏 m_hvDraw->setChecked(true);