追加文字结论表格WORDS_RELUST数据的可视化

This commit is contained in:
jiayulong 2025-12-04 17:55:42 +08:00
parent 14649eee58
commit e884d9b00a
5 changed files with 271 additions and 28 deletions

View File

@ -12,9 +12,11 @@ class TransparentDraggableRect : public QObject
{
Q_OBJECT
public:
explicit TransparentDraggableRect(QMyCustomPlot *parentPlot, double minWidth = 1.0, QString strTitle = "")
explicit TransparentDraggableRect(QMyCustomPlot *parentPlot, QString strUuid="", double minWidth = 1.0, QString strTitle = "")
: QObject(parentPlot), mPlot(parentPlot), mstrTitle(strTitle), mMinWidth(minWidth)
{
m_strUuid = strUuid;
//
initRect();
}
@ -34,8 +36,8 @@ public:
//设置标题
void setTitle(QString strTitle){
mstrTitle = strTitle;
// mItemTitle->setText(mstrTitle);
// mPlot->replot();
mItemTitle->setText(mstrTitle);
mPlot->replot();
}
// 设置矩形范围
@ -50,6 +52,12 @@ public:
mPixmap->topLeft->setCoords(left_Low, lY1);
mPixmap->bottomRight->setCoords(right_Hight, lY2);
//mItemTitle->position->setCoords(0.5, 0.5);
// 设置父锚点,定位点
//mItemTitle->position->setParentAnchor(mRect->bottom);
mItemTitle->position->setCoords((mRect->topLeft->coords().x() + mRect->bottomRight->coords().x())/2,
(mRect->topLeft->coords().y() + mRect->bottomRight->coords().y())/2); // 设置文本在矩形中心位置
//mRect->topLeft->setCoords(left, mPlot->yAxis->range().upper);
//mRect->bottomRight->setCoords(right, mPlot->yAxis->range().lower);
@ -78,10 +86,13 @@ public:
// mRightHandle->deleteLater();
// mPixmap->deleteLater();
mPlot->m_mapDraggableRect.remove(m_strUuid);
mPlot->removeItem(mRect);
mPlot->removeItem(mLeftHandle);
mPlot->removeItem(mRightHandle);
mPlot->removeItem(mPixmap);
mPlot->removeItem(mItemTitle);
mPlot->replot();
this->deleteLater();
@ -129,19 +140,20 @@ private:
connect(mPlot, &QCustomPlot::mouseRelease, this, &TransparentDraggableRect::onMouseRelease);
mPixmap = new QCPItemPixmap(mPlot);
mPixmap->setPixmap(QPixmap(":/image/file.png")); // 设置图片
//mPixmap->setPixmap(QPixmap(":/image/file.png")); // 设置图片
mPixmap->setScaled(true, Qt::IgnoreAspectRatio); // 设置缩放方式
mPixmap->setLayer("overlay"); // 确保在最上层
// mItemTitle = new QCPItemText(mPlot);
// mItemTitle->setText(mstrTitle);
// //mItemTitle->setBrush(QBrush(Qt::red));
// mItemTitle->setFont(QFont("Arial", 12, QFont::Bold));
// mItemTitle->setColor(Qt::black);
// mItemTitle->setPositionAlignment(Qt::AlignTop | Qt::AlignHCenter);
mItemTitle = new QCPItemText(mPlot);
mItemTitle->setText(mstrTitle);
//mItemTitle->setBrush(QBrush(Qt::red));
mItemTitle->setFont(QFont("Arial", 12, QFont::Bold));
mItemTitle->setColor(Qt::black);
mItemTitle->setPositionAlignment(Qt::AlignTop | Qt::AlignHCenter);
mItemTitle->position->setType(QCPItemPosition::ptPlotCoords);
//mItemTitle->position->setType(QCPItemPosition::ptAxisRectRatio);
// mItemTitle->position->setCoords(0.5, 0);
// mItemTitle->setLayer("overlay");
mItemTitle->position->setCoords(0.5, 0);
mItemTitle->setLayer("overlay");
}
void updateHandles() {
@ -156,6 +168,7 @@ private:
mRightHandle->bottomRight->setParentAnchor(mRect->bottomRight);
mRightHandle->topLeft->setCoords(-5, 5); // 矩形大小
mRightHandle->bottomRight->setCoords(5, -5); // 矩形大小
}
private slots:
@ -276,7 +289,8 @@ private slots:
double proposedLeft = mDragStartRange.lower + dy;
// 确保不超出轴范围且不使宽度小于最小值
newRange.lower = qBound(
mPlot->xAxis->range().lower,
//mPlot->xAxis->range().lower,
getMyLower(),
proposedLeft,
mDragStartRange.upper - mMinWidth);
break;
@ -288,7 +302,8 @@ private slots:
newRange.upper = qBound(
mDragStartRange.lower + mMinWidth,
proposedRight,
mPlot->xAxis->range().upper);
getMyUpper());
//mPlot->xAxis->range().upper);
break;
}
case DragRect: {
@ -299,15 +314,24 @@ private slots:
newRange.upper = center + width/2;
// 检查是否超出轴范围
QCPRange axisRange = mPlot->xAxis->range();
if(newRange.lower < axisRange.lower) {
newRange.lower = axisRange.lower;
if(newRange.lower < getMyLower()) {
newRange.lower = getMyLower();
newRange.upper = newRange.lower + width;
}
else if(newRange.upper > axisRange.upper) {
newRange.upper = axisRange.upper;
else if(newRange.upper > getMyUpper()) {
newRange.upper = getMyUpper();
newRange.lower = newRange.upper - width;
}
// QCPRange axisRange = mPlot->xAxis->range();
// if(newRange.lower < axisRange.lower) {
// newRange.lower = axisRange.lower;
// newRange.upper = newRange.lower + width;
// }
// else if(newRange.upper > axisRange.upper) {
// newRange.upper = axisRange.upper;
// newRange.lower = newRange.upper - width;
// }
break;
}
default:
@ -362,6 +386,64 @@ private slots:
}
}
double getMyLower()
{
double dLower = mPlot->xAxis->range().lower;
double proposedLeft = mDragStartRange.lower;
TransparentDraggableRect *pDraggableRect =NULL;
{
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDraggableRect.begin();
while( it != mPlot->m_mapDraggableRect.end() )
{
if(it.key() == m_strUuid)
{
it++;
continue;
}
pDraggableRect = (TransparentDraggableRect*)it.value();
//
QCPRange tmpRange = pDraggableRect->getRange();
if(tmpRange.upper >= dLower && tmpRange.upper <= proposedLeft)
{
dLower = tmpRange.upper;
}
it++;
}
}
return dLower;
}
double getMyUpper()
{
double dUpper = mPlot->xAxis->range().upper;
double proposedRight = mDragStartRange.upper;
TransparentDraggableRect *pDraggableRect =NULL;
{
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDraggableRect.begin();
while( it != mPlot->m_mapDraggableRect.end() )
{
if(it.key() == m_strUuid)
{
it++;
continue;
}
pDraggableRect = (TransparentDraggableRect*)it.value();
//
QCPRange tmpRange = pDraggableRect->getRange();
if(tmpRange.lower <= dUpper && tmpRange.lower >= proposedRight)
{
dUpper = tmpRange.lower;
}
it++;
}
}
return dUpper;
}
private:
QMyCustomPlot *mPlot;
QCPItemRect *mRect;
@ -369,8 +451,9 @@ private:
QCPItemRect *mRightHandle;
QCPItemPixmap *mPixmap;
//QCPItemText *mItemTitle;
QString mstrTitle;
QCPItemText *mItemTitle;
QString mstrTitle="";
QString m_strUuid = "";
enum DragMode { DragNone, DragLeft, DragRight, DragRect };
DragMode mDragMode = DragNone;

