1.优化蝌蚪图,支持倾角类型的刻度。
2.测试自定义item,支持拖拉改变位置,大小
This commit is contained in:
parent
8bd033e8fe
commit
f78bed60d3
67
logPlus/QCPSizeHandle.cpp
Normal file
67
logPlus/QCPSizeHandle.cpp
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#include "QCPSizeHandle.h"
|
||||
|
||||
QCPSizeHandle::QCPSizeHandle(QCustomPlot *parentPlot)
|
||||
: QCPAbstractItem(parentPlot),
|
||||
position(createPosition(QLatin1String("position"))),
|
||||
mHovered(false)
|
||||
{
|
||||
// position->setType(QCPItemPosition::ptAbsolute);
|
||||
setBrush(QColor("#436EEE"));
|
||||
setHoveredBrush(QColor("#1C86EE"));
|
||||
setSelectedBrush(QColor("#3A5FCD"));
|
||||
setSize(8);
|
||||
}
|
||||
|
||||
QCPSizeHandle::~QCPSizeHandle()
|
||||
{
|
||||
}
|
||||
|
||||
void QCPSizeHandle::setBrush(const QBrush &brush)
|
||||
{
|
||||
mBrush = brush;
|
||||
}
|
||||
|
||||
void QCPSizeHandle::setSelectedBrush(const QBrush &brush)
|
||||
{
|
||||
mSelectedBrush = brush;
|
||||
}
|
||||
|
||||
void QCPSizeHandle::setHoveredBrush(const QBrush &brush)
|
||||
{
|
||||
mHoveredBrush = brush;
|
||||
}
|
||||
|
||||
void QCPSizeHandle::setSize(double size)
|
||||
{
|
||||
mSize = size;
|
||||
}
|
||||
|
||||
double QCPSizeHandle::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const
|
||||
{
|
||||
Q_UNUSED(details)
|
||||
if (onlySelectable && !mSelectable)
|
||||
return -1;
|
||||
|
||||
QPointF itemPos = position->pixelPosition();
|
||||
QRectF rect = QRectF(itemPos.x() - mSize * 0.5, itemPos.y() - mSize * 0.5, mSize, mSize);
|
||||
bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0;
|
||||
return rectDistance(rect, pos, filledRect);
|
||||
}
|
||||
|
||||
void QCPSizeHandle::draw(QCPPainter *painter)
|
||||
{
|
||||
QRectF rect(-mSize * 0.5, -mSize * 0.5, mSize, mSize);
|
||||
|
||||
painter->translate(position->pixelPosition());
|
||||
painter->setClipRect(rect);
|
||||
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(mainBrush());
|
||||
painter->drawRect(rect);
|
||||
}
|
||||
|
||||
QBrush QCPSizeHandle::mainBrush() const
|
||||
{
|
||||
return selected() ? mSelectedBrush : (mHovered ? mHoveredBrush : mBrush);
|
||||
}
|
||||
|
||||
35
logPlus/QCPSizeHandle.h
Normal file
35
logPlus/QCPSizeHandle.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include "qcustomplot.h"
|
||||
|
||||
class QCP_LIB_DECL QCPSizeHandle : public QCPAbstractItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QCPSizeHandle(QCustomPlot *parentPlot);
|
||||
~QCPSizeHandle();
|
||||
|
||||
void setBrush(const QBrush &brush);
|
||||
void setSelectedBrush(const QBrush &brush);
|
||||
void setHoveredBrush(const QBrush &brush);
|
||||
void setSize(double size);
|
||||
|
||||
virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const Q_DECL_OVERRIDE;
|
||||
virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
|
||||
|
||||
QBrush mainBrush() const;
|
||||
|
||||
QCPItemPosition * const position;
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
protected:
|
||||
QBrush mBrush;
|
||||
QBrush mSelectedBrush;
|
||||
QBrush mHoveredBrush;
|
||||
//bool mSelectable;
|
||||
double mSize;
|
||||
bool mHovered;
|
||||
|
||||
|
||||
};
|
||||
|
||||
89
logPlus/QCPSizeHandleManager.cpp
Normal file
89
logPlus/QCPSizeHandleManager.cpp
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
#include "QCPSizeHandleManager.h"
|
||||
|
||||
QCPSizeHandleManager::QCPSizeHandleManager(QCustomPlot *parentPlot)
|
||||
: QCPLayerable(parentPlot)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QCPSizeHandleManager::~QCPSizeHandleManager()
|
||||
{
|
||||
}
|
||||
|
||||
void QCPSizeHandleManager::addItem(QCPAbstractItem *item, bool showHandlesLines)
|
||||
{
|
||||
if (!item || mHandles.contains(item))
|
||||
return;
|
||||
|
||||
if (item->positions().size() < 2) // 要改变item的大小,最起码要两个位置
|
||||
return;
|
||||
|
||||
QList<QCPSizeHandle *> handles;
|
||||
foreach (auto *position, item->positions()) {
|
||||
handles.push_back(addHandleToPosition(position));
|
||||
}
|
||||
|
||||
ControlItemData data;
|
||||
data.showHandlesLines = showHandlesLines;
|
||||
data.handles = handles;
|
||||
mHandles.insert(item, data);
|
||||
}
|
||||
|
||||
void QCPSizeHandleManager::handleItemMove(QCPAbstractItem *item, const QPointF &delta)
|
||||
{
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
auto positions = item->positions();
|
||||
foreach (auto *position, positions)
|
||||
position->setPixelPosition(position->pixelPosition() + delta);
|
||||
}
|
||||
|
||||
void QCPSizeHandleManager::handleItemResize(QCPSizeHandle *sizeHandle, const QPointF &delta)
|
||||
{
|
||||
if (!sizeHandle)
|
||||
return;
|
||||
|
||||
auto *parentPosition = static_cast<QCPItemPosition *>(sizeHandle->position->parentAnchor());
|
||||
if (!parentPosition)
|
||||
return;
|
||||
|
||||
parentPosition->setPixelPosition(parentPosition->pixelPosition() + delta);
|
||||
}
|
||||
|
||||
QCPSizeHandle *QCPSizeHandleManager::addHandleToPosition(QCPItemPosition *position)
|
||||
{
|
||||
auto *handle = new QCPSizeHandle(mParentPlot);
|
||||
handle->position->setParentAnchor(position); // 设置QCPSizeHandle的父锚点为position
|
||||
handle->setVisible(false);
|
||||
handle->setLayer(QLatin1String("overlay"));
|
||||
return handle;
|
||||
}
|
||||
|
||||
void QCPSizeHandleManager::applyDefaultAntialiasingHint(QCPPainter *painter) const
|
||||
{
|
||||
applyAntialiasingHint(painter, mAntialiased, QCP::aeOther);
|
||||
}
|
||||
|
||||
void QCPSizeHandleManager::draw(QCPPainter *painter)
|
||||
{
|
||||
QMapIterator<QCPAbstractItem *, ControlItemData> i(mHandles);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
auto data = i.value();
|
||||
if (!data.showHandlesLines)
|
||||
continue;
|
||||
|
||||
painter->setPen(data.connectHandlePen);
|
||||
QVector<QPointF> lines;
|
||||
foreach (auto *handle, data.handles)
|
||||
lines.push_back(handle->position->pixelPosition());
|
||||
painter->drawLines(lines);
|
||||
// painter->drawPolyline(QPolygonF(lines));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
38
logPlus/QCPSizeHandleManager.h
Normal file
38
logPlus/QCPSizeHandleManager.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include "qcustomplot.h"
|
||||
#include "QCPSizeHandle.h"
|
||||
|
||||
struct ControlItemData {
|
||||
bool showHandlesLines;
|
||||
bool moveable;
|
||||
bool resizeable;
|
||||
QPen connectHandlePen;
|
||||
QList<QCPSizeHandle*> handles;
|
||||
|
||||
//ControlItemData();
|
||||
};
|
||||
|
||||
class QCP_LIB_DECL QCPSizeHandleManager : public QCPLayerable
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QCPSizeHandleManager(QCustomPlot *parent);
|
||||
~QCPSizeHandleManager();
|
||||
|
||||
void addItem(QCPAbstractItem *item, bool showHandlesLines = false);
|
||||
//void addItems(const QList<QCPAbstractItem *> items, bool showHandlesLines = false);
|
||||
|
||||
public slots:
|
||||
void handleItemMove(QCPAbstractItem *item, const QPointF &delta);
|
||||
void handleItemResize(QCPSizeHandle *sizeHandle, const QPointF &delta);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
QMap<QCPAbstractItem *, ControlItemData> mHandles;
|
||||
|
||||
QCPSizeHandle *addHandleToPosition(QCPItemPosition *position);
|
||||
|
||||
virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE;
|
||||
virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ private slots:
|
|||
// }
|
||||
|
||||
void onMousePress(QMouseEvent *event) {
|
||||
if(event->button() != Qt::LeftButton)
|
||||
if(event->button() != Qt::LeftButton)//右键
|
||||
{
|
||||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());//x轴展示深度
|
||||
QCPRange currentRange = getRange();
|
||||
|
|
|
|||
|
|
@ -270,7 +270,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")
|
||||
{
|
||||
return;
|
||||
}
|
||||
//井名&道名不一致
|
||||
if(strUuid == m_strUuid && m_strWellName == strWellName && m_strTrackName == strTrackName)
|
||||
{
|
||||
|
|
@ -320,7 +324,16 @@ void FormDraw::s_addTableLine(QString strUuid, QString strSlfName, QString strWe
|
|||
// curv->setSizePolicy(policy);
|
||||
|
||||
curv->show();
|
||||
initTableLine(curv, strSlfName, strLineName);
|
||||
|
||||
if(strLineName == "FRAC_HOLE.TABLE")
|
||||
{
|
||||
curv->mKedou = true;
|
||||
//隐藏网格
|
||||
curv->xAxis->grid()->setVisible(false);
|
||||
curv->yAxis->grid()->setVisible(false);
|
||||
|
||||
initTableLine(curv, strSlfName, strLineName);
|
||||
}
|
||||
connect(curv, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(s_mouseWheel(QWheelEvent*)));
|
||||
|
||||
//
|
||||
|
|
@ -1087,6 +1100,7 @@ void FormDraw::initWave2(QMyCustomPlot *widget, QString strSlfName, QString strW
|
|||
logio->CloseWave(index);
|
||||
delete logio;
|
||||
|
||||
bool bFistValue=false;
|
||||
float vmax = (float)_nSamples;
|
||||
float vmin = 0;
|
||||
//
|
||||
|
|
@ -1107,6 +1121,12 @@ void FormDraw::initWave2(QMyCustomPlot *widget, QString strSlfName, QString strW
|
|||
continue;
|
||||
}
|
||||
//
|
||||
// if(bFistValue==false)
|
||||
// {
|
||||
// //最大值,最小值默认采用第一个有效值
|
||||
// bFistValue=true;
|
||||
// vmax = vmin = val;
|
||||
// }
|
||||
// if(vmax<val)vmax=val;
|
||||
// if(vmin>val)vmin=val;
|
||||
}
|
||||
|
|
@ -1183,13 +1203,15 @@ void FormDraw::initWave2(QMyCustomPlot *widget, QString strSlfName, QString strW
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//表格曲线
|
||||
void FormDraw::initTableLine(QMyCustomPlot *widget, QString strSlfName, QString strLineName)
|
||||
{
|
||||
m_Value=NULL;
|
||||
m_Value2=NULL;
|
||||
m_Value3=NULL;
|
||||
//m_csUnit = "(°)";
|
||||
m_bTableData=0;
|
||||
m_bTableData=0;//表格或曲线
|
||||
m_LeftVal2=0;
|
||||
m_RightVal2=360;
|
||||
//m_csCurveDDIR="DDIR";
|
||||
|
|
@ -1198,8 +1220,10 @@ void FormDraw::initTableLine(QMyCustomPlot *widget, QString strSlfName, QString
|
|||
m_nTailWidth=2;
|
||||
m_crTail=qRgb(0,0,0);
|
||||
m_crPointFill=qRgb(0,0,0);
|
||||
m_nRadius = 4;
|
||||
m_nTailLen = 8;
|
||||
|
||||
m_crGridSmall=qRgb(100,100,100);
|
||||
m_nRadius = 6;
|
||||
m_nTailLen = 10;
|
||||
m_nCircleWidth=1;
|
||||
m_flGrad1 = 10;
|
||||
m_flGrad2 = 50;
|
||||
|
|
@ -1213,39 +1237,69 @@ void FormDraw::initTableLine(QMyCustomPlot *widget, QString strSlfName, QString
|
|||
m_qsProperty=("ID");
|
||||
m_iPrecision = 3;
|
||||
//
|
||||
ReadFracDef();
|
||||
for (int i = 0 ; i < iFracType ; i++)
|
||||
// ReadFracDef();
|
||||
// for (int i = 0 ; i < iFracType ; i++)
|
||||
// {
|
||||
// m_bTypeDraw[i] = false;
|
||||
// }
|
||||
|
||||
if (m_bTableData)
|
||||
{
|
||||
m_bTypeDraw[i] = false;
|
||||
//
|
||||
m_qsDIR=("DDIR"); // 方位 曲线名
|
||||
m_qsDIP=("DANG");//倾角
|
||||
m_qsDepth="DEPT";
|
||||
m_qsID = "ID";
|
||||
ReadData(strSlfName, strLineName);
|
||||
|
||||
//------------------------
|
||||
// int nPointNum = m_FracTabList.count();
|
||||
// if ( nPointNum < 1 )return ;
|
||||
// FRAC_TABLE frac = m_FracTabList.at(0);
|
||||
}
|
||||
//
|
||||
m_qsDIR=("DDIR"); // 方位 曲线名
|
||||
m_qsDIP=("DANG");//倾角
|
||||
m_qsDepth="DEPT";
|
||||
m_qsID = "ID";
|
||||
ReadData(strSlfName, strLineName);
|
||||
|
||||
|
||||
//------------------------
|
||||
int nPointNum = m_FracTabList.count();
|
||||
if ( nPointNum < 1 )return ;
|
||||
FRAC_TABLE frac = m_FracTabList.at(0);
|
||||
|
||||
float vmax = -9999;
|
||||
float vmin = -9999;
|
||||
//最大值,最小值
|
||||
vmax=vmin=frac.DIR;
|
||||
|
||||
//slf文件读取曲线
|
||||
for(int i=0; i<nPointNum; i++)
|
||||
else
|
||||
{
|
||||
frac = m_FracTabList.at(i);
|
||||
if(vmax<frac.DIR)vmax=frac.DIR;
|
||||
if(vmin>frac.DIR)vmin=frac.DIR;
|
||||
//
|
||||
m_csCurveDDIR = "DDIR"; // 方位 曲线名
|
||||
m_csCurveDANG = "DANG";//倾角
|
||||
m_csCurveGrad = "GRAD";
|
||||
this->ReadData(strSlfName, m_csCurveDDIR, 0, &m_Curve);
|
||||
this->ReadData(strSlfName, m_csCurveDANG, 1, &m_Curve2);
|
||||
this->ReadData(strSlfName, m_csCurveGrad, 2, &m_Curve3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// bool bFistValue=false;
|
||||
// float vmax = -9999;
|
||||
// float vmin = -9999;
|
||||
// //最大值,最小值
|
||||
// vmax=vmin=frac.DIR;
|
||||
// //slf文件读取曲线
|
||||
// for(int i=0; i<nPointNum; i++)
|
||||
// {
|
||||
// frac = m_FracTabList.at(i);
|
||||
// if(frac.DIR==-9999)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// if(bFistValue==false)
|
||||
// {
|
||||
// //最大值,最小值默认采用第一个有效值
|
||||
// bFistValue=true;
|
||||
// vmax = vmin = frac.DIR;
|
||||
// }
|
||||
// if(vmax<frac.DIR)vmax=frac.DIR;
|
||||
// if(vmin>frac.DIR)vmin=frac.DIR;
|
||||
// }
|
||||
// widget->m_iX1 = vmin;
|
||||
// widget->m_iX2 = vmax;
|
||||
|
||||
int iMyWidth = widget->axisRect(0)->width();
|
||||
float vmax = iMyWidth;
|
||||
float vmin = 0;
|
||||
widget->m_iX1 = vmin;
|
||||
widget->m_iX2 = vmax;
|
||||
widget->m_iX2 = iMyWidth;
|
||||
widget->m_iY1 = g_iY1;
|
||||
widget->m_iY2 = g_iY2;
|
||||
//
|
||||
|
|
@ -1261,8 +1315,19 @@ void FormDraw::initTableLine(QMyCustomPlot *widget, QString strSlfName, QString
|
|||
QCPAxis *xAxis = widget->xAxis;
|
||||
widget->xAxis = yAxis;
|
||||
widget->yAxis = xAxis;
|
||||
|
||||
|
||||
m_LeftVal = 0;
|
||||
m_RightVal = 360;
|
||||
//
|
||||
DrawTabDip(widget);
|
||||
if (m_bTableData)
|
||||
{
|
||||
DrawTabDip(widget);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawDip(widget);
|
||||
}
|
||||
|
||||
QString strAliasName = "";
|
||||
QString strUnit = "";
|
||||
|
|
@ -1270,7 +1335,7 @@ void FormDraw::initTableLine(QMyCustomPlot *widget, QString strSlfName, QString
|
|||
double width=2;
|
||||
QString strScaleType = "";
|
||||
//道-对象
|
||||
m_formTrack->Add(strSlfName, m_strWellName, m_strTrackName, strLineName, strAliasName, strUnit, newlineColor, width, vmax, vmin, strScaleType, "tableObject");
|
||||
m_formTrack->Add(strSlfName, m_strWellName, m_strTrackName, strLineName, strAliasName, strUnit, newlineColor, width, m_RightVal, m_LeftVal, strScaleType, "tableObject");
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1292,9 +1357,161 @@ void FormDraw::CalcDipWidth(int nColumn,float *flWidth,float factor,int x1,int x
|
|||
}
|
||||
}
|
||||
|
||||
void FormDraw::DrawDip(QMyCustomPlot *widget)
|
||||
{
|
||||
float flWidth[50];
|
||||
int l;
|
||||
float dep;
|
||||
int m_nScaleThinGrid=10;
|
||||
// 计算位置
|
||||
int iMyWidth = widget->axisRect(0)->width();
|
||||
float x1 = 0;
|
||||
float x2 = iMyWidth;
|
||||
float x=0,y=0;
|
||||
int j=0,i=0,k=0;
|
||||
float flTemp=0;
|
||||
for(int i=0;i<50;i++) flWidth[i]=0;
|
||||
CalcDipWidth(m_nScaleThinGrid, flWidth, 1.2, x1, x2, 1.);
|
||||
|
||||
//绘制网格线,注意颜色、宽度属性
|
||||
QPen pPenStraightLine(m_crTail, m_nTailWidth);
|
||||
QPen pPenStraightLineSmall(m_crGridSmall, m_nTailWidth/2);
|
||||
for(i=0;i<m_nScaleThinGrid;i++)
|
||||
{
|
||||
if ( i == 0 ) x =1;
|
||||
else x = x1;
|
||||
x1 = x + flWidth[i];
|
||||
if ( (x1-x) <= 7) {
|
||||
l = 2; // 小于1厘米
|
||||
}
|
||||
else l = 5;
|
||||
for ( j=0; j<l; j++)
|
||||
{
|
||||
flTemp = (x + j*(x1 - x)/l);
|
||||
double dtick=flTemp;
|
||||
if(i==0&&j==0) continue;
|
||||
{
|
||||
QCPItemStraightLine *qcpItemLine = new QCPItemStraightLine(widget);
|
||||
qcpItemLine->point1->setCoords(-m_SDep, dtick);//位置
|
||||
qcpItemLine->point2->setCoords(-m_EDep, dtick);//位置
|
||||
if(j==0)
|
||||
{
|
||||
qcpItemLine->setPen(pPenStraightLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
qcpItemLine->setPen(pPenStraightLineSmall);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QPen pPen(m_crTail,m_nTailWidth);
|
||||
QBrush cBrushFill(m_crPointFill);
|
||||
|
||||
float flDepthScale,tempf,flVal;
|
||||
int nPointNum=0,tempi;
|
||||
QRectF rt,rtRect;
|
||||
float dgtord,dr;
|
||||
for(int i=0;i<50;i++) flWidth[i]=0;
|
||||
if(m_Value==0 || m_Value2==0)
|
||||
{
|
||||
Refurbish();
|
||||
}
|
||||
if ( m_Value==0 || m_Value2==0 )
|
||||
return ;
|
||||
|
||||
dgtord=3.14159265/180.;
|
||||
|
||||
CalcDipWidth(9, flWidth, 1.2, 0, iMyWidth, 1);
|
||||
|
||||
|
||||
while ( 1)
|
||||
{
|
||||
dep = m_SDep + k * m_Rlev;
|
||||
if ( dep >m_EDep )
|
||||
break;
|
||||
|
||||
if(dep<m_SDep)
|
||||
{
|
||||
k++;
|
||||
continue;
|
||||
}
|
||||
|
||||
i=(dep-m_Curve2.StartDepth)/m_Curve2.DepLevel+0.5;
|
||||
if(i<0)
|
||||
{
|
||||
k++;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
flVal = GetData(m_Curve2.RepCode,(char *)&m_Value2[i*m_Curve2.CodeLen]);//DANG
|
||||
if ( flVal > m_RightVal || flVal < m_LeftVal )
|
||||
{
|
||||
k++;
|
||||
continue;
|
||||
}
|
||||
|
||||
tempi = (int)( flVal /10.);
|
||||
|
||||
tempf = 0.;
|
||||
for (j=0; j<tempi; j++)
|
||||
{
|
||||
tempf += flWidth[j];
|
||||
}
|
||||
x = tempf + (flVal-tempi*10.)*(flWidth[j+1]/10.);
|
||||
y = -dep;//起始深度
|
||||
|
||||
|
||||
// pDC->setPen(pPen);// [5/22/2019 9:43 hxb]
|
||||
// rtRect.setLeft(x - GetLineWidth(pDC,m_nRadius));
|
||||
// rtRect.setRight(x + GetLineWidth(pDC,m_nRadius));
|
||||
// rtRect.setBottom(y +GetLineWidth(pDC,m_nRadius));
|
||||
// rtRect.setTop(y -GetLineWidth(pDC,m_nRadius));
|
||||
// pDC->setPen(PenCircle);
|
||||
// pDC->drawEllipse(rtRect.center(),m_nRadius,m_nRadius);
|
||||
|
||||
QCPItemEllipse *qcpItemEllipse = new QCPItemEllipse(widget);
|
||||
qcpItemEllipse->setPen(pPen);
|
||||
qcpItemEllipse->m_bCustom = true;
|
||||
qcpItemEllipse->m_nRadius = m_nRadius;
|
||||
qcpItemEllipse->topLeft->setCoords(y, x);//圆心位置
|
||||
qcpItemEllipse->bottomRight->setCoords(y, x);//圆心位置
|
||||
qcpItemEllipse->setBrush(cBrushFill);//填充圆的颜色
|
||||
|
||||
|
||||
//方位
|
||||
flVal = GetData(m_Curve.RepCode,(char *)&m_Value[i*m_Curve.CodeLen]);//DDIR
|
||||
dr=flVal*dgtord;
|
||||
// // 注意映射方式
|
||||
// x +=GetLineWidth(pDC,m_nRadius)*sin(dr);
|
||||
// y -=GetLineWidth(pDC,m_nRadius)*cos(dr);
|
||||
// float x1=x +GetLineWidth(pDC,m_nTailLen)*sin(dr);
|
||||
// float y1=y -GetLineWidth(pDC,m_nTailLen)*cos(dr);
|
||||
// pDC->setPen(pPen);
|
||||
// pDC->drawLine(QPointF(x,y),QPointF(x1,y1));
|
||||
QCPItemLine *qcpItemLine = new QCPItemLine(widget);
|
||||
qcpItemLine->start->setCoords(y, x);//圆心位置
|
||||
qcpItemLine->end->setCoords(y, x);//圆心位置
|
||||
qcpItemLine->setPen(pPen);
|
||||
qcpItemLine->m_bCustom = true;
|
||||
qcpItemLine->m_nTailLen = m_nTailLen; //尾长
|
||||
qcpItemLine->m_nRadius = m_nRadius; //半径
|
||||
qcpItemLine->m_dr = dr;
|
||||
|
||||
|
||||
//移动对象
|
||||
// widget->mSizeHandleManager->addItem(qcpItemEllipse, true);
|
||||
// widget->mSizeHandleManager->addItem(qcpItemLine, true);
|
||||
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
void FormDraw::DrawTabDip(QMyCustomPlot *widget)
|
||||
{
|
||||
float sdep,edep,flDepthScale,tempf,flVal;
|
||||
float flDepthScale,tempf,flVal;
|
||||
int i,j,n,nPointNum=0,tempi;
|
||||
QRectF rt,rtRect;
|
||||
float x,y;
|
||||
|
|
@ -1324,25 +1541,70 @@ void FormDraw::DrawTabDip(QMyCustomPlot *widget)
|
|||
int iMyHeight = widget->axisRect(0)->height(); //setSizeConstraintRect()
|
||||
qDebug() << "iMyWidth=" << QString::number(iMyWidth) << ", iMyHeight=" << QString::number(iMyHeight);
|
||||
|
||||
//-----------
|
||||
int l;
|
||||
float x1 = 0;
|
||||
float x2 = iMyWidth;
|
||||
float flTemp=0;
|
||||
for(int i=0;i<50;i++) flWidth[i]=0;
|
||||
int m_nScaleThinGrid=10;
|
||||
CalcDipWidth(m_nScaleThinGrid, flWidth, 1.2, x1, x2, 1.);
|
||||
//绘制网格线,注意颜色、宽度属性
|
||||
QPen pPenStraightLine(m_crTail, m_nTailWidth);
|
||||
QPen pPenStraightLineSmall(m_crGridSmall, m_nTailWidth/2);
|
||||
for(i=0;i<m_nScaleThinGrid;i++)
|
||||
{
|
||||
if ( i == 0 ) x =1;
|
||||
else x = x1;
|
||||
x1 = x + flWidth[i];
|
||||
if ( (x1-x) <= 7) {
|
||||
l = 2; // 小于1厘米
|
||||
}
|
||||
else l = 5;
|
||||
for ( j=0; j<l; j++)
|
||||
{
|
||||
flTemp = (x + j*(x1 - x)/l);
|
||||
double dtick=flTemp;
|
||||
if(i==0&&j==0) continue;
|
||||
{
|
||||
QCPItemStraightLine *qcpItemLine = new QCPItemStraightLine(widget);
|
||||
qcpItemLine->point1->setCoords(-g_iY2, dtick);//位置
|
||||
qcpItemLine->point2->setCoords(-g_iY1, dtick);//位置
|
||||
if(j==0)
|
||||
{
|
||||
qcpItemLine->setPen(pPenStraightLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
qcpItemLine->setPen(pPenStraightLineSmall);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CalcDipWidth(9,flWidth, 1.2, 0, iMyWidth, 1.);
|
||||
|
||||
n = m_FracDefList.count();
|
||||
for (i=0; i<nPointNum; i++)
|
||||
{
|
||||
frac = m_FracTabList.at(i);
|
||||
// if ( frac.DEP < -g_iY2 || frac.DEP > -g_iY1)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
bDraw = false;
|
||||
for (j=0; j<n; j++)
|
||||
{
|
||||
fd = m_FracDefList.at(j);
|
||||
// 裂缝描述表中未保存裂缝名称:
|
||||
//比较裂缝名称比较准确,代码更改,如果比较代码会引起不一致性
|
||||
if ( (int)(frac.ID) == fd.iCode )
|
||||
{
|
||||
bDraw = m_bTypeDraw[j];//fd.bDraw;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// bDraw = false;
|
||||
// for (j=0; j<n; j++)
|
||||
// {
|
||||
// fd = m_FracDefList.at(j);
|
||||
// // 裂缝描述表中未保存裂缝名称:
|
||||
// //比较裂缝名称比较准确,代码更改,如果比较代码会引起不一致性
|
||||
// if ( (int)(frac.ID) == fd.iCode )
|
||||
// {
|
||||
// bDraw = m_bTypeDraw[j];//fd.bDraw;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//if ( bDraw )
|
||||
{
|
||||
QBrush cBrush(fd.crColor);
|
||||
|
|
@ -1490,6 +1752,99 @@ void FormDraw::ReadFracDef()
|
|||
}
|
||||
}
|
||||
|
||||
void FormDraw::Refurbish()
|
||||
{
|
||||
// if we are in the valid range for the property
|
||||
// set the new property value
|
||||
// update the property
|
||||
// let the control know that the property has changed
|
||||
// if(this->m_bTableData)
|
||||
// {
|
||||
// this->ReadData();//read table
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this->ReadData(m_csCurveDDIR,0,&m_Curve);
|
||||
// this->ReadData(m_csCurveDANG,1,&m_Curve2);
|
||||
// this->ReadData(m_csCurveGrad,2,&m_Curve3);
|
||||
// }
|
||||
// redraw the control
|
||||
}
|
||||
|
||||
//曲线
|
||||
//read curve
|
||||
void FormDraw::ReadData(QString strSlfName, QString strLineName, int iCurve, Slf_CURVE *curve)
|
||||
{
|
||||
//
|
||||
if(strSlfName.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 读曲线数值
|
||||
CMemRdWt mrw;
|
||||
m_PointNum = 0 ;
|
||||
if ( iCurve== 0 )
|
||||
{
|
||||
if(m_Value) delete []m_Value;
|
||||
m_Value = 0;
|
||||
}
|
||||
if ( iCurve== 1 )
|
||||
{
|
||||
if(m_Value2) delete []m_Value2;
|
||||
m_Value2 = 0;
|
||||
}
|
||||
if ( iCurve== 2 )
|
||||
{
|
||||
if(m_Value3) delete []m_Value3;
|
||||
m_Value3 = 0;
|
||||
}
|
||||
DWORD byte;
|
||||
//CString wellname(sFilePath);
|
||||
if ( mrw.Open(strSlfName.toStdString().c_str()) ) // 打开井文件
|
||||
{
|
||||
int iIndex=mrw.OpenCurve(strLineName.toStdString().c_str());
|
||||
if (iIndex >= 0)
|
||||
{
|
||||
mrw.GetCurveInfo(iIndex,curve);
|
||||
if(curve->DepLevel==0) return;
|
||||
m_PointNum = (float)(fabs((curve->EndDepth - curve->StartDepth)/curve->DepLevel+0.5));
|
||||
m_SDep=curve->StartDepth;
|
||||
m_EDep=curve->EndDepth;
|
||||
m_Rlev=curve->DepLevel;
|
||||
|
||||
if ( iCurve== 0 )
|
||||
{
|
||||
m_Value=new char[m_PointNum*curve->CodeLen+4];
|
||||
if(m_Value)
|
||||
{
|
||||
byte = mrw.ReadCurve(iIndex,m_SDep,m_PointNum,(void *)m_Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( iCurve == 1 )
|
||||
{
|
||||
m_Value2=new char[m_PointNum*curve->CodeLen+4];
|
||||
if(m_Value2){
|
||||
byte = mrw.ReadCurve(iIndex,m_SDep,m_PointNum,(void *)m_Value2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Value3=new char[m_PointNum*curve->CodeLen+4];
|
||||
if(m_Value3){
|
||||
byte = mrw.ReadCurve(iIndex,m_SDep,m_PointNum,(void *)m_Value3);
|
||||
}
|
||||
}
|
||||
}
|
||||
mrw.CloseCurve(iIndex);
|
||||
}
|
||||
mrw.Close(); //关闭井文件
|
||||
}
|
||||
}
|
||||
|
||||
//表格
|
||||
//for table dip ,read FRAC_HOLE.TABLE
|
||||
void FormDraw::ReadData(QString strSlfName, QString strLineName)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -94,9 +94,12 @@ public:
|
|||
//表格曲线
|
||||
void initTableLine(QMyCustomPlot *widget, QString strSlfName, QString strLineName);
|
||||
void ReadFracDef();
|
||||
void ReadData(QString strSlfName, QString strLineName);
|
||||
void ReadData(QString strSlfName, QString strLineName);//表格
|
||||
void ReadData(QString strSlfName, QString strLineName, int iCurve, Slf_CURVE *curve);//曲线
|
||||
void DrawDip(QMyCustomPlot *widget);
|
||||
void DrawTabDip(QMyCustomPlot *widget);
|
||||
void CalcDipWidth(int nColumn,float *flWidth,float factor,int x1,int x2,float flHoriRatio);
|
||||
void Refurbish();
|
||||
|
||||
int m_PointNum;
|
||||
//
|
||||
|
|
@ -106,17 +109,18 @@ public:
|
|||
//CString m_csUnit;
|
||||
//
|
||||
Slf_CURVE m_Curve,m_Curve2,m_Curve3;
|
||||
char *m_Value2,*m_Value3;
|
||||
char *m_Value,*m_Value2,*m_Value3;
|
||||
// 以下变量需保存在模板里
|
||||
// 绘制时,方位/倾角/可信度曲线的深度、采样间隔应该一致
|
||||
//CString m_csCurveDDIR,m_csCurveDANG,m_csCurveGrad; // 方位/倾角/可信度 曲线名
|
||||
float m_LeftVal2,m_RightVal2;
|
||||
float m_flGrad1,m_flGrad2; // 可信度
|
||||
int m_bTableData;
|
||||
int m_bTableData;//表格或曲线
|
||||
QRectF m_Rect;
|
||||
float m_nRadius,m_nCircleWidth; // 半径,圆线宽度
|
||||
float m_nTailWidth,m_nTailLen; // 尾宽度、尾长
|
||||
QColor m_crPointFill,m_crTail,m_crCircle;
|
||||
QColor m_crGridSmall;
|
||||
//TabDip
|
||||
QString m_qsWellName,m_qsTable; //
|
||||
QString m_qsDepth,m_qsDIP,m_qsDIR,m_qsID,m_qsProperty; // 控制曲线
|
||||
|
|
@ -125,7 +129,10 @@ public:
|
|||
bool m_bTypeDraw[iFracType];
|
||||
bool m_bDrawValue;
|
||||
int m_iPrecision;//小数位数
|
||||
|
||||
float m_SDep,m_EDep,m_Rlev;
|
||||
QString m_csCurveDDIR,m_csCurveDANG,m_csCurveGrad;
|
||||
float m_LeftVal; //左刻度
|
||||
float m_RightVal; //右刻度
|
||||
signals:
|
||||
//void sig_AddLine(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName);
|
||||
|
||||
|
|
|
|||
|
|
@ -185,6 +185,11 @@ void FormTrack::s_addWave(QString strSlfName, QString strWellName, QString strTr
|
|||
|
||||
void FormTrack::s_AddTableLine(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, QString strAliasName, QString strUnit, QColor lineColor, double dWidth, float vmax, float vmin, QString strScaleType)
|
||||
{
|
||||
if(strLineName != "FRAC_HOLE.TABLE")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "FormTrack s_AddTableLine";
|
||||
|
||||
ui->tableWidget->m_strUuid = m_strUuid;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ SOURCES += \
|
|||
InDefTableDlg.cpp \
|
||||
InterfaceWidget.cpp \
|
||||
PropertyWidget.cpp \
|
||||
QCPSizeHandle.cpp \
|
||||
QCPSizeHandleManager.cpp \
|
||||
backgrounddelegate.cpp \
|
||||
customtabbar.cpp \
|
||||
customtabwidget.cpp \
|
||||
|
|
@ -66,6 +68,8 @@ HEADERS += \
|
|||
InDefTableDlg.h \
|
||||
InterfaceWidget.h \
|
||||
PropertyWidget.h \
|
||||
QCPSizeHandle.h \
|
||||
QCPSizeHandleManager.h \
|
||||
TransparentDraggableRect.h \
|
||||
backgrounddelegate.h \
|
||||
customtabbar.h \
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ QMyCustomPlot::QMyCustomPlot(QWidget *parent, QString strSlfName, QString strWel
|
|||
m_strTrackName = strTrackName;
|
||||
m_strLineName = strLineName;
|
||||
|
||||
mSizeHandleManager = new QCPSizeHandleManager(this);
|
||||
|
||||
setObjectName("QMyCustomPlot");
|
||||
//this->setOpenGl(true);//不开启,电脑不支持会卡
|
||||
|
|
@ -37,6 +38,8 @@ QMyCustomPlot::QMyCustomPlot(QWidget *parent, QString strSlfName, QString strWel
|
|||
// make bottom and left axes transfer their ranges to top and right axes:
|
||||
connect(xAxis, SIGNAL(rangeChanged(QCPRange)), xAxis2, SLOT(setRange(QCPRange)));
|
||||
connect(yAxis, SIGNAL(rangeChanged(QCPRange)), yAxis2, SLOT(setRange(QCPRange)));
|
||||
// 在自定义类中
|
||||
connect(this, SIGNAL(afterReplot()), this, SLOT(drawCustomElements()));
|
||||
|
||||
//关联信号槽
|
||||
//左刻度
|
||||
|
|
@ -62,17 +65,117 @@ QMyCustomPlot::QMyCustomPlot(QWidget *parent, QString strSlfName, QString strWel
|
|||
|
||||
}
|
||||
|
||||
//蝌蚪图,重绘网格线
|
||||
void QMyCustomPlot::drawCustomElements()
|
||||
{
|
||||
QCPPainter painter(this);
|
||||
|
||||
//if(!mKedou)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// 绘制自定义背景网格
|
||||
painter.setPen(QPen(QColor(220, 0, 0), 0, Qt::DotLine));
|
||||
for (int i=0; i<10; ++i) {
|
||||
double x = xAxis->range().lower + i*xAxis->range().size()/10.0;
|
||||
QPointF p1;
|
||||
QPointF p2;
|
||||
p1.setX(xAxis->coordToPixel(x));
|
||||
p1.setY(yAxis->coordToPixel(yAxis->range().lower));
|
||||
//
|
||||
p2.setX(xAxis->coordToPixel(x));
|
||||
p2.setY(yAxis->coordToPixel(yAxis->range().upper));
|
||||
//
|
||||
painter.drawLine(p1,p2);
|
||||
}
|
||||
|
||||
// 绘制自定义标记
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(QColor(255, 100, 100, 150));
|
||||
painter.drawEllipse(QPointF(xAxis->coordToPixel(5.0),
|
||||
yAxis->coordToPixel(0.5)), 20, 20);
|
||||
}
|
||||
|
||||
|
||||
void QMyCustomPlot::init(QString strName, QVector<double> xx, QVector<double> yy0)
|
||||
{
|
||||
//raise(); //置于上层显示
|
||||
}
|
||||
|
||||
//void QMyCustomPlot::mousePressEvent(QMouseEvent *event)
|
||||
//{
|
||||
// //qDebug() << "mousePress";
|
||||
// QCustomPlot::mousePressEvent(event);
|
||||
//}
|
||||
|
||||
void QMyCustomPlot::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
//qDebug() << "mousePress";
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
|
||||
if (auto *item = itemAt(event->pos(), true)) {
|
||||
emit mousePress(event); // 由于我们直接返回了,所以要负责将鼠标点击信号发送出去
|
||||
|
||||
// deselectAll();
|
||||
mMousePress = true;
|
||||
mLastPos = event->pos();
|
||||
item->setSelected(true);
|
||||
replot();
|
||||
return; // 如果点击的是一个item直接返回,不然QCustomPlot会把事件传递给其它的层对象(例如:轴矩形)
|
||||
}
|
||||
}
|
||||
|
||||
QCustomPlot::mousePressEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void QMyCustomPlot::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
QCustomPlot::mouseMoveEvent(event);
|
||||
|
||||
if (mMousePress) {
|
||||
auto items = selectedItems();
|
||||
|
||||
foreach (auto *item, items) {
|
||||
if (auto *sizeHandle = qobject_cast<QCPSizeHandle *>(item))
|
||||
{
|
||||
mSizeHandleManager->handleItemResize(sizeHandle, event->pos() - mLastPos); // 控制item缩放
|
||||
}
|
||||
else
|
||||
{
|
||||
mSizeHandleManager->handleItemMove(item, event->pos() - mLastPos); // 控制item移动
|
||||
}
|
||||
|
||||
}
|
||||
mLastPos = event->pos();
|
||||
replot();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 当前鼠标位置(像素坐标)
|
||||
//int x_pos = event->pos().x();
|
||||
int y_pos = event->pos().y();
|
||||
|
||||
// 像素坐标转成实际的x,y轴的坐标
|
||||
//float x_val = yAxis->pixelToCoord(x_pos);
|
||||
float y_val = xAxis->pixelToCoord(y_pos);
|
||||
emit CallManage::getInstance()->sig_MouseMove(m_strUuid, m_strWellName, m_strTrackName, 0-y_val);
|
||||
}
|
||||
}
|
||||
|
||||
void QMyCustomPlot::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (mMousePress) {
|
||||
mMousePress = false;
|
||||
if (auto *item = itemAt(event->pos(), true)) {
|
||||
emit mouseReleaseEvent(event); // 由于我们直接返回了,所以要负责将鼠标点击信号发送出去
|
||||
item->setSelected(false);
|
||||
replot();
|
||||
return;
|
||||
}
|
||||
}
|
||||
QCustomPlot::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
//槽函数,选中曲线
|
||||
void QMyCustomPlot::s_LineClicked(int index)
|
||||
{
|
||||
|
|
@ -904,20 +1007,20 @@ void QMyCustomPlot::s_ChangeFillMode(QString strUuid, QString strSlfName, QStrin
|
|||
}
|
||||
}
|
||||
|
||||
void QMyCustomPlot::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
// 当前鼠标位置(像素坐标)
|
||||
//int x_pos = event->pos().x();
|
||||
int y_pos = event->pos().y();
|
||||
//void QMyCustomPlot::mouseMoveEvent(QMouseEvent *event)
|
||||
//{
|
||||
// // 当前鼠标位置(像素坐标)
|
||||
// //int x_pos = event->pos().x();
|
||||
// int y_pos = event->pos().y();
|
||||
|
||||
// 像素坐标转成实际的x,y轴的坐标
|
||||
//float x_val = yAxis->pixelToCoord(x_pos);
|
||||
float y_val = xAxis->pixelToCoord(y_pos);
|
||||
// // 像素坐标转成实际的x,y轴的坐标
|
||||
// //float x_val = yAxis->pixelToCoord(x_pos);
|
||||
// float y_val = xAxis->pixelToCoord(y_pos);
|
||||
|
||||
emit CallManage::getInstance()->sig_MouseMove(m_strUuid, m_strWellName, m_strTrackName, 0-y_val);
|
||||
// emit CallManage::getInstance()->sig_MouseMove(m_strUuid, m_strWellName, m_strTrackName, 0-y_val);
|
||||
|
||||
QCustomPlot::mouseMoveEvent(event);
|
||||
}
|
||||
// QCustomPlot::mouseMoveEvent(event);
|
||||
//}
|
||||
|
||||
|
||||
void QMyCustomPlot::addRandomGraph(QVector<double> x, QVector<double> y, QString strSlfName, QString strLineName, QString strAliasName, QString strUnit,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "qcustomplot.h"
|
||||
#include "LogIO.h"
|
||||
#include "QCPSizeHandleManager.h"
|
||||
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
|
|
@ -17,7 +18,7 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
virtual void mouseMoveEvent(QMouseEvent *event);
|
||||
//virtual void mouseMoveEvent(QMouseEvent *event);
|
||||
|
||||
public:
|
||||
QString m_strUuid;
|
||||
|
|
@ -96,9 +97,20 @@ public slots:
|
|||
|
||||
void onAddRect();
|
||||
|
||||
//蝌蚪图重绘网格线
|
||||
void drawCustomElements();
|
||||
|
||||
public:
|
||||
//蝌蚪图重绘网格线
|
||||
bool mKedou = false;
|
||||
//
|
||||
bool mMousePress = false;
|
||||
QPoint mLastPos;
|
||||
QCPSizeHandleManager *mSizeHandleManager;
|
||||
virtual void mousePressEvent(QMouseEvent *event);
|
||||
virtual void mouseMoveEvent(QMouseEvent *event);
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
||||
virtual void contextMenuEvent(QContextMenuEvent *event);
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user