1051 lines
32 KiB
C++
1051 lines
32 KiB
C++
#include "TransparentDraggableGeoLith.h"
|
||
#include "PropertyWidget.h"
|
||
#include "CallManage.h"
|
||
|
||
extern double g_dPixelPerCm;//每厘米像素数
|
||
//static GeoIndicatorGenerator m_drawGeo;
|
||
|
||
TransparentDraggableGeoLith::TransparentDraggableGeoLith(QMyCustomPlot *parentPlot, QString strUuid, double minWidth, QString strTitle)
|
||
: QObject(parentPlot), mPlot(parentPlot), mstrTitle(strTitle), mMinWidth(minWidth)
|
||
{
|
||
m_strUuid = strUuid;
|
||
//
|
||
initRect();
|
||
}
|
||
|
||
TransparentDraggableGeoLith::~TransparentDraggableGeoLith()
|
||
{
|
||
if(mPlot) {
|
||
// mPlot->removeItem(mRect);
|
||
// mPlot->removeItem(mLeftHandle);
|
||
// mPlot->removeItem(mRightHandle);
|
||
}
|
||
}
|
||
|
||
void TransparentDraggableGeoLith::DrawSVGNormal(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout)
|
||
{
|
||
QString svg=svgFileName;
|
||
QRectF boundingRect = painter->transform().mapRect(borderRect);
|
||
painter->save();
|
||
QTransform transform;
|
||
transform.reset();
|
||
if (!IsWellSectonHorizonLayout)
|
||
{
|
||
painter->setWorldTransform(transform);
|
||
}
|
||
else
|
||
{
|
||
}
|
||
QPixmap tiledmap(svg);
|
||
QRect border(boundingRect.left(),boundingRect.top(),boundingRect.width(),boundingRect.height());
|
||
painter->drawPixmap(border,tiledmap);
|
||
painter->restore();
|
||
}
|
||
//拉伸
|
||
void TransparentDraggableGeoLith::DrawSVGSteched(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout)
|
||
{
|
||
QString svg=svgFileName;
|
||
QSvgRenderer m_SvgRenderer;
|
||
m_SvgRenderer.load(svg);
|
||
m_SvgRenderer.render(painter,borderRect);
|
||
}
|
||
//平铺
|
||
void TransparentDraggableGeoLith::DrawSVGTiled(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout)
|
||
{
|
||
QString svg=svgFileName;
|
||
QRectF boundingRect = painter->transform().mapRect(borderRect);
|
||
painter->save();
|
||
QTransform transform;
|
||
transform.reset();
|
||
if (!IsWellSectonHorizonLayout)
|
||
{
|
||
painter->setWorldTransform(transform);
|
||
}
|
||
else
|
||
{
|
||
}
|
||
QPixmap tiledmap(svg);
|
||
painter->drawTiledPixmap(boundingRect,tiledmap);
|
||
painter->restore();
|
||
}
|
||
|
||
|
||
//设置最小宽度
|
||
void TransparentDraggableGeoLith::setMinWidth(double minWidth)
|
||
{
|
||
mMinWidth = minWidth;
|
||
}
|
||
|
||
//设置标题
|
||
void TransparentDraggableGeoLith::setTitle(QString strTitle)
|
||
{
|
||
mstrTitle = strTitle;
|
||
mItemTitle->setText(mstrTitle);
|
||
//mPlot->replot();
|
||
}
|
||
|
||
//设置解释结论
|
||
void TransparentDraggableGeoLith::setLith(QString filePath, QString colorPath)
|
||
{
|
||
m_Lith = filePath;
|
||
m_Color = colorPath;
|
||
|
||
//-----------------------------
|
||
int Color=0;
|
||
QString name,path;
|
||
GetWellNameAndPath(m_Color,name,path);
|
||
//
|
||
int ind=mPlot->ColorOrder.value(name).toInt();
|
||
if(ind<0||ind>=mPlot->ColorInds.size()) Color=0;
|
||
else Color=mPlot->ColorInds.key(QString::number(ind)).toInt();
|
||
//
|
||
mstrTitle = QString::number(Color);
|
||
}
|
||
|
||
void TransparentDraggableGeoLith::drawLith(double left_Low, double right_Hight, double lY1, double lY2)
|
||
{
|
||
if(m_Lith=="")
|
||
{
|
||
return;
|
||
}
|
||
|
||
double x1 = mPlot->xAxis->coordToPixel(left_Low)-1; //下边上移1像素-1
|
||
double x2 = mPlot->xAxis->coordToPixel(right_Hight)+1;//上边下移1像素+1
|
||
double y1 = 0;
|
||
if(mPlot->m_bShowOil)
|
||
{
|
||
if(mPlot->m_bShowColor || mPlot->m_bShowColorNum) // 绘制颜色号/显示颜色
|
||
{
|
||
if(mPlot->m_bCenterOil)//含油性居中
|
||
{
|
||
y1 = mPlot->yAxis->coordToPixel(lY1+(lY2-lY1)/mPlot->m_dOilZhan);
|
||
}
|
||
else
|
||
{
|
||
y1 = mPlot->yAxis->coordToPixel(lY1+2*(lY2-lY1)/mPlot->m_dOilZhan);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(mPlot->m_bCenterOil)//含油性居中
|
||
{
|
||
y1 = mPlot->yAxis->coordToPixel(lY1);
|
||
}
|
||
else
|
||
{
|
||
y1 = mPlot->yAxis->coordToPixel(lY1+(lY2-lY1)/mPlot->m_dOilZhan);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(mPlot->m_bShowColor || mPlot->m_bShowColorNum) // 绘制颜色号/显示颜色
|
||
{
|
||
//不绘制含油性
|
||
y1 = mPlot->yAxis->coordToPixel(lY1+(lY2-lY1)/mPlot->m_dOilZhan);
|
||
}
|
||
else
|
||
{
|
||
//不绘制含油性,左侧颜色
|
||
y1 = mPlot->yAxis->coordToPixel(lY1);
|
||
}
|
||
}
|
||
double y2 = mPlot->yAxis->coordToPixel(lY2);
|
||
double newWidth = y2-y1;
|
||
double newHeight = x1-x2;
|
||
|
||
//
|
||
QString filePath = m_Lith;
|
||
QString strLast = filePath.right(4);
|
||
if(strLast.toLower()==".svg")
|
||
{
|
||
QString path,filename;
|
||
GetWellNameAndPath(filePath, filename, path);
|
||
QString basename = filename;
|
||
|
||
QString val=filePath;
|
||
QImage image(newWidth, newHeight, QImage::Format_RGB32);
|
||
QPainter painter(&image);
|
||
QRectF fillRect(0,0,newWidth, newHeight);
|
||
painter.fillRect(fillRect,Qt::white);
|
||
|
||
//
|
||
if(mPlot->m_bLithColor)
|
||
{
|
||
//颜色
|
||
QString strLastColor = m_Color.right(4);
|
||
if(strLastColor.toLower()==".svg")
|
||
{
|
||
//拉伸
|
||
DrawSVGSteched(&painter,m_Color,fillRect,0);
|
||
}
|
||
}
|
||
//拉伸
|
||
DrawSVGSteched(&painter,filePath,fillRect,0);
|
||
|
||
val=GetImagePath()+"TempNew";
|
||
QDir ss;
|
||
if(!ss.exists(val)) {
|
||
ss.mkdir(val);
|
||
}
|
||
val+=QDir::separator();
|
||
val+=basename+".png";
|
||
image.save(val);
|
||
|
||
//
|
||
mPixmap_Lith->setPixmap(QPixmap(val)); // 设置图片
|
||
}
|
||
else
|
||
{
|
||
QString path,filename;
|
||
GetWellNameAndPath(filePath, filename, path);
|
||
QString basename = filename;
|
||
|
||
QString val=filePath;
|
||
QImage image(newWidth, newHeight, QImage::Format_RGB32);
|
||
QPainter painter(&image);
|
||
QRectF fillRect(0,0,newWidth, newHeight);
|
||
painter.fillRect(fillRect,Qt::white);
|
||
|
||
if(mPlot->m_bLithColor)
|
||
{
|
||
//颜色
|
||
QString strLastColor = m_Color.right(4);
|
||
if(strLastColor.toLower()==".svg")
|
||
{
|
||
//拉伸
|
||
DrawSVGSteched(&painter,m_Color,fillRect,0);
|
||
}
|
||
}
|
||
|
||
//
|
||
bool isOne=mPlot->m_bLithOne; //单岩性显示
|
||
bool isStech=true;
|
||
bool isHorizon=false;
|
||
float cm = g_dPixelPerCm;//一厘米对应的像素个数
|
||
QColor bkColor = QColor(255,255,255,0);
|
||
|
||
float GeoResult = m_drawGeo.seleGeo("岩性符号库", basename, &painter, fillRect, isOne, isStech, isHorizon, cm, bkColor);
|
||
|
||
val=GetImagePath()+"TempNew";
|
||
QDir ss;
|
||
if(!ss.exists(val)) {
|
||
ss.mkdir(val);
|
||
}
|
||
val+=QDir::separator();
|
||
val+=basename+".png";
|
||
image.save(val);
|
||
|
||
//
|
||
mPixmap_Lith->setPixmap(QPixmap(val)); // 设置图片
|
||
}
|
||
mPixmap_Lith->topLeft->setCoords(mPlot->xAxis->pixelToCoord(x2+1), mPlot->yAxis->pixelToCoord(y1+1));//right_Hight
|
||
mPixmap_Lith->bottomRight->setCoords(mPlot->xAxis->pixelToCoord(x1-1), mPlot->yAxis->pixelToCoord(y2-1));//left_Low
|
||
}
|
||
|
||
void TransparentDraggableGeoLith::drawColorLeft(double left_Low, double right_Hight, double lY1, double lY2)
|
||
{
|
||
//不显示
|
||
if(m_Color=="" || !mPlot->m_bShowColor)
|
||
{
|
||
mPixmap_Color->topLeft->setCoords(0, 0);//right_Hight
|
||
mPixmap_Color->bottomRight->setCoords(0, 0);//left_Low
|
||
return;
|
||
}
|
||
|
||
QString path,filename;
|
||
GetWellNameAndPath(m_Color, filename, path);
|
||
QString basename = filename;
|
||
|
||
double x1 = mPlot->xAxis->coordToPixel(left_Low)-1; //下边上移1像素-1
|
||
double x2 = mPlot->xAxis->coordToPixel(right_Hight)+1;//上边下移1像素+1
|
||
double y1 = mPlot->yAxis->coordToPixel(lY1);
|
||
double y2 = mPlot->yAxis->coordToPixel(lY1+(lY2-lY1)/mPlot->m_dOilZhan);
|
||
double newWidth = y2-y1;
|
||
double newHeight = x1-x2;
|
||
|
||
QString val="";
|
||
QImage image(newWidth, newHeight, QImage::Format_RGB32);
|
||
QPainter painter(&image);
|
||
QRectF fillRect(0,0,newWidth, newHeight);
|
||
painter.fillRect(fillRect,Qt::white);
|
||
|
||
//
|
||
if(mPlot->m_bShowColor)
|
||
{
|
||
//颜色
|
||
QString strLastColor = m_Color.right(4);
|
||
if(strLastColor.toLower()==".svg")
|
||
{
|
||
//拉伸
|
||
DrawSVGSteched(&painter,m_Color,fillRect,0);
|
||
}
|
||
}
|
||
//
|
||
val=GetImagePath()+"TempNew";
|
||
QDir ss;
|
||
if(!ss.exists(val)) {
|
||
ss.mkdir(val);
|
||
}
|
||
val+=QDir::separator();
|
||
val+=basename+".png";
|
||
image.save(val);
|
||
//
|
||
mPixmap_Color->setPixmap(QPixmap(val)); // 设置图片
|
||
|
||
mPixmap_Color->topLeft->setCoords(right_Hight, mPlot->yAxis->pixelToCoord(y1+1));//right_Hight
|
||
mPixmap_Color->bottomRight->setCoords(left_Low, mPlot->yAxis->pixelToCoord(y2-1));//left_Low
|
||
}
|
||
|
||
//设置m_Oil
|
||
void TransparentDraggableGeoLith::setOil(QString filePath)
|
||
{
|
||
m_Oil = filePath;
|
||
}
|
||
|
||
void TransparentDraggableGeoLith::drawOil(double left_Low, double right_Hight, double lY1, double lY2)
|
||
{
|
||
if(m_Oil=="" || !mPlot->m_bShowOil)
|
||
{
|
||
mPixmap_Oil->topLeft->setCoords(0, 0); //right_Hight, lY1
|
||
mPixmap_Oil->bottomRight->setCoords(0, 0); //left_Low
|
||
|
||
//含油2条线
|
||
m_qcpItemLine1->start->setCoords(0, 0);
|
||
m_qcpItemLine1->end->setCoords(0, 0);
|
||
//
|
||
m_qcpItemLine2->start->setCoords(0, 0);
|
||
m_qcpItemLine2->end->setCoords(0, 0);
|
||
return;
|
||
}
|
||
|
||
double x1 = mPlot->xAxis->coordToPixel(left_Low);
|
||
double x2 = mPlot->xAxis->coordToPixel(right_Hight);
|
||
double y1 = 0;
|
||
double y2 = 0;
|
||
if(mPlot->m_bShowColor || mPlot->m_bShowColorNum) // 绘制颜色号/显示颜色
|
||
{
|
||
y1 = mPlot->yAxis->coordToPixel(lY1+(lY2-lY1)/mPlot->m_dOilZhan);
|
||
y2 = mPlot->yAxis->coordToPixel(lY1+2*(lY2-lY1)/mPlot->m_dOilZhan);
|
||
}
|
||
else
|
||
{
|
||
y1 = mPlot->yAxis->coordToPixel(lY1);
|
||
y2 = mPlot->yAxis->coordToPixel(lY1+(lY2-lY1)/mPlot->m_dOilZhan);
|
||
}
|
||
|
||
bool bWidthBig = false;
|
||
double newWidth = y2-y1;
|
||
double newHeight = x1-x2;
|
||
if(newWidth>newHeight)
|
||
{
|
||
//取小,画正方形框
|
||
newWidth = newHeight;
|
||
bWidthBig = true;
|
||
}
|
||
|
||
float rect_xRight = x2 + newHeight/ 2 - newWidth/ 2;
|
||
double xNewRight = mPlot->xAxis->pixelToCoord(rect_xRight+1);
|
||
//
|
||
float rect_xLeft = rect_xRight + newWidth;
|
||
double xNewLeft = mPlot->xAxis->pixelToCoord(rect_xLeft-1);
|
||
|
||
//
|
||
QString filePath = m_Oil;
|
||
//
|
||
QString strLast = filePath.right(4);
|
||
if(strLast.toLower()==".svg")
|
||
{
|
||
QString path,filename;
|
||
GetWellNameAndPath(filePath, filename, path);
|
||
QString basename = filename;
|
||
|
||
QString val=filePath;
|
||
QImage image(newWidth, newWidth,QImage::Format_RGB32);
|
||
QPainter painter(&image);
|
||
QRectF fillRect(0,0, newWidth, newWidth);
|
||
painter.fillRect(fillRect,Qt::white);
|
||
//拉伸
|
||
DrawSVGSteched(&painter,filePath,fillRect,0);
|
||
//平铺
|
||
//DrawSVGTiled(&painter,filePath,fillRect,0);
|
||
//正常
|
||
//DrawSVGNormal(&painter,filePath,fillRect,0);
|
||
|
||
val=GetImagePath()+"TempNew";
|
||
QDir ss;
|
||
if(!ss.exists(val)) {
|
||
ss.mkdir(val);
|
||
}
|
||
val+=QDir::separator();
|
||
val+=basename+".png";
|
||
image.save(val);
|
||
|
||
//
|
||
mPixmap_Oil->setPixmap(QPixmap(val)); // 设置图片
|
||
}
|
||
else
|
||
{
|
||
mPixmap_Oil->setPixmap(QPixmap(filePath)); // 设置图片
|
||
}
|
||
|
||
if(mPlot->m_bCenterOil)//含油性居中
|
||
{
|
||
double yTmp1 = mPlot->yAxis->coordToPixel(lY1+ (lY2-lY1 -(lY2-lY1)/mPlot->m_dOilZhan) / 2.0);
|
||
double yTmp2 = mPlot->yAxis->coordToPixel(lY2- (lY2-lY1 -(lY2-lY1)/mPlot->m_dOilZhan) / 2.0);
|
||
|
||
mPixmap_Oil->topLeft->setCoords(xNewRight, mPlot->yAxis->pixelToCoord(yTmp1+1)); //right_Hight, lY1
|
||
mPixmap_Oil->bottomRight->setCoords(xNewLeft, mPlot->yAxis->pixelToCoord(yTmp2-2)); //left_Low
|
||
|
||
if(mPlot->m_bShowColor || mPlot->m_bShowColorNum) // 绘制颜色号/显示颜色
|
||
{
|
||
//颜色1条线
|
||
m_qcpItemLine1->start->setCoords(right_Hight, mPlot->yAxis->pixelToCoord(y1));
|
||
m_qcpItemLine1->end->setCoords(left_Low, mPlot->yAxis->pixelToCoord(y1));
|
||
//第2条隐藏
|
||
m_qcpItemLine2->start->setCoords(0, 0);
|
||
m_qcpItemLine2->end->setCoords(0, 0);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
mPixmap_Oil->topLeft->setCoords(xNewRight, mPlot->yAxis->pixelToCoord(y1+1)); //right_Hight, lY1
|
||
mPixmap_Oil->bottomRight->setCoords(xNewLeft, mPlot->yAxis->pixelToCoord(y2-2)); //left_Low
|
||
|
||
//含油2条线
|
||
m_qcpItemLine1->start->setCoords(right_Hight, mPlot->yAxis->pixelToCoord(y1));
|
||
m_qcpItemLine1->end->setCoords(left_Low, mPlot->yAxis->pixelToCoord(y1));
|
||
//
|
||
m_qcpItemLine2->start->setCoords(right_Hight, mPlot->yAxis->pixelToCoord(y2));
|
||
m_qcpItemLine2->end->setCoords(left_Low, mPlot->yAxis->pixelToCoord(y2));
|
||
|
||
}
|
||
|
||
//mPlot->replot();
|
||
}
|
||
|
||
// 设置矩形范围
|
||
void TransparentDraggableGeoLith::setRange(double left_Low, double right_Hight, bool bReplot)
|
||
{
|
||
if(left_Low >= right_Hight) return;
|
||
|
||
double lY1 = mPlot->yAxis->range().lower;//+10
|
||
double lY2 = mPlot->yAxis->range().upper;
|
||
|
||
//坐标转像素
|
||
double x1 = mPlot->xAxis->coordToPixel(left_Low);
|
||
double x2 = mPlot->xAxis->coordToPixel(right_Hight);
|
||
double left_Low2 = mPlot->xAxis->pixelToCoord(x1-2);
|
||
double right_Hight2 = mPlot->xAxis->pixelToCoord(x2+1);
|
||
|
||
mRect->topLeft->setCoords(left_Low, lY1);
|
||
mRect->bottomRight->setCoords(right_Hight, lY2);
|
||
|
||
//位置与rect不一样,否则图像反转
|
||
if(mPlot->m_bShowOil)
|
||
{
|
||
if(mPlot->m_bShowColor || mPlot->m_bShowColorNum) // 绘制颜色号/显示颜色
|
||
{
|
||
// 设置父锚点,定位点
|
||
if(mPlot->m_bShowColorNum)
|
||
{
|
||
mItemTitle->setText(mstrTitle);
|
||
}
|
||
else{
|
||
mItemTitle->setText("");
|
||
}
|
||
float flNewPos = mPlot->xAxis->coordToPixel((left_Low + right_Hight)/2.0) - 15;
|
||
mItemTitle->position->setCoords(mPlot->xAxis->pixelToCoord(flNewPos),
|
||
lY1+(lY2-lY1)/mPlot->m_dOilZhan/2);
|
||
}
|
||
else
|
||
{
|
||
mItemTitle->setText("");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(mPlot->m_bShowColor || mPlot->m_bShowColorNum) // 绘制颜色号/显示颜色
|
||
{
|
||
// 设置父锚点,定位点
|
||
if(mPlot->m_bShowColorNum)
|
||
{
|
||
mItemTitle->setText(mstrTitle);
|
||
}
|
||
else{
|
||
mItemTitle->setText("");
|
||
}
|
||
float flNewPos = mPlot->xAxis->coordToPixel((left_Low + right_Hight)/2.0) - 15;
|
||
mItemTitle->position->setCoords(mPlot->xAxis->pixelToCoord(flNewPos),
|
||
lY1+(lY2-lY1)/mPlot->m_dOilZhan/2);
|
||
}
|
||
else
|
||
{
|
||
mItemTitle->setText("");
|
||
}
|
||
}
|
||
//
|
||
drawLith(left_Low2, right_Hight2, lY1, lY2);
|
||
|
||
//位置与rect不一样,否则图像反转
|
||
drawOil(left_Low2, right_Hight2, lY1, lY2);
|
||
|
||
//左侧颜色
|
||
drawColorLeft(left_Low2, right_Hight2, lY1, lY2);
|
||
|
||
updateHandles();
|
||
|
||
//刷新,针对批量修改不在此处刷新,后面统一刷新
|
||
if(bReplot)
|
||
{
|
||
mPlot->replot();
|
||
}
|
||
}
|
||
|
||
// 获取当前范围
|
||
QCPRange TransparentDraggableGeoLith::getRange()
|
||
{
|
||
return QCPRange(mRect->topLeft->coords().x(), mRect->bottomRight->coords().x());
|
||
}
|
||
|
||
// 设置矩形颜色
|
||
void TransparentDraggableGeoLith::setColor(const QColor &color)
|
||
{
|
||
mRect->setBrush(QBrush(color));
|
||
mRect->setPen(QPen(color.darker()));
|
||
//mPlot->replot();
|
||
}
|
||
|
||
// 删除框图
|
||
void TransparentDraggableGeoLith::deleteRect()
|
||
{
|
||
if(mPlot) {
|
||
|
||
// mRect->deleteLater();
|
||
// mLeftHandle->deleteLater();
|
||
// mRightHandle->deleteLater();
|
||
// mPixmap->deleteLater();
|
||
|
||
mPlot->m_mapDraggable_GeoLith.remove(m_strUuid);
|
||
|
||
mPlot->removeItem(mRect);
|
||
mPlot->removeItem(mLeftHandle);
|
||
mPlot->removeItem(mRightHandle);
|
||
mPlot->removeItem(mPixmap_Lith);
|
||
mPlot->removeItem(mPixmap_Oil);
|
||
mPlot->removeItem(mPixmap_Color);
|
||
mPlot->removeItem(mItemTitle);
|
||
//含油2边
|
||
mPlot->removeItem(m_qcpItemLine1);
|
||
mPlot->removeItem(m_qcpItemLine2);
|
||
|
||
//mPlot->replot();
|
||
this->deleteLater();
|
||
|
||
//
|
||
// //避免二次绘制框图
|
||
// mPlot->m_bDrawRect = false;
|
||
// mDragMode = DragNone;
|
||
// //取消选中框
|
||
// mPlot->selectionRect()->cancel();
|
||
// mPlot->replot();
|
||
// mPlot->selectionRect()->mActive=true;
|
||
}
|
||
}
|
||
|
||
|
||
void TransparentDraggableGeoLith::initRect()
|
||
{
|
||
// 创建透明矩形
|
||
mRect = new QCPItemRect(mPlot);
|
||
mRect->setLayer("overlay"); // 确保在最上层
|
||
mRect->setBrush(QBrush(QColor(255, 255, 255, 50))); // 半透明蓝色100, 100, 255, 50
|
||
mRect->setPen(QPen(QColor(70, 70, 255, 200)));
|
||
|
||
// 创建左右边界控制点
|
||
mLeftHandle = new QCPItemRect(mPlot);
|
||
mLeftHandle->setLayer("overlay");
|
||
mLeftHandle->setBrush(QBrush(Qt::black));
|
||
mLeftHandle->setPen(QPen(Qt::black));
|
||
|
||
mRightHandle = new QCPItemRect(mPlot);
|
||
mRightHandle->setLayer("overlay");
|
||
mRightHandle->setBrush(QBrush(Qt::black));
|
||
mRightHandle->setPen(QPen(Qt::black));
|
||
|
||
// 设置初始位置
|
||
//double center = mPlot->xAxis->range().center();
|
||
// setRange(center - 10, center + 10);
|
||
|
||
// 连接鼠标事件
|
||
connect(mPlot, &QCustomPlot::mousePress, this, &TransparentDraggableGeoLith::onMousePress);
|
||
connect(mPlot, &QCustomPlot::mouseMove, this, &TransparentDraggableGeoLith::onMouseMove);
|
||
connect(mPlot, &QCustomPlot::mouseRelease, this, &TransparentDraggableGeoLith::onMouseRelease);
|
||
|
||
mPixmap_Lith = new QCPItemPixmap(mPlot);
|
||
//mPixmap->setPixmap(QPixmap(":/image/file.png")); // 设置图片
|
||
mPixmap_Lith->setScaled(true, Qt::IgnoreAspectRatio); // 设置缩放方式 KeepAspectRatio
|
||
mPixmap_Lith->setLayer("overlay"); // 确保在最上层
|
||
|
||
mPixmap_Oil = new QCPItemPixmap(mPlot);
|
||
//mPixmap_Oil->setPixmap(QPixmap(":/image/file.png")); // 设置图片
|
||
mPixmap_Oil->setScaled(true, Qt::IgnoreAspectRatio); // 设置缩放方式 KeepAspectRatio
|
||
mPixmap_Oil->setLayer("overlay"); // 确保在最上层
|
||
|
||
mPixmap_Color = new QCPItemPixmap(mPlot);
|
||
//mPixmap_Color->setPixmap(QPixmap(":/image/file.png")); // 设置图片
|
||
mPixmap_Color->setScaled(true, Qt::IgnoreAspectRatio); // 设置缩放方式 KeepAspectRatio
|
||
mPixmap_Color->setLayer("overlay"); // 确保在最上层
|
||
|
||
mItemTitle = new QCPItemText(mPlot);
|
||
mItemTitle->setText("");
|
||
//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");
|
||
|
||
//含油2边
|
||
m_qcpItemLine1 = new QCPItemLine(mPlot);
|
||
m_qcpItemLine1->setPen(QPen(QColor(0, 0, 0, 200)));
|
||
//
|
||
m_qcpItemLine2 = new QCPItemLine(mPlot);
|
||
m_qcpItemLine2->setPen(QPen(QColor(0, 0, 0, 200)));
|
||
|
||
}
|
||
|
||
void TransparentDraggableGeoLith::updateHandles()
|
||
{
|
||
// 左边界矩形控制点
|
||
mLeftHandle->topLeft->setParentAnchor(mRect->topLeft);
|
||
mLeftHandle->bottomRight->setParentAnchor(mRect->topRight);//(mRect->bottomLeft);
|
||
mLeftHandle->topLeft->setCoords(-0.5, 0.5); // 矩形大小
|
||
mLeftHandle->bottomRight->setCoords(0.5, -0.5); // 矩形大小
|
||
|
||
// 右边界矩形控制点
|
||
mRightHandle->topLeft->setParentAnchor(mRect->bottomLeft);
|
||
mRightHandle->bottomRight->setParentAnchor(mRect->bottomRight);
|
||
mRightHandle->topLeft->setCoords(-0.5, 0.5); // 矩形大小
|
||
mRightHandle->bottomRight->setCoords(0.5, -0.5); // 矩形大小
|
||
}
|
||
|
||
//分割
|
||
void TransparentDraggableGeoLith::onSplitRect()
|
||
{
|
||
QCPRange currentRange = getRange();
|
||
//分割后显示上半部分
|
||
setRange((currentRange.lower+currentRange.upper)/2.0, currentRange.upper);
|
||
|
||
//添加下半部分
|
||
mPlot->addGeoLithToPlot(currentRange.lower, (currentRange.lower+currentRange.upper)/2.0, m_Lith, m_Oil, m_Color);
|
||
|
||
//保存
|
||
mPlot->SaveToSLF_GeoLith();
|
||
|
||
//属性清空
|
||
PropertyService()->InitCurrentViewInfo();
|
||
|
||
//取消所有选中单元格
|
||
emit CallManage::getInstance()->sig_Raise(mPlot->m_strUuid, "", "", "", "", 0, "");
|
||
}
|
||
|
||
void TransparentDraggableGeoLith::onDelRect()
|
||
{
|
||
//mDragMode = DragNone;
|
||
//删除框图
|
||
deleteRect();
|
||
mPlot->replot();
|
||
//保存
|
||
mPlot->SaveToSLF_GeoLith();
|
||
//属性清空
|
||
PropertyService()->InitCurrentViewInfo();
|
||
}
|
||
|
||
//设置深度移动量
|
||
void TransparentDraggableGeoLith::setItemDepthOffset()
|
||
{
|
||
bool ok=0;
|
||
double depthshift=QInputDialog::getDouble(NULL,"深度移动","请输入移动的深度量(上移-,下移+)",0.0,-2147483647, 2147483647,4,&ok);
|
||
if(!ok) return;
|
||
|
||
QCPRange currentRange = getRange();
|
||
QCPRange newRange = currentRange;
|
||
|
||
newRange.lower = currentRange.lower-depthshift;
|
||
newRange.upper = currentRange.upper-depthshift;
|
||
|
||
//
|
||
double width = currentRange.size();
|
||
// //double center = mDragStartRange.center() + dx;
|
||
// double center = currentRange.center() - depthshift;
|
||
// newRange.lower = center - width/2;
|
||
// newRange.upper = center + width/2;
|
||
|
||
// 检查是否超出轴范围
|
||
if(newRange.lower < getMyLower()) {
|
||
return;
|
||
}
|
||
else if(newRange.upper > getMyUpper()) {
|
||
return;
|
||
}
|
||
//
|
||
setRange(newRange.lower, newRange.upper);
|
||
|
||
{
|
||
// double low = mRect->topLeft->coords().x();
|
||
// double hight = mRect->bottomRight->coords().x();
|
||
// PropertyService()->initGeoLithItemProperty(this, low, hight, m_Lith, m_Oil, m_Color);
|
||
|
||
//保存
|
||
mPlot->SaveToSLF_GeoLith();
|
||
|
||
//属性清空
|
||
PropertyService()->InitCurrentViewInfo();
|
||
|
||
//取消所有选中单元格
|
||
emit CallManage::getInstance()->sig_Raise(mPlot->m_strUuid, "", "", "", "", 0, "");
|
||
}
|
||
}
|
||
|
||
//设置顶深
|
||
void TransparentDraggableGeoLith::setUpper(double upper)
|
||
{
|
||
QCPRange currentRange = getRange();
|
||
QCPRange newRange = currentRange;
|
||
|
||
double proposedRight = upper;
|
||
// 确保不超出轴范围且不使宽度小于最小值
|
||
newRange.upper = qBound(
|
||
currentRange.lower + mMinWidth,
|
||
proposedRight,
|
||
getMyUpper());
|
||
|
||
// 最终确保宽度不小于最小值(针对整体拖动的情况)
|
||
if(newRange.size() < mMinWidth) {
|
||
newRange.upper = newRange.lower + mMinWidth;
|
||
}
|
||
|
||
setRange(newRange.lower, newRange.upper);
|
||
}
|
||
|
||
//设置底深
|
||
void TransparentDraggableGeoLith::setLower(double lower)
|
||
{
|
||
QCPRange currentRange = getRange();
|
||
QCPRange newRange = currentRange;
|
||
|
||
double proposedLeft = lower;
|
||
// 确保不超出轴范围且不使宽度小于最小值
|
||
newRange.lower = qBound(
|
||
getMyLower(),
|
||
proposedLeft,
|
||
currentRange.upper - mMinWidth);
|
||
|
||
// 最终确保宽度不小于最小值(针对整体拖动的情况)
|
||
if(newRange.size() < mMinWidth) {
|
||
// 如果是边界拖动,强制设置最小宽度
|
||
newRange.lower = newRange.upper - mMinWidth;
|
||
}
|
||
|
||
setRange(newRange.lower, newRange.upper);
|
||
}
|
||
|
||
void TransparentDraggableGeoLith::onMousePress(QMouseEvent *event)
|
||
{
|
||
if(event->button() != Qt::LeftButton)//右键
|
||
{
|
||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());//x轴展示深度
|
||
QCPRange currentRange = getRange();
|
||
if(mLeftHandle->selectTest(event->pos(), false) < 5) {
|
||
mDragMode = DragNone;
|
||
}
|
||
else if(mRightHandle->selectTest(event->pos(), false) < 5) {
|
||
mDragMode = DragNone;
|
||
}
|
||
//else if(x >= currentRange.lower && x <= currentRange.upper) {
|
||
else if(y >= currentRange.lower && y <= currentRange.upper) {
|
||
mDragMode = DragNone;
|
||
}
|
||
else {
|
||
mDragMode = DragNone;
|
||
return;
|
||
}
|
||
|
||
//event->accept();
|
||
|
||
double low = mRect->topLeft->coords().x();
|
||
double hight = mRect->bottomRight->coords().x();
|
||
PropertyService()->initGeoLithItemProperty(this, low, hight, m_Lith, m_Oil, m_Color);
|
||
|
||
QMenu menu(nullptr);
|
||
menu.addAction(QIcon(::GetImagePath() + "icon/Split.png"), "分割", this, &TransparentDraggableGeoLith::onSplitRect);
|
||
menu.addAction(QIcon(::GetImagePath() + "icon/Delete.png"), "删除选中对象", this, &TransparentDraggableGeoLith::onDelRect);
|
||
menu.addAction(QIcon(::GetImagePath() + "icon/Shift.png"), "设置深度移动量", this, &TransparentDraggableGeoLith::setItemDepthOffset);
|
||
menu.exec(event->globalPos());
|
||
|
||
return;
|
||
}
|
||
|
||
event->accept();
|
||
|
||
// 检查点击了哪个部分
|
||
//double x = mPlot->xAxis->pixelToCoord(event->pos().x());
|
||
//double y = mPlot->yAxis->pixelToCoord(event->pos().y());
|
||
|
||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());//x轴展示深度
|
||
|
||
QCPRange currentRange = getRange();
|
||
|
||
if(mLeftHandle->selectTest(event->pos(), false) < 5) {
|
||
mDragMode = DragLeft;
|
||
}
|
||
else if(mRightHandle->selectTest(event->pos(), false) < 5) {
|
||
mDragMode = DragRight;
|
||
}
|
||
//else if(x >= currentRange.lower && x <= currentRange.upper) {
|
||
else if(y >= currentRange.lower && y <= currentRange.upper) {
|
||
mDragMode = DragRect;
|
||
}
|
||
else {
|
||
mDragMode = DragNone;
|
||
return;
|
||
}
|
||
|
||
//mDragStartX = x;
|
||
mDragStartY = y;
|
||
mDragStartRange = currentRange;
|
||
|
||
}
|
||
|
||
int TransparentDraggableGeoLith::getCursor()
|
||
{
|
||
if (m_bMoveRect)
|
||
{
|
||
return 2;
|
||
}
|
||
if (m_bArrow)
|
||
{
|
||
return 1;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
void TransparentDraggableGeoLith::onMouseMove(QMouseEvent *event)
|
||
{
|
||
if (mDragMode == DragRect)
|
||
{
|
||
m_bMoveRect = true;
|
||
}
|
||
else if (mLeftHandle->selectTest(event->pos(), false) < 5
|
||
|| mRightHandle->selectTest(event->pos(), false) < 5)
|
||
{
|
||
m_bArrow = true;
|
||
m_bMoveRect = false;
|
||
}
|
||
else
|
||
{
|
||
m_bArrow = false;
|
||
m_bMoveRect = false;
|
||
}
|
||
|
||
//--------------------
|
||
if(mDragMode == DragNone) return;
|
||
|
||
event->accept();
|
||
|
||
//double x = mPlot->xAxis->pixelToCoord(event->pos().x());
|
||
//double dx = x - mDragStartX;
|
||
|
||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());
|
||
double dy = y - mDragStartY;
|
||
|
||
QCPRange newRange = mDragStartRange;
|
||
|
||
switch(mDragMode) {
|
||
case DragLeft: {
|
||
//double proposedLeft = mDragStartRange.lower + dx;
|
||
double proposedLeft = mDragStartRange.lower + dy;
|
||
// 确保不超出轴范围且不使宽度小于最小值
|
||
newRange.lower = qBound(
|
||
//mPlot->xAxis->range().lower,
|
||
getMyLower(),
|
||
proposedLeft,
|
||
mDragStartRange.upper - mMinWidth);
|
||
break;
|
||
}
|
||
case DragRight: {
|
||
//double proposedRight = mDragStartRange.upper + dx;
|
||
double proposedRight = mDragStartRange.upper + dy;
|
||
// 确保不超出轴范围且不使宽度小于最小值
|
||
newRange.upper = qBound(
|
||
mDragStartRange.lower + mMinWidth,
|
||
proposedRight,
|
||
getMyUpper());
|
||
//mPlot->xAxis->range().upper);
|
||
break;
|
||
}
|
||
case DragRect: {
|
||
double width = mDragStartRange.size();
|
||
//double center = mDragStartRange.center() + dx;
|
||
double center = mDragStartRange.center() + dy;
|
||
newRange.lower = center - width/2;
|
||
newRange.upper = center + width/2;
|
||
|
||
// 检查是否超出轴范围
|
||
if(newRange.lower < getMyLower()) {
|
||
newRange.lower = getMyLower();
|
||
newRange.upper = newRange.lower + width;
|
||
}
|
||
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:
|
||
break;
|
||
}
|
||
|
||
// //取整数(方便显示统计,左右边界整数显示。)
|
||
// newRange.lower = (int)newRange.lower;
|
||
// QCPRange rangeByFile = mPlot->xAxis->range();
|
||
// if (std::fabs(rangeByFile.upper - (int)newRange.upper) >= 1.0)
|
||
// {
|
||
// newRange.upper = (int)newRange.upper;
|
||
// }
|
||
|
||
// 最终确保宽度不小于最小值(针对整体拖动的情况)
|
||
if(newRange.size() < mMinWidth) {
|
||
if(mDragMode == DragRect) {
|
||
// 如果是整体拖动,保持中心点不变
|
||
double center = newRange.center();
|
||
newRange.lower = center - mMinWidth/2;
|
||
newRange.upper = center + mMinWidth/2;
|
||
} else {
|
||
// 如果是边界拖动,强制设置最小宽度
|
||
if(mDragMode == DragLeft) {
|
||
newRange.lower = newRange.upper - mMinWidth;
|
||
} else if(mDragMode == DragRight) {
|
||
newRange.upper = newRange.lower + mMinWidth;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//位置改变,鼠标拖动item
|
||
if(newRange.lower!= mDragStartRange.lower || newRange.upper!= mDragStartRange.upper)
|
||
{
|
||
m_bChange = true;
|
||
}
|
||
|
||
setRange(newRange.lower, newRange.upper);
|
||
|
||
}
|
||
|
||
void TransparentDraggableGeoLith::onMouseRelease(QMouseEvent *event)
|
||
{
|
||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||
event->accept();
|
||
//属性
|
||
{
|
||
double low = mRect->topLeft->coords().x();
|
||
double hight = mRect->bottomRight->coords().x();
|
||
PropertyService()->initGeoLithItemProperty(this, low, hight, m_Lith, m_Oil, m_Color);
|
||
if(m_bChange)
|
||
{
|
||
//保存
|
||
mPlot->SaveToSLF_GeoLith();
|
||
}
|
||
|
||
//取消所有选中单元格
|
||
emit CallManage::getInstance()->sig_Raise(mPlot->m_strUuid, "", "", "", "", 0, "");
|
||
}
|
||
|
||
//避免二次绘制框图
|
||
mPlot->m_bDrawRect = false;
|
||
//emit rangeChanged(getRange());
|
||
mDragMode = DragNone;
|
||
//取消选中状态
|
||
// QCPDataSelection emptySelection;
|
||
// mPlot->graph(0)->setSelection(emptySelection);
|
||
// mPlot->replot();
|
||
|
||
//取消选中框
|
||
mPlot->selectionRect()->cancel();
|
||
mPlot->replot();
|
||
mPlot->selectionRect()->mActive=true;
|
||
}
|
||
}
|
||
|
||
double TransparentDraggableGeoLith::getMyLower()
|
||
{
|
||
double dLower = mPlot->xAxis->range().lower;
|
||
double proposedLeft = mDragStartRange.lower;
|
||
|
||
TransparentDraggableGeoLith *pDraggableRect =NULL;
|
||
{
|
||
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDraggable_GeoLith.begin();
|
||
while( it != mPlot->m_mapDraggable_GeoLith.end() )
|
||
{
|
||
if(it.key() == m_strUuid)
|
||
{
|
||
it++;
|
||
continue;
|
||
}
|
||
pDraggableRect = (TransparentDraggableGeoLith*)it.value();
|
||
//
|
||
QCPRange tmpRange = pDraggableRect->getRange();
|
||
if(tmpRange.upper >= dLower && tmpRange.upper <= proposedLeft)
|
||
{
|
||
dLower = tmpRange.upper;
|
||
}
|
||
it++;
|
||
}
|
||
}
|
||
|
||
return dLower;
|
||
}
|
||
|
||
double TransparentDraggableGeoLith::getMyUpper()
|
||
{
|
||
double dUpper = mPlot->xAxis->range().upper;
|
||
double proposedRight = mDragStartRange.upper;
|
||
|
||
TransparentDraggableGeoLith *pDraggableRect =NULL;
|
||
{
|
||
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDraggable_GeoLith.begin();
|
||
while( it != mPlot->m_mapDraggable_GeoLith.end() )
|
||
{
|
||
if(it.key() == m_strUuid)
|
||
{
|
||
it++;
|
||
continue;
|
||
}
|
||
pDraggableRect = (TransparentDraggableGeoLith*)it.value();
|
||
//
|
||
QCPRange tmpRange = pDraggableRect->getRange();
|
||
if(tmpRange.lower <= dUpper && tmpRange.lower >= proposedRight)
|
||
{
|
||
dUpper = tmpRange.lower;
|
||
}
|
||
it++;
|
||
}
|
||
}
|
||
|
||
return dUpper;
|
||
}
|
||
|