View File

@ -271,7 +271,11 @@ void FormDraw::s_addWave(QString strUuid, QString strSlfName, QString strWellNam
void FormDraw::s_addTableLine(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName)
{
if(strLineName != "FRAC_HOLE.TABLE")
if(strLineName != "FRAC_HOLE.TABLE" || strLineName != "WORDS_RELUST")
{
}
else
{
return;
}
@ -327,6 +331,7 @@ void FormDraw::s_addTableLine(QString strUuid, QString strSlfName, QString strWe
if(strLineName == "FRAC_HOLE.TABLE")
{
//蝌蚪图
curv->mKedou = true;
//隐藏网格
curv->xAxis->grid()->setVisible(false);
@ -334,6 +339,12 @@ void FormDraw::s_addTableLine(QString strUuid, QString strSlfName, QString strWe
initTableLine(curv, strSlfName, strLineName);
}
else if(strLineName == "WORDS_RELUST")
{
//文字结论
initWords(curv, strSlfName, strLineName);
}
connect(curv, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(s_mouseWheel(QWheelEvent*)));
//
@ -1318,7 +1329,7 @@ void FormDraw::initTableLine(QMyCustomPlot *widget, QString strSlfName, QString
m_LeftVal = 0;
m_RightVal = 360;
m_RightVal = 90;
//隐藏刻度
widget->xAxis->setTicks(false);
widget->yAxis->setTicks(false);
@ -1344,6 +1355,120 @@ void FormDraw::initTableLine(QMyCustomPlot *widget, QString strSlfName, QString
}
void FormDraw::initWords(QMyCustomPlot *widget, QString strSlfName, QString strLineName)
{
int iMyWidth = widget->axisRect(0)->width();
float vmax = iMyWidth;
float vmin = 0;
widget->m_iX1 = vmin;
widget->m_iX2 = iMyWidth;
widget->m_iY1 = g_iY1;
widget->m_iY2 = g_iY2;
//
widget->xAxis->setRange(vmin, vmax);
widget->yAxis->setRange(g_iY1, g_iY2);
widget->axisRect()->setupFullAxesBox();
//
widget->xAxis->ticker()->setTickCount(10);//x个主刻度
widget->yAxis->ticker()->setTickCount(60);//y个主刻度
//对调XY轴在最前面设置
QCPAxis *yAxis = widget->yAxis;
QCPAxis *xAxis = widget->xAxis;
widget->xAxis = yAxis;
widget->yAxis = xAxis;
m_LeftVal = 0;
m_RightVal = 90;
//隐藏刻度
widget->xAxis->setTicks(false);
widget->yAxis->setTicks(false);
widget->xAxis2->setTicks(false);
widget->yAxis2->setTicks(false);
//
LoadFromSLF(widget, strSlfName, strLineName);
QString strAliasName = "";
QString strUnit = "";
QColor newlineColor=QColor(0,0,0);
double width=2;
QString strScaleType = "";
//道-对象
m_formTrack->Add(strSlfName, m_strWellName, m_strTrackName, strLineName, strAliasName, strUnit, newlineColor, width, m_RightVal, m_LeftVal, strScaleType, "tableObject");
}
bool FormDraw::LoadFromSLF(QMyCustomPlot *widget, QString strSlfName, QString strLineName)
{
QString FieldName="RESULT";
{
QString ss=strSlfName;
CMemRdWt *logio=new CMemRdWt();
if(ss==""||!logio->Open(ss.toStdString().c_str(),CSlfIO::modeRead))
{
delete logio;
// QMessageBox::information(NULL,"提示","SLF文件打开失败请检查",QMessageBox::Yes);
return false;
}
int iIndex=logio->OpenTable(strLineName.toStdString().c_str());
if(iIndex>-1) {
int len=logio->GetTableRecordLength(iIndex);
if(len<sizeof(WORDS_DATA)) len=sizeof(WORDS_DATA);
char*buf=new char[len+1];
WORDS_DATA *m_Result=(WORDS_DATA *)buf;
int count=logio->GetTableRecordCount(iIndex);
for(int i=0;i<count;i++) {
memset(m_Result,0,sizeof(WORDS_DATA));
logio->ReadTable(iIndex,i+1,m_Result);
// WelllogItem* item=AddItem(m_Result->StartDepth,m_Result->EndDepth);
// if(!item) continue;
// OGWordsResultItem* pResult = dynamic_cast<OGWordsResultItem*>(item);
logio->GetTableFieldData(iIndex,(char*)FieldName.toStdString().c_str(),m_Result->Words,i+1);
if(strstr(m_Result->Words,"$L")) {
char *s=strstr(m_Result->Words,"$L");
if(strstr(s+2,"$U")) {
char *p=strstr(s+1,"$U");
int len=p-s-2;
char buf1[100];
strncpy(buf1,s+2,len);
buf1[len]=0;
// pResult->SetLeftAndRightAlign(atoi(buf1));
// pResult->SetUpAndDownAlign(atoi(p+2));
}
else {
// pResult->SetLeftAndRightAlign(atoi(s+2));
}
*s=0;
}
else if(strstr(m_Result->Words,"$U")){
char *p=strstr(m_Result->Words,"$U");
// pResult->SetUpAndDownAlign(atoi(p+2));
*p=0;
}
// pResult->SetCharacters(m_Result->Words);
// pResult->fontColor=QColor(0,0,0,255);
// pResult->backgroundColor=QColor(255,255,255,255);
// pResult->wordfont.setFamily("黑体");
// pResult->wordfont.setPointSize(10);
//显示文本
widget->addTextToPlot(-m_Result->EndDepth, -m_Result->StartDepth, QString::fromLocal8Bit(m_Result->Words));
//widget->addTextToPlot(-2910, -2900, "你好");//QString(m_Result->Words)
}
logio->CloseTable(iIndex);
delete buf;
}
delete logio;
}
return true;
}
void FormDraw::CalcDipWidth(int nColumn,float *flWidth,float factor,int x1,int x2,float flHoriRatio)
{
float scale ;

View File

@ -133,6 +133,11 @@ public:
QString m_csCurveDDIR,m_csCurveDANG,m_csCurveGrad;
float m_LeftVal; //左刻度
float m_RightVal; //右刻度
//文字结论
void initWords(QMyCustomPlot *widget, QString strSlfName, QString strLineName);
bool LoadFromSLF(QMyCustomPlot *widget, QString strSlfName, QString strLineName);
signals:
//void sig_AddLine(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName);

View File

@ -2,6 +2,7 @@
#include "CallManage.h"
#include "geometryutils.h"
#include "TransparentDraggableRect.h"
#include "qtcommonclass.h"
//是否隐藏刻度
extern int g_iShow;
@ -230,14 +231,37 @@ void QMyCustomPlot::onAddRect()
void QMyCustomPlot::addImageToPlot(double left_Low, double right_Hight, const QString imagePath)
{
QtCommonClass *qtCommon = new QtCommonClass(this);
QString strUuid = qtCommon->getUUid();
// 在初始化代码中
TransparentDraggableRect *dragRect = new TransparentDraggableRect(this);
TransparentDraggableRect *dragRect = new TransparentDraggableRect(this, strUuid);
// 设置初始范围
dragRect->setRange(left_Low, right_Hight);
// 可选:设置颜色
dragRect->setColor(QColor(255, 100, 100, 80)); // 半透明红色
//最小宽度
dragRect->setMinWidth(5);
dragRect->setMinWidth(0.1);
m_mapDraggableRect[strUuid] = dragRect;
}
void QMyCustomPlot::addTextToPlot(double left_Low, double right_Hight, const QString strText)
{
QtCommonClass *qtCommon = new QtCommonClass(this);
QString strUuid = qtCommon->getUUid();
// 在初始化代码中
TransparentDraggableRect *dragRect = new TransparentDraggableRect(this, strUuid);
// 设置初始范围
dragRect->setRange(left_Low, right_Hight);
// 可选:设置颜色
dragRect->setColor(QColor(255, 100, 100, 80)); // 半透明红色
//最小宽度
dragRect->setMinWidth(0.1);
dragRect->setTitle(strText);
m_mapDraggableRect[strUuid] = dragRect;
}
void QMyCustomPlot::onResetZoom()

View File

@ -3,6 +3,7 @@
#include "qcustomplot.h"
#include "LogIO.h"
//#include "TransparentDraggableRect.h"
#include "QCPSizeHandleManager.h"
#pragma execution_character_set("utf-8")
@ -57,6 +58,9 @@ public:
QVector<double> m_y;
int m_iCurNum=0;
int m_iSplitNum=2000; //2000000; //2000;
QMap<QString, QObject*> m_mapDraggableRect;
public slots:
void slot_time();
@ -66,6 +70,8 @@ public:
void addRandomGraph(QVector<double> x, QVector<double> y, QString strSlfName, QString strLineName, QString strAliasName, QString strUnit,
double newLeftScale, double newRightScale, QString strScaleType, QColor newlineColor, double width, Qt::PenStyle lineStyle);
void addTextToPlot(double left_Low, double right_Hight, const QString strText);
public slots:
void s_LineClicked(int index);
void onResetZoom();