diff --git a/logPlus/TransparentDraggableRect.h b/logPlus/TransparentDraggableRect.h index 1d846c9..e4194bf 100644 --- a/logPlus/TransparentDraggableRect.h +++ b/logPlus/TransparentDraggableRect.h @@ -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->position->setType(QCPItemPosition::ptAxisRectRatio); -// mItemTitle->position->setCoords(0.5, 0); -// mItemTitle->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->position->setType(QCPItemPosition::ptPlotCoords); + //mItemTitle->position->setType(QCPItemPosition::ptAxisRectRatio); + mItemTitle->position->setCoords(0.5, 0); + mItemTitle->setLayer("overlay"); } void updateHandles() { @@ -155,7 +167,8 @@ private: mRightHandle->topLeft->setParentAnchor(mRect->bottomLeft); mRightHandle->bottomRight->setParentAnchor(mRect->bottomRight); mRightHandle->topLeft->setCoords(-5, 5); // 矩形大小 - mRightHandle->bottomRight->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::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::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,9 +451,10 @@ 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; //double mDragStartX = 0; diff --git a/logPlus/formdraw.cpp b/logPlus/formdraw.cpp index 139d7c2..1ee6a47 100644 --- a/logPlus/formdraw.cpp +++ b/logPlus/formdraw.cpp @@ -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(lenGetTableRecordCount(iIndex); + for(int i=0;iReadTable(iIndex,i+1,m_Result); +// WelllogItem* item=AddItem(m_Result->StartDepth,m_Result->EndDepth); +// if(!item) continue; +// OGWordsResultItem* pResult = dynamic_cast(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 ; diff --git a/logPlus/formdraw.h b/logPlus/formdraw.h index 97e57bf..d2ac0e7 100644 --- a/logPlus/formdraw.h +++ b/logPlus/formdraw.h @@ -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); diff --git a/logPlus/qmycustomplot.cpp b/logPlus/qmycustomplot.cpp index d9b07fa..1a998f4 100644 --- a/logPlus/qmycustomplot.cpp +++ b/logPlus/qmycustomplot.cpp @@ -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() diff --git a/logPlus/qmycustomplot.h b/logPlus/qmycustomplot.h index 6da6d23..b680622 100644 --- a/logPlus/qmycustomplot.h +++ b/logPlus/qmycustomplot.h @@ -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 m_y; int m_iCurNum=0; int m_iSplitNum=2000; //2000000; //2000; + + QMap m_mapDraggableRect; + public slots: void slot_time(); @@ -66,6 +70,8 @@ public: void addRandomGraph(QVector x, QVector 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();