Merge branch 'main' of http://git.hivekion.com:3000/jiayulong/logplus
This commit is contained in:
commit
ca28be2e50
|
|
@ -155,6 +155,20 @@ public:
|
|||
return m_DataSourceZ;
|
||||
}
|
||||
};
|
||||
|
||||
//录井剖面
|
||||
typedef struct GEOLITH_Table
|
||||
{
|
||||
int NO;//序号
|
||||
float SDEP;//起始深度
|
||||
float EDEP;//终止深度
|
||||
int Oil;//含油性
|
||||
int Lith;//岩性
|
||||
int Color;//颜色
|
||||
char Dest[64];
|
||||
} GeoLith_DATA;
|
||||
|
||||
|
||||
QString GetProjectFolder();
|
||||
QString GetLogdataPath();
|
||||
void GetWellNameAndPath(QString slf,QString &wellname,QString &path);
|
||||
|
|
|
|||
|
|
@ -29913,6 +29913,12 @@ void QCPItemRect::draw(QCPPainter *painter)
|
|||
{
|
||||
QPointF p1 = topLeft->pixelPosition();
|
||||
QPointF p2 = bottomRight->pixelPosition();
|
||||
if(m_bCustom)
|
||||
{
|
||||
QPointF p1_tmp = QPointF(p1.rx(), p1.ry()+m_y1);
|
||||
p2 = QPointF(p2.rx(), p2.ry()+m_y2);
|
||||
p1 = p1_tmp;
|
||||
}
|
||||
if (p1.toPoint() == p2.toPoint()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7361,6 +7361,11 @@ public:
|
|||
QCPItemAnchor *const bottomLeft;
|
||||
QCPItemAnchor *const left;
|
||||
|
||||
//jyl
|
||||
bool m_bCustom = false;
|
||||
float m_y1; // 3D变化
|
||||
float m_y2; // 3D变化
|
||||
|
||||
protected:
|
||||
enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
|
||||
|
||||
|
|
|
|||
1451
logPlus/GeoIndicatorGenerator.cpp
Normal file
1451
logPlus/GeoIndicatorGenerator.cpp
Normal file
File diff suppressed because it is too large
Load Diff
61
logPlus/GeoIndicatorGenerator.h
Normal file
61
logPlus/GeoIndicatorGenerator.h
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#ifndef GEOINDICATORGENERATOR_H
|
||||
#define GEOINDICATORGENERATOR_H
|
||||
|
||||
#include <qgraphicsscene.h>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QPainter>
|
||||
class GeoIndicatorGenerator
|
||||
{
|
||||
public:
|
||||
explicit GeoIndicatorGenerator();
|
||||
~GeoIndicatorGenerator();
|
||||
/*Give scene items
|
||||
attr:
|
||||
Geo name
|
||||
scene
|
||||
*/
|
||||
|
||||
/*
|
||||
符号库名称
|
||||
符号名称
|
||||
*QPainter
|
||||
绘制区域qrectf
|
||||
是否绘制单行
|
||||
是否横向拉伸
|
||||
是否平躺
|
||||
一厘米对应的像素个数
|
||||
背景色
|
||||
*/
|
||||
float seleGeo(QString, QString, QPainter*, QRectF rect, bool, bool, bool, float, QColor);
|
||||
|
||||
private:
|
||||
bool initGeoInf(QString, int);
|
||||
float * getWH(QXmlStreamReader*);
|
||||
void calcLNum(float*, QRectF, int* p, bool);
|
||||
bool FindGeoName(QString, QXmlStreamReader*);
|
||||
std::map<QString, int> libMap; //符号库映射
|
||||
std::map<QString, int> nameMap; //符号名称映射
|
||||
std::map<QString, int> lineType; //分隔线映射
|
||||
std::map<QString, int> SymbolType; //纵向拉伸映射
|
||||
std::map<QString, int> reverseType; //反向绘制映射
|
||||
std::map<QString, int> fillType; //填充绘制映射
|
||||
std::map<QString, int> ifGeoHeight; //是否使用标准符号高度
|
||||
|
||||
void PolylinePainter( QXmlStreamReader*, QPainter*, int*, float*, bool, bool, bool);
|
||||
void LinePainter( QXmlStreamReader*, QPainter*, int*, float*, bool, bool, bool);
|
||||
void CirclePainter( QXmlStreamReader*, QPainter*, int*, float*, bool, bool, bool);
|
||||
void TextPainter( QXmlStreamReader*, QPainter*, int*, float*, bool, bool, bool);
|
||||
void ArcPainter( QXmlStreamReader*, QPainter*, int*, float*, bool, bool, bool);
|
||||
void PolygonPainter( QXmlStreamReader*, QPainter*, int*, float*, bool, bool, bool);
|
||||
|
||||
private:
|
||||
QString lines[3]; //xml文本信息
|
||||
QString tempLine; //缓存近期xml信息
|
||||
QRectF m_Rect;
|
||||
float mm; //毫米对应像素量
|
||||
QStringList libStr;
|
||||
float h_strechRate; //纵向拉伸比例
|
||||
//QXmlStreamReader *reader;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
#include <QSvgRenderer>
|
||||
#include <QLabel>
|
||||
#include "CallManage.h"
|
||||
#include "geometryutils.h"
|
||||
|
||||
extern int g_iScale;
|
||||
extern double g_dPixelPerCm;//每厘米像素数
|
||||
|
|
@ -855,8 +856,13 @@ void PropertyWidget::initCurveProperty(FormInfo *formInfo, QStringList strListOt
|
|||
_CreateEnumPropertyItem("岩性填充", "填充类型", listFillType.indexOf(formInfo->m_newFillType), listFillType);
|
||||
_CreateEnumPropertyItem("岩性填充", "填充模式", listFillMode.indexOf(formInfo->m_newFillMode), listFillMode);
|
||||
_CreateVariantPropertyItem("岩性填充", "填充颜色", formInfo->m_newColor, QVariant::Color);
|
||||
_CreateVariantPropertyItem("岩性填充", "填充岩性", formInfo->m_newLithosImage, VariantManager::filePathTypeId()); //"./image/胜利符号库/岩性符号/砂岩.png"
|
||||
|
||||
if(formInfo->m_newLithosImage=="")
|
||||
{
|
||||
_CreateVariantPropertyItem("岩性填充", "填充岩性", ::GetLithSymbolDir(), VariantManager::filePathTypeId());
|
||||
}
|
||||
else {
|
||||
_CreateVariantPropertyItem("岩性填充", "填充岩性", formInfo->m_newLithosImage, VariantManager::filePathTypeId()); //"./image/胜利符号库/岩性符号/砂岩.png"
|
||||
}
|
||||
_CreateVariantPropertyItem("岩性填充", "岩性前景色", formInfo->m_frontColor, QVariant::Color);
|
||||
_CreateVariantPropertyItem("岩性填充", "岩性背景色", formInfo->m_backColor, QVariant::Color);
|
||||
}
|
||||
|
|
|
|||
766
logPlus/TransparentDraggableGeoLith.cpp
Normal file
766
logPlus/TransparentDraggableGeoLith.cpp
Normal file
|
|
@ -0,0 +1,766 @@
|
|||
#include "TransparentDraggableGeoLith.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;
|
||||
}
|
||||
|
||||
void TransparentDraggableGeoLith::drawLith(double left_Low, double right_Hight, double lY1, double lY2)
|
||||
{
|
||||
if(m_Lith=="")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
double x1 = mPlot->xAxis->coordToPixel(left_Low);
|
||||
double x2 = mPlot->xAxis->coordToPixel(right_Hight);
|
||||
double y1 = mPlot->yAxis->coordToPixel(lY1+(lY2-lY1)/4);
|
||||
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);
|
||||
//
|
||||
//painter.setBrush(QBrush(QPixmap(colorPath)));
|
||||
//颜色
|
||||
QString strLastColor = m_Color.right(4);
|
||||
if(strLastColor.toLower()==".svg")
|
||||
{
|
||||
//拉伸
|
||||
DrawSVGSteched(&painter,m_Color,fillRect,0);
|
||||
}
|
||||
|
||||
// bool isStrech=false;
|
||||
// QSvgRenderer m_SvgRenderer;
|
||||
// m_SvgRenderer.load(filePath);
|
||||
// if(!isStrech){
|
||||
// float oil_h = fillRect.width();
|
||||
// oil_h = (oil_h / 2 >= fillRect.height() / 2) ? fillRect.height() : oil_h;
|
||||
// float rect_y = fillRect.y() + fillRect.height() / 2 - oil_h / 2;
|
||||
// fillRect.setY(rect_y);
|
||||
// fillRect.setHeight(oil_h);
|
||||
// }
|
||||
// fillRect.setX(fillRect.x() + 1);
|
||||
// m_SvgRenderer.render(&painter, fillRect);
|
||||
|
||||
//拉伸
|
||||
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_Lith->setPixmap(QPixmap(val)); // 设置图片
|
||||
|
||||
|
||||
// QSvgRenderer* svgRender = new QSvgRenderer();
|
||||
// svgRender->load(result);
|
||||
// //
|
||||
// QPixmap* pixmap = new QPixmap(10, 10);
|
||||
// pixmap->fill(Qt::transparent);//设置背景透明
|
||||
// QPainter p(pixmap);
|
||||
// svgRender->render(&p);
|
||||
// //
|
||||
// mPixmap->setPixmap(*pixmap); // 设置图片
|
||||
}
|
||||
else
|
||||
{
|
||||
// QString val=filePath;
|
||||
// QImage image(47,16,QImage::Format_RGB32);
|
||||
// QPainter painter(&image);
|
||||
// QRectF fillRect(0,0,47,16);
|
||||
// painter.fillRect(fillRect, QColor(0, 0, 0, 0));
|
||||
// //
|
||||
// painter.setBrush(QBrush(QPixmap(colorPath)));
|
||||
|
||||
// QPixmap* pixmap = new QPixmap(filePath);
|
||||
// pixmap->fill(Qt::transparent);//设置背景透明
|
||||
// mPixmap_Lith->setPixmap(*pixmap); // 设置图片
|
||||
|
||||
//mPixmap_Lith->setPixmap(QPixmap(filePath)); // 设置图片
|
||||
|
||||
|
||||
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);
|
||||
//颜色
|
||||
QString strLastColor = m_Color.right(4);
|
||||
if(strLastColor.toLower()==".svg")
|
||||
{
|
||||
//拉伸
|
||||
DrawSVGSteched(&painter,m_Color,fillRect,0);
|
||||
}
|
||||
//
|
||||
bool isOne=true;
|
||||
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
|
||||
|
||||
// mPixmap_Lith->topLeft->setCoords(right_Hight, lY1+(lY2-lY1)/4);
|
||||
// mPixmap_Lith->bottomRight->setCoords(left_Low, lY2);
|
||||
|
||||
//mPlot->replot();
|
||||
}
|
||||
|
||||
//设置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=="")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
double x1 = mPlot->xAxis->coordToPixel(left_Low);
|
||||
double x2 = mPlot->xAxis->coordToPixel(right_Hight);
|
||||
double y1 = mPlot->yAxis->coordToPixel(lY1);
|
||||
double y2 = mPlot->yAxis->coordToPixel(lY1+(lY2-lY1)/4);
|
||||
|
||||
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)); // 设置图片
|
||||
}
|
||||
|
||||
mPixmap_Oil->topLeft->setCoords(xNewRight, mPlot->yAxis->pixelToCoord(y1+1)); //right_Hight, lY1
|
||||
mPixmap_Oil->bottomRight->setCoords(xNewLeft, mPlot->yAxis->pixelToCoord(y2-1)); //left_Low
|
||||
|
||||
//mPlot->replot();
|
||||
}
|
||||
|
||||
//设置Color
|
||||
void TransparentDraggableGeoLith::setColor(QString filePath)
|
||||
{
|
||||
m_Color = filePath;
|
||||
//
|
||||
QString strLast = filePath.right(4);
|
||||
if(strLast.toLower()==".svg")
|
||||
{
|
||||
QString path,filename;
|
||||
GetWellNameAndPath(filePath, filename, path);
|
||||
QString basename = filename;
|
||||
|
||||
QString val=filePath;
|
||||
QImage image(320,160,QImage::Format_RGB32);
|
||||
QPainter painter(&image);
|
||||
QRectF fillRect(0,0,320,160);
|
||||
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_Color->setPixmap(QPixmap(val)); // 设置图片
|
||||
}
|
||||
else
|
||||
{
|
||||
mPixmap_Color->setPixmap(QPixmap(filePath)); // 设置图片
|
||||
}
|
||||
|
||||
//mPlot->replot();
|
||||
}
|
||||
|
||||
// 设置矩形范围
|
||||
void TransparentDraggableGeoLith::setRange(double left_Low, double right_Hight)
|
||||
{
|
||||
if(left_Low >= right_Hight) return;
|
||||
|
||||
double lY1 = mPlot->yAxis->range().lower;//+10
|
||||
double lY2 = mPlot->yAxis->range().upper;
|
||||
|
||||
mRect->topLeft->setCoords(left_Low, lY1);
|
||||
mRect->bottomRight->setCoords(right_Hight, lY2);
|
||||
|
||||
//位置与rect不一样,否则图像反转
|
||||
mPixmap_Color->topLeft->setCoords(right_Hight, lY1+(lY2-lY1)/4);
|
||||
mPixmap_Color->bottomRight->setCoords(left_Low, lY2);
|
||||
//
|
||||
//mPixmap_Lith->topLeft->setCoords(right_Hight, lY1+(lY2-lY1)/4);
|
||||
//mPixmap_Lith->bottomRight->setCoords(left_Low, lY2);
|
||||
drawLith(left_Low, right_Hight, lY1, lY2);
|
||||
|
||||
//位置与rect不一样,否则图像反转
|
||||
//mPixmap_Oil->topLeft->setCoords(right_Hight, lY1);
|
||||
//mPixmap_Oil->bottomRight->setCoords(left_Low, lY1+(lY2-lY1)/4);
|
||||
drawOil(left_Low, right_Hight, lY1, 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);
|
||||
|
||||
updateHandles();
|
||||
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);
|
||||
|
||||
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::red));
|
||||
mLeftHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
mRightHandle = new QCPItemRect(mPlot);
|
||||
mRightHandle->setLayer("overlay");
|
||||
mRightHandle->setBrush(QBrush(Qt::red));
|
||||
mRightHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
// 设置初始位置
|
||||
//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(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 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::onDelRect()
|
||||
{
|
||||
//mDragMode = DragNone;
|
||||
//删除框图
|
||||
deleteRect();
|
||||
}
|
||||
|
||||
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();
|
||||
// QMenu menu(nullptr);
|
||||
// QAction *delAction = menu.addAction("删除框图");
|
||||
// //delAction->installEventFilter(this);
|
||||
// connect(delAction, &QAction::triggered, this, &TransparentDraggableResult::onDelRect);
|
||||
// QAction* pItem = menu.exec(event->globalPos());
|
||||
// if(pItem == delAction)
|
||||
// {
|
||||
// //event->accept();
|
||||
// int ii=0;
|
||||
// ii++;
|
||||
// }
|
||||
// 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;
|
||||
|
||||
}
|
||||
|
||||
void TransparentDraggableGeoLith::onMouseMove(QMouseEvent *event)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRange(newRange.lower, newRange.upper);
|
||||
|
||||
}
|
||||
|
||||
void TransparentDraggableGeoLith::onMouseRelease(QMouseEvent *event)
|
||||
{
|
||||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||||
event->accept();
|
||||
//避免二次绘制框图
|
||||
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;
|
||||
}
|
||||
|
||||
98
logPlus/TransparentDraggableGeoLith.h
Normal file
98
logPlus/TransparentDraggableGeoLith.h
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#ifndef TRANSPARENTDRAGGABLEGEOLITH_H
|
||||
#define TRANSPARENTDRAGGABLEGEOLITH_H
|
||||
|
||||
#include <QObject>
|
||||
#include "qmycustomplot.h"
|
||||
#include <QString>
|
||||
#include <QMenu>
|
||||
#include "geometryutils.h"
|
||||
#include <QSvgRenderer>
|
||||
#include "GeoIndicatorGenerator.h"
|
||||
|
||||
#pragma execution_character_set("utf-8") // 强制指定执行字符集为 UTF-8
|
||||
|
||||
|
||||
class TransparentDraggableGeoLith : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TransparentDraggableGeoLith(QMyCustomPlot *parentPlot, QString strUuid="", double minWidth = 1.0, QString strTitle = "");
|
||||
|
||||
~TransparentDraggableGeoLith();
|
||||
|
||||
void DrawSVGNormal(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout);
|
||||
//拉伸
|
||||
void DrawSVGSteched(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout);
|
||||
//平铺
|
||||
void DrawSVGTiled(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout);
|
||||
//设置最小宽度
|
||||
void setMinWidth(double minWidth);
|
||||
//设置标题
|
||||
void setTitle(QString strTitle);
|
||||
|
||||
//设置解释结论
|
||||
void setLith(QString filePath, QString colorPath);
|
||||
void drawLith(double left_Low, double right_Hight, double lY1, double lY2);
|
||||
|
||||
void setColor(QString filePath);
|
||||
|
||||
//设置m_Oil
|
||||
void setOil(QString filePath);
|
||||
void drawOil(double left_Low, double right_Hight, double lY1, double lY2);
|
||||
|
||||
// 设置矩形范围
|
||||
void setRange(double left_Low, double right_Hight);
|
||||
// 获取当前范围
|
||||
QCPRange getRange();
|
||||
|
||||
// 设置矩形颜色
|
||||
void setColor(const QColor &color);
|
||||
|
||||
// 删除框图
|
||||
void deleteRect();
|
||||
|
||||
signals:
|
||||
void rangeChanged(QCPRange newRange);
|
||||
|
||||
private:
|
||||
void initRect();
|
||||
void updateHandles() ;
|
||||
|
||||
private slots:
|
||||
void onDelRect();
|
||||
void onMousePress(QMouseEvent *event);
|
||||
void onMouseMove(QMouseEvent *event);
|
||||
void onMouseRelease(QMouseEvent *event);
|
||||
double getMyLower();
|
||||
double getMyUpper();
|
||||
|
||||
private:
|
||||
QMyCustomPlot *mPlot;
|
||||
QCPItemRect *mRect;
|
||||
QCPItemRect *mLeftHandle;
|
||||
QCPItemRect *mRightHandle;
|
||||
|
||||
QCPItemPixmap *mPixmap_Lith;
|
||||
QCPItemPixmap *mPixmap_Oil;
|
||||
QCPItemPixmap *mPixmap_Color;
|
||||
QCPItemText *mItemTitle;
|
||||
QString mstrTitle="";
|
||||
QString m_strUuid = "";
|
||||
|
||||
QString m_Lith;
|
||||
QString m_Oil;
|
||||
QString m_Color;
|
||||
|
||||
GeoIndicatorGenerator m_drawGeo;
|
||||
|
||||
enum DragMode { DragNone, DragLeft, DragRight, DragRect };
|
||||
DragMode mDragMode = DragNone;
|
||||
//double mDragStartX = 0;
|
||||
double mDragStartY = 0;
|
||||
QCPRange mDragStartRange;
|
||||
|
||||
// 添加最小宽度成员变量
|
||||
double mMinWidth;
|
||||
};
|
||||
|
||||
#endif // TRANSPARENTDRAGGABLEGEOLITH_H
|
||||
562
logPlus/TransparentDraggableGujing.cpp
Normal file
562
logPlus/TransparentDraggableGujing.cpp
Normal file
|
|
@ -0,0 +1,562 @@
|
|||
#include "TransparentDraggableGujing.h"
|
||||
|
||||
extern double g_dPixelPerCm;//每厘米像素数
|
||||
//static GeoIndicatorGenerator m_drawGeo;
|
||||
|
||||
TransparentDraggableGujing::TransparentDraggableGujing(QMyCustomPlot *parentPlot, QString strUuid, double minWidth, QString strTitle)
|
||||
: QObject(parentPlot), mPlot(parentPlot), mstrTitle(strTitle), mMinWidth(minWidth)
|
||||
{
|
||||
m_strUuid = strUuid;
|
||||
//
|
||||
initRect();
|
||||
}
|
||||
|
||||
TransparentDraggableGujing::~TransparentDraggableGujing()
|
||||
{
|
||||
if(mPlot) {
|
||||
// mPlot->removeItem(mRect);
|
||||
// mPlot->removeItem(mLeftHandle);
|
||||
// mPlot->removeItem(mRightHandle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TransparentDraggableGujing::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 TransparentDraggableGujing::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 TransparentDraggableGujing::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 TransparentDraggableGujing::setMinWidth(double minWidth)
|
||||
{
|
||||
mMinWidth = minWidth;
|
||||
}
|
||||
|
||||
//设置标题
|
||||
void TransparentDraggableGujing::setTitle(QString strTitle)
|
||||
{
|
||||
mstrTitle = strTitle;
|
||||
mItemTitle->setText(mstrTitle);
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
//设置解释结论
|
||||
void TransparentDraggableGujing::setResult(QString filePath)
|
||||
{
|
||||
m_Result = filePath;
|
||||
}
|
||||
|
||||
void TransparentDraggableGujing::drawResult(double left_Low, double right_Hight, double lY1, double lY2)
|
||||
{
|
||||
if(m_Result=="")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
double x1 = mPlot->xAxis->coordToPixel(left_Low);
|
||||
double x2 = mPlot->xAxis->coordToPixel(right_Hight);
|
||||
double y1 = mPlot->yAxis->coordToPixel(lY1);
|
||||
double y2 = mPlot->yAxis->coordToPixel(lY2);
|
||||
|
||||
//
|
||||
QString filePath = m_Result;
|
||||
//
|
||||
QString strLast = filePath.right(4);
|
||||
if(strLast.toLower()==".svg")
|
||||
{
|
||||
QString path,filename;
|
||||
GetWellNameAndPath(filePath, filename, path);
|
||||
QString basename = filename;
|
||||
|
||||
QString val=filePath;
|
||||
QImage image(y2-y1, x1-x2,QImage::Format_RGB32);
|
||||
QPainter painter(&image);
|
||||
QRectF fillRect(0,0, y2-y1, x1-x2);
|
||||
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->setPixmap(QPixmap(val)); // 设置图片
|
||||
}
|
||||
else
|
||||
{
|
||||
//mPixmap->setPixmap(QPixmap(filePath)); // 设置图片
|
||||
|
||||
QString path,filename;
|
||||
GetWellNameAndPath(filePath, filename, path);
|
||||
QString basename = filename;
|
||||
|
||||
QString val=filePath;
|
||||
QImage image(y2-y1, x1-x2,QImage::Format_RGB32);
|
||||
QPainter painter(&image);
|
||||
QRectF fillRect(0,0, y2-y1, x1-x2);
|
||||
painter.fillRect(fillRect,Qt::white);
|
||||
//平铺
|
||||
DrawSVGTiled(&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->setPixmap(QPixmap(val)); // 设置图片
|
||||
}
|
||||
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
// 设置矩形范围
|
||||
void TransparentDraggableGujing::setRange(double left_Low, double right_Hight)
|
||||
{
|
||||
if(left_Low >= right_Hight) return;
|
||||
|
||||
double lY1 = mPlot->yAxis->range().lower;//+10
|
||||
double lY2 = mPlot->yAxis->range().upper;
|
||||
mRect->topLeft->setCoords(left_Low, lY1);
|
||||
mRect->bottomRight->setCoords(right_Hight, lY2);
|
||||
|
||||
//位置与rect不一样,否则图像反转
|
||||
mPixmap->topLeft->setCoords(right_Hight, lY1);
|
||||
mPixmap->bottomRight->setCoords(left_Low, lY2);
|
||||
drawResult(left_Low, right_Hight, lY1, 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);
|
||||
|
||||
updateHandles();
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
// 获取当前范围
|
||||
QCPRange TransparentDraggableGujing::getRange()
|
||||
{
|
||||
return QCPRange(mRect->topLeft->coords().x(), mRect->bottomRight->coords().x());
|
||||
}
|
||||
|
||||
// 设置矩形颜色
|
||||
void TransparentDraggableGujing::setColor(const QColor &color)
|
||||
{
|
||||
mRect->setBrush(QBrush(color));
|
||||
mRect->setPen(QPen(color.darker()));
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
// 删除框图
|
||||
void TransparentDraggableGujing::deleteRect()
|
||||
{
|
||||
if(mPlot) {
|
||||
|
||||
// mRect->deleteLater();
|
||||
// mLeftHandle->deleteLater();
|
||||
// mRightHandle->deleteLater();
|
||||
// mPixmap->deleteLater();
|
||||
|
||||
mPlot->m_mapDraggable_Gujing.remove(m_strUuid);
|
||||
|
||||
mPlot->removeItem(mRect);
|
||||
mPlot->removeItem(mLeftHandle);
|
||||
mPlot->removeItem(mRightHandle);
|
||||
mPlot->removeItem(mPixmap);
|
||||
mPlot->removeItem(mItemTitle);
|
||||
|
||||
mPlot->replot();
|
||||
this->deleteLater();
|
||||
|
||||
//
|
||||
// //避免二次绘制框图
|
||||
// mPlot->m_bDrawRect = false;
|
||||
// mDragMode = DragNone;
|
||||
// //取消选中框
|
||||
// mPlot->selectionRect()->cancel();
|
||||
// mPlot->replot();
|
||||
// mPlot->selectionRect()->mActive=true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TransparentDraggableGujing::initRect()
|
||||
{
|
||||
// 创建透明矩形
|
||||
mRect = new QCPItemRect(mPlot);
|
||||
mRect->setLayer("overlay"); // 确保在最上层
|
||||
mRect->setBrush(QBrush(QColor(255, 255, 255, 50))); // 半透明蓝色
|
||||
mRect->setPen(QPen(QColor(70, 70, 255, 200)));
|
||||
|
||||
// 创建左右边界控制点
|
||||
mLeftHandle = new QCPItemRect(mPlot);
|
||||
mLeftHandle->setLayer("overlay");
|
||||
mLeftHandle->setBrush(QBrush(Qt::red));
|
||||
mLeftHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
mRightHandle = new QCPItemRect(mPlot);
|
||||
mRightHandle->setLayer("overlay");
|
||||
mRightHandle->setBrush(QBrush(Qt::red));
|
||||
mRightHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
// 设置初始位置
|
||||
//double center = mPlot->xAxis->range().center();
|
||||
// setRange(center - 10, center + 10);
|
||||
|
||||
// 连接鼠标事件
|
||||
connect(mPlot, &QCustomPlot::mousePress, this, &TransparentDraggableGujing::onMousePress);
|
||||
connect(mPlot, &QCustomPlot::mouseMove, this, &TransparentDraggableGujing::onMouseMove);
|
||||
connect(mPlot, &QCustomPlot::mouseRelease, this, &TransparentDraggableGujing::onMouseRelease);
|
||||
|
||||
mPixmap = new QCPItemPixmap(mPlot);
|
||||
//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::ptPlotCoords);
|
||||
//mItemTitle->position->setType(QCPItemPosition::ptAxisRectRatio);
|
||||
mItemTitle->position->setCoords(0.5, 0);
|
||||
mItemTitle->setLayer("overlay");
|
||||
}
|
||||
|
||||
void TransparentDraggableGujing::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 TransparentDraggableGujing::onDelRect()
|
||||
{
|
||||
//mDragMode = DragNone;
|
||||
//删除框图
|
||||
deleteRect();
|
||||
}
|
||||
|
||||
|
||||
void TransparentDraggableGujing::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();
|
||||
|
||||
QMenu menu(nullptr);
|
||||
QAction *delAction = menu.addAction("删除框图");
|
||||
//delAction->installEventFilter(this);
|
||||
connect(delAction, &QAction::triggered, this, &TransparentDraggableGujing::onDelRect);
|
||||
|
||||
// QAction* pItem = menu.exec(event->globalPos());
|
||||
// if(pItem == delAction)
|
||||
// {
|
||||
// //event->accept();
|
||||
|
||||
// int ii=0;
|
||||
// ii++;
|
||||
// }
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
void TransparentDraggableGujing::onMouseMove(QMouseEvent *event)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRange(newRange.lower, newRange.upper);
|
||||
|
||||
}
|
||||
|
||||
void TransparentDraggableGujing::onMouseRelease(QMouseEvent *event)
|
||||
{
|
||||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||||
event->accept();
|
||||
//避免二次绘制框图
|
||||
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 TransparentDraggableGujing::getMyLower()
|
||||
{
|
||||
double dLower = mPlot->xAxis->range().lower;
|
||||
double proposedLeft = mDragStartRange.lower;
|
||||
|
||||
TransparentDraggableGujing *pDraggableRect =NULL;
|
||||
{
|
||||
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDraggable_Gujing.begin();
|
||||
while( it != mPlot->m_mapDraggable_Gujing.end() )
|
||||
{
|
||||
if(it.key() == m_strUuid)
|
||||
{
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
pDraggableRect = (TransparentDraggableGujing*)it.value();
|
||||
//
|
||||
QCPRange tmpRange = pDraggableRect->getRange();
|
||||
if(tmpRange.upper >= dLower && tmpRange.upper <= proposedLeft)
|
||||
{
|
||||
dLower = tmpRange.upper;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
return dLower;
|
||||
}
|
||||
|
||||
double TransparentDraggableGujing::getMyUpper()
|
||||
{
|
||||
double dUpper = mPlot->xAxis->range().upper;
|
||||
double proposedRight = mDragStartRange.upper;
|
||||
|
||||
TransparentDraggableGujing *pDraggableRect =NULL;
|
||||
{
|
||||
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDraggable_Gujing.begin();
|
||||
while( it != mPlot->m_mapDraggable_Gujing.end() )
|
||||
{
|
||||
if(it.key() == m_strUuid)
|
||||
{
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
pDraggableRect = (TransparentDraggableGujing*)it.value();
|
||||
//
|
||||
QCPRange tmpRange = pDraggableRect->getRange();
|
||||
if(tmpRange.lower <= dUpper && tmpRange.lower >= proposedRight)
|
||||
{
|
||||
dUpper = tmpRange.lower;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
return dUpper;
|
||||
}
|
||||
|
||||
85
logPlus/TransparentDraggableGujing.h
Normal file
85
logPlus/TransparentDraggableGujing.h
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#ifndef TRANSPARENTDRAGGABLEGUJING_H
|
||||
#define TRANSPARENTDRAGGABLEGUJING_H
|
||||
|
||||
#include <QObject>
|
||||
#include "qmycustomplot.h"
|
||||
#include <QString>
|
||||
#include <QMenu>
|
||||
#include "geometryutils.h"
|
||||
#include <QSvgRenderer>
|
||||
|
||||
#pragma execution_character_set("utf-8") // 强制指定执行字符集为 UTF-8
|
||||
|
||||
class TransparentDraggableGujing : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TransparentDraggableGujing(QMyCustomPlot *parentPlot, QString strUuid="", double minWidth = 1.0, QString strTitle = "");
|
||||
|
||||
|
||||
~TransparentDraggableGujing();
|
||||
|
||||
|
||||
void DrawSVGNormal(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout);
|
||||
//拉伸
|
||||
void DrawSVGSteched(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout);
|
||||
//平铺
|
||||
void DrawSVGTiled(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout);
|
||||
//设置最小宽度
|
||||
void setMinWidth(double minWidth);
|
||||
//设置标题
|
||||
void setTitle(QString strTitle);
|
||||
|
||||
//设置解释结论
|
||||
void setResult(QString filePath);
|
||||
void drawResult(double left_Low, double right_Hight, double lY1, double lY2);
|
||||
|
||||
// 设置矩形范围
|
||||
void setRange(double left_Low, double right_Hight);
|
||||
// 获取当前范围
|
||||
QCPRange getRange();
|
||||
|
||||
// 设置矩形颜色
|
||||
void setColor(const QColor &color);
|
||||
|
||||
// 删除框图
|
||||
void deleteRect();
|
||||
|
||||
signals:
|
||||
void rangeChanged(QCPRange newRange);
|
||||
|
||||
private:
|
||||
void initRect();
|
||||
void updateHandles() ;
|
||||
|
||||
private slots:
|
||||
void onDelRect();
|
||||
void onMousePress(QMouseEvent *event);
|
||||
void onMouseMove(QMouseEvent *event);
|
||||
void onMouseRelease(QMouseEvent *event);
|
||||
double getMyLower();
|
||||
double getMyUpper();
|
||||
|
||||
private:
|
||||
QMyCustomPlot *mPlot;
|
||||
QCPItemRect *mRect;
|
||||
QCPItemRect *mLeftHandle;
|
||||
QCPItemRect *mRightHandle;
|
||||
|
||||
QCPItemPixmap *mPixmap;
|
||||
QCPItemText *mItemTitle;
|
||||
QString mstrTitle="";
|
||||
QString m_strUuid = "";
|
||||
QString m_Result;
|
||||
|
||||
enum DragMode { DragNone, DragLeft, DragRight, DragRect };
|
||||
DragMode mDragMode = DragNone;
|
||||
//double mDragStartX = 0;
|
||||
double mDragStartY = 0;
|
||||
QCPRange mDragStartRange;
|
||||
|
||||
// 添加最小宽度成员变量
|
||||
double mMinWidth;
|
||||
};
|
||||
|
||||
#endif // TRANSPARENTDRAGGABLEGUJING_H
|
||||
427
logPlus/TransparentDraggableRect.cpp
Normal file
427
logPlus/TransparentDraggableRect.cpp
Normal file
|
|
@ -0,0 +1,427 @@
|
|||
#include "TransparentDraggableRect.h"
|
||||
|
||||
extern double g_dPixelPerCm;//每厘米像素数
|
||||
//static GeoIndicatorGenerator m_drawGeo;
|
||||
|
||||
TransparentDraggableRect::TransparentDraggableRect(QMyCustomPlot *parentPlot, QString strUuid, double minWidth, QString strTitle)
|
||||
: QObject(parentPlot), mPlot(parentPlot), mstrTitle(strTitle), mMinWidth(minWidth)
|
||||
{
|
||||
m_strUuid = strUuid;
|
||||
//
|
||||
initRect();
|
||||
}
|
||||
|
||||
TransparentDraggableRect::~TransparentDraggableRect()
|
||||
{
|
||||
if(mPlot) {
|
||||
// mPlot->removeItem(mRect);
|
||||
// mPlot->removeItem(mLeftHandle);
|
||||
// mPlot->removeItem(mRightHandle);
|
||||
}
|
||||
}
|
||||
|
||||
//设置最小宽度
|
||||
void TransparentDraggableRect::setMinWidth(double minWidth)
|
||||
{
|
||||
mMinWidth = minWidth;
|
||||
}
|
||||
|
||||
//设置标题
|
||||
void TransparentDraggableRect::setTitle(QString strTitle)
|
||||
{
|
||||
mstrTitle = strTitle;
|
||||
mItemTitle->setText(mstrTitle);
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
// 设置矩形范围
|
||||
void TransparentDraggableRect::setRange(double left_Low, double right_Hight)
|
||||
{
|
||||
if(left_Low >= right_Hight) return;
|
||||
|
||||
double lY1 = mPlot->yAxis->range().lower;//+10
|
||||
double lY2 = mPlot->yAxis->range().upper;
|
||||
mRect->topLeft->setCoords(left_Low, lY1);
|
||||
mRect->bottomRight->setCoords(right_Hight, lY2);
|
||||
|
||||
//位置与rect不一样,否则图像反转
|
||||
mPixmap->topLeft->setCoords(right_Hight, lY1);
|
||||
mPixmap->bottomRight->setCoords(left_Low, 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);
|
||||
|
||||
updateHandles();
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
// 获取当前范围
|
||||
QCPRange TransparentDraggableRect::getRange()
|
||||
{
|
||||
return QCPRange(mRect->topLeft->coords().x(), mRect->bottomRight->coords().x());
|
||||
}
|
||||
|
||||
// 设置矩形颜色
|
||||
void TransparentDraggableRect::setColor(const QColor &color)
|
||||
{
|
||||
mRect->setBrush(QBrush(color));
|
||||
mRect->setPen(QPen(color.darker()));
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
// 删除框图
|
||||
void TransparentDraggableRect::deleteRect()
|
||||
{
|
||||
if(mPlot) {
|
||||
|
||||
// mRect->deleteLater();
|
||||
// mLeftHandle->deleteLater();
|
||||
// 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();
|
||||
|
||||
//
|
||||
// //避免二次绘制框图
|
||||
// mPlot->m_bDrawRect = false;
|
||||
// mDragMode = DragNone;
|
||||
// //取消选中框
|
||||
// mPlot->selectionRect()->cancel();
|
||||
// mPlot->replot();
|
||||
// mPlot->selectionRect()->mActive=true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TransparentDraggableRect::initRect()
|
||||
{
|
||||
// 创建透明矩形
|
||||
mRect = new QCPItemRect(mPlot);
|
||||
mRect->setLayer("overlay"); // 确保在最上层
|
||||
mRect->setBrush(QBrush(QColor(255, 255, 255, 50))); // 半透明蓝色
|
||||
mRect->setPen(QPen(QColor(70, 70, 255, 200)));
|
||||
|
||||
// 创建左右边界控制点
|
||||
mLeftHandle = new QCPItemRect(mPlot);
|
||||
mLeftHandle->setLayer("overlay");
|
||||
mLeftHandle->setBrush(QBrush(Qt::red));
|
||||
mLeftHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
mRightHandle = new QCPItemRect(mPlot);
|
||||
mRightHandle->setLayer("overlay");
|
||||
mRightHandle->setBrush(QBrush(Qt::red));
|
||||
mRightHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
// 设置初始位置
|
||||
//double center = mPlot->xAxis->range().center();
|
||||
// setRange(center - 10, center + 10);
|
||||
|
||||
// 连接鼠标事件
|
||||
connect(mPlot, &QCustomPlot::mousePress, this, &TransparentDraggableRect::onMousePress);
|
||||
connect(mPlot, &QCustomPlot::mouseMove, this, &TransparentDraggableRect::onMouseMove);
|
||||
connect(mPlot, &QCustomPlot::mouseRelease, this, &TransparentDraggableRect::onMouseRelease);
|
||||
|
||||
mPixmap = new QCPItemPixmap(mPlot);
|
||||
//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::ptPlotCoords);
|
||||
//mItemTitle->position->setType(QCPItemPosition::ptAxisRectRatio);
|
||||
mItemTitle->position->setCoords(0.5, 0);
|
||||
mItemTitle->setLayer("overlay");
|
||||
}
|
||||
|
||||
void TransparentDraggableRect::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 TransparentDraggableRect::onDelRect()
|
||||
{
|
||||
//mDragMode = DragNone;
|
||||
//删除框图
|
||||
deleteRect();
|
||||
}
|
||||
|
||||
|
||||
void TransparentDraggableRect::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();
|
||||
|
||||
QMenu menu(nullptr);
|
||||
QAction *delAction = menu.addAction("删除框图");
|
||||
//delAction->installEventFilter(this);
|
||||
connect(delAction, &QAction::triggered, this, &TransparentDraggableRect::onDelRect);
|
||||
|
||||
// QAction* pItem = menu.exec(event->globalPos());
|
||||
// if(pItem == delAction)
|
||||
// {
|
||||
// //event->accept();
|
||||
|
||||
// int ii=0;
|
||||
// ii++;
|
||||
// }
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
void TransparentDraggableRect::onMouseMove(QMouseEvent *event)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRange(newRange.lower, newRange.upper);
|
||||
|
||||
}
|
||||
|
||||
void TransparentDraggableRect::onMouseRelease(QMouseEvent *event)
|
||||
{
|
||||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||||
event->accept();
|
||||
//避免二次绘制框图
|
||||
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 TransparentDraggableRect::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 TransparentDraggableRect::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;
|
||||
}
|
||||
|
||||
|
|
@ -12,439 +12,42 @@ class TransparentDraggableRect : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TransparentDraggableRect(QMyCustomPlot *parentPlot, QString strUuid="", double minWidth = 1.0, QString strTitle = "")
|
||||
: QObject(parentPlot), mPlot(parentPlot), mstrTitle(strTitle), mMinWidth(minWidth)
|
||||
{
|
||||
m_strUuid = strUuid;
|
||||
//
|
||||
initRect();
|
||||
}
|
||||
explicit TransparentDraggableRect(QMyCustomPlot *parentPlot, QString strUuid="", double minWidth = 1.0, QString strTitle = "");
|
||||
|
||||
|
||||
~TransparentDraggableRect() {
|
||||
if(mPlot) {
|
||||
// mPlot->removeItem(mRect);
|
||||
// mPlot->removeItem(mLeftHandle);
|
||||
// mPlot->removeItem(mRightHandle);
|
||||
}
|
||||
}
|
||||
~TransparentDraggableRect();
|
||||
|
||||
//设置最小宽度
|
||||
void setMinWidth(double minWidth){
|
||||
mMinWidth = minWidth;
|
||||
}
|
||||
|
||||
void setMinWidth(double minWidth);
|
||||
//设置标题
|
||||
void setTitle(QString strTitle){
|
||||
mstrTitle = strTitle;
|
||||
mItemTitle->setText(mstrTitle);
|
||||
mPlot->replot();
|
||||
}
|
||||
void setTitle(QString strTitle);
|
||||
|
||||
// 设置矩形范围
|
||||
void setRange(double left_Low, double right_Hight) {
|
||||
if(left_Low >= right_Hight) return;
|
||||
|
||||
double lY1 = mPlot->yAxis->range().lower;//+10
|
||||
double lY2 = mPlot->yAxis->range().upper;
|
||||
mRect->topLeft->setCoords(left_Low, lY1);
|
||||
mRect->bottomRight->setCoords(right_Hight, lY2);
|
||||
|
||||
//位置与rect不一样,否则图像反转
|
||||
mPixmap->topLeft->setCoords(right_Hight, lY1);
|
||||
mPixmap->bottomRight->setCoords(left_Low, 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);
|
||||
|
||||
updateHandles();
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
void setRange(double left_Low, double right_Hight);
|
||||
// 获取当前范围
|
||||
QCPRange getRange() const {
|
||||
return QCPRange(mRect->topLeft->coords().x(), mRect->bottomRight->coords().x());
|
||||
}
|
||||
QCPRange getRange();
|
||||
|
||||
// 设置矩形颜色
|
||||
void setColor(const QColor &color) {
|
||||
mRect->setBrush(QBrush(color));
|
||||
mRect->setPen(QPen(color.darker()));
|
||||
mPlot->replot();
|
||||
}
|
||||
void setColor(const QColor &color);
|
||||
|
||||
// 删除框图
|
||||
void deleteRect() {
|
||||
if(mPlot) {
|
||||
|
||||
// mRect->deleteLater();
|
||||
// mLeftHandle->deleteLater();
|
||||
// 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();
|
||||
|
||||
//
|
||||
// //避免二次绘制框图
|
||||
// mPlot->m_bDrawRect = false;
|
||||
// mDragMode = DragNone;
|
||||
// //取消选中框
|
||||
// mPlot->selectionRect()->cancel();
|
||||
// mPlot->replot();
|
||||
// mPlot->selectionRect()->mActive=true;
|
||||
}
|
||||
}
|
||||
void deleteRect();
|
||||
|
||||
signals:
|
||||
void rangeChanged(QCPRange newRange);
|
||||
|
||||
private:
|
||||
void initRect() {
|
||||
// 创建透明矩形
|
||||
mRect = new QCPItemRect(mPlot);
|
||||
mRect->setLayer("overlay"); // 确保在最上层
|
||||
mRect->setBrush(QBrush(QColor(100, 100, 255, 50))); // 半透明蓝色
|
||||
mRect->setPen(QPen(QColor(70, 70, 255, 200)));
|
||||
|
||||
// 创建左右边界控制点
|
||||
mLeftHandle = new QCPItemRect(mPlot);
|
||||
mLeftHandle->setLayer("overlay");
|
||||
mLeftHandle->setBrush(QBrush(Qt::red));
|
||||
mLeftHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
mRightHandle = new QCPItemRect(mPlot);
|
||||
mRightHandle->setLayer("overlay");
|
||||
mRightHandle->setBrush(QBrush(Qt::red));
|
||||
mRightHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
// 设置初始位置
|
||||
//double center = mPlot->xAxis->range().center();
|
||||
// setRange(center - 10, center + 10);
|
||||
|
||||
// 连接鼠标事件
|
||||
connect(mPlot, &QCustomPlot::mousePress, this, &TransparentDraggableRect::onMousePress);
|
||||
connect(mPlot, &QCustomPlot::mouseMove, this, &TransparentDraggableRect::onMouseMove);
|
||||
connect(mPlot, &QCustomPlot::mouseRelease, this, &TransparentDraggableRect::onMouseRelease);
|
||||
|
||||
mPixmap = new QCPItemPixmap(mPlot);
|
||||
//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::ptPlotCoords);
|
||||
//mItemTitle->position->setType(QCPItemPosition::ptAxisRectRatio);
|
||||
mItemTitle->position->setCoords(0.5, 0);
|
||||
mItemTitle->setLayer("overlay");
|
||||
}
|
||||
|
||||
void 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 initRect();
|
||||
void updateHandles() ;
|
||||
|
||||
private slots:
|
||||
void onDelRect()
|
||||
{
|
||||
//mDragMode = DragNone;
|
||||
//删除框图
|
||||
deleteRect();
|
||||
}
|
||||
|
||||
// 事件过滤器处理函数
|
||||
// bool eventFilter(QObject* object, QEvent* event) {
|
||||
// if (event->type() == QEvent::MouseButtonPress) {
|
||||
// // 拦截操作
|
||||
// return true; // 阻止事件传递
|
||||
|
||||
//// if (object == action) {
|
||||
//// // 验证权限
|
||||
//// if (1) {
|
||||
//// // 允许操作
|
||||
//// action->trigger();
|
||||
//// } else {
|
||||
//// // 拦截操作
|
||||
//// return true; // 阻止事件传递
|
||||
//// }
|
||||
//// }
|
||||
// }
|
||||
// return false; // 默认不拦截其他事件
|
||||
// }
|
||||
|
||||
void 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();
|
||||
|
||||
QMenu menu(nullptr);
|
||||
QAction *delAction = menu.addAction("删除框图");
|
||||
//delAction->installEventFilter(this);
|
||||
connect(delAction, &QAction::triggered, this, &TransparentDraggableRect::onDelRect);
|
||||
|
||||
// QAction* pItem = menu.exec(event->globalPos());
|
||||
// if(pItem == delAction)
|
||||
// {
|
||||
// //event->accept();
|
||||
|
||||
// int ii=0;
|
||||
// ii++;
|
||||
// }
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
void onMouseMove(QMouseEvent *event) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRange(newRange.lower, newRange.upper);
|
||||
|
||||
}
|
||||
|
||||
void onMouseRelease(QMouseEvent *event) {
|
||||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||||
event->accept();
|
||||
//避免二次绘制框图
|
||||
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 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;
|
||||
}
|
||||
|
||||
void onDelRect();
|
||||
void onMousePress(QMouseEvent *event);
|
||||
void onMouseMove(QMouseEvent *event);
|
||||
void onMouseRelease(QMouseEvent *event);
|
||||
double getMyLower();
|
||||
double getMyUpper();
|
||||
|
||||
private:
|
||||
QMyCustomPlot *mPlot;
|
||||
QCPItemRect *mRect;
|
||||
|
|
|
|||
696
logPlus/TransparentDraggableResult.cpp
Normal file
696
logPlus/TransparentDraggableResult.cpp
Normal file
|
|
@ -0,0 +1,696 @@
|
|||
#include "TransparentDraggableResult.h"
|
||||
|
||||
extern double g_dPixelPerCm;//每厘米像素数
|
||||
//static GeoIndicatorGenerator m_drawGeo;
|
||||
|
||||
TransparentDraggableResult::TransparentDraggableResult(QMyCustomPlot *parentPlot, TransparentDraggableResult *upDraggableResult, QString strUuid, double minWidth, QString strTitle)
|
||||
: QObject(parentPlot), mPlot(parentPlot), mstrTitle(strTitle), mMinWidth(minWidth)
|
||||
{
|
||||
m_upDraggableResult = upDraggableResult;
|
||||
m_strUuid = strUuid;
|
||||
//
|
||||
initRect();
|
||||
|
||||
//将自己,设置为上方rect的下方
|
||||
if(m_upDraggableResult)
|
||||
{
|
||||
m_upDraggableResult->m_downDraggableResult = this;
|
||||
}
|
||||
}
|
||||
|
||||
TransparentDraggableResult::~TransparentDraggableResult()
|
||||
{
|
||||
if(mPlot) {
|
||||
// mPlot->removeItem(mRect);
|
||||
// mPlot->removeItem(mLeftHandle);
|
||||
// mPlot->removeItem(mRightHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void TransparentDraggableResult::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 TransparentDraggableResult::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 TransparentDraggableResult::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 TransparentDraggableResult::setMinWidth(double minWidth)
|
||||
{
|
||||
mMinWidth = minWidth;
|
||||
}
|
||||
|
||||
//设置标题
|
||||
void TransparentDraggableResult::setTitle(QString strTitle)
|
||||
{
|
||||
mstrTitle = strTitle;
|
||||
mItemTitle->setText(mstrTitle);
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
//设置解释结论
|
||||
void TransparentDraggableResult::setResult(QString filePath)
|
||||
{
|
||||
m_Result = filePath;
|
||||
}
|
||||
|
||||
void TransparentDraggableResult::drawResult(double left_Low, double right_Hight, double lY1, double lY2)
|
||||
{
|
||||
if(m_Result=="")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
double x1 = mPlot->xAxis->coordToPixel(left_Low);
|
||||
double x2 = mPlot->xAxis->coordToPixel(right_Hight);
|
||||
double y1 = mPlot->yAxis->coordToPixel(lY1);
|
||||
double y2 = mPlot->yAxis->coordToPixel(lY2);
|
||||
|
||||
//
|
||||
QString filePath = m_Result;
|
||||
//
|
||||
QString strLast = filePath.right(4);
|
||||
if(strLast.toLower()==".svg")
|
||||
{
|
||||
QString path,filename;
|
||||
GetWellNameAndPath(filePath, filename, path);
|
||||
QString basename = filename;
|
||||
|
||||
QString val=filePath;
|
||||
QImage image(y2-y1, x1-x2,QImage::Format_RGB32);
|
||||
QPainter painter(&image);
|
||||
QRectF fillRect(0,0, y2-y1, x1-x2);
|
||||
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->setPixmap(QPixmap(val)); // 设置图片
|
||||
|
||||
|
||||
// QSvgRenderer* svgRender = new QSvgRenderer();
|
||||
// svgRender->load(result);
|
||||
// //
|
||||
// QPixmap* pixmap = new QPixmap(10, 10);
|
||||
// pixmap->fill(Qt::transparent);//设置背景透明
|
||||
// QPainter p(pixmap);
|
||||
// svgRender->render(&p);
|
||||
// //
|
||||
// mPixmap->setPixmap(*pixmap); // 设置图片
|
||||
}
|
||||
else
|
||||
{
|
||||
mPixmap->setPixmap(QPixmap(filePath)); // 设置图片
|
||||
}
|
||||
|
||||
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
// 设置矩形范围
|
||||
void TransparentDraggableResult::setRange(double left_Low, double right_Hight)
|
||||
{
|
||||
if(left_Low >= right_Hight) return;
|
||||
|
||||
double lY1 = mPlot->yAxis->range().lower;//+10
|
||||
double lY2 = (mPlot->yAxis->range().upper-mPlot->yAxis->range().lower)/4;
|
||||
mRect->topLeft->setCoords(left_Low, lY1);
|
||||
mRect->bottomRight->setCoords(right_Hight, lY2);
|
||||
|
||||
//位置与rect不一样,否则图像反转
|
||||
// double dbCenterX = (right_Hight+left_Low)/2.0; //right_Hight; //
|
||||
// double dbCenterY = (lY1+lY2)/2.0; //lY2; //
|
||||
// double x1 = mPlot->xAxis->coordToPixel(dbCenterX);
|
||||
// double y1 = mPlot->yAxis->coordToPixel(dbCenterY);
|
||||
// mPixmap->topLeft->setCoords(mPlot->xAxis->pixelToCoord(x1), mPlot->yAxis->pixelToCoord(y1));
|
||||
// mPixmap->topLeft->setCoords(right_Hight, lY2);
|
||||
// mPixmap->bottomRight->setCoords(left_Low, lY1);
|
||||
mPixmap->topLeft->setCoords(right_Hight, lY1);
|
||||
mPixmap->bottomRight->setCoords(left_Low, lY2);
|
||||
drawResult(left_Low, right_Hight, lY1, lY2);
|
||||
|
||||
// mPixmap->topLeft->setCoords(right_Hight, lY1);
|
||||
// mPixmap->bottomRight->setCoords(left_Low, lY1);
|
||||
|
||||
//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); // 设置文本在矩形中心位置
|
||||
|
||||
mItemTitle->position->setCoords((mRect->topLeft->coords().x() + mRect->bottomRight->coords().x())/2,
|
||||
lY2 + lY2/2);
|
||||
|
||||
//mRect->topLeft->setCoords(left, mPlot->yAxis->range().upper);
|
||||
//mRect->bottomRight->setCoords(right, mPlot->yAxis->range().lower);
|
||||
|
||||
updateHandles();
|
||||
//后面统一刷新上方和下方rect
|
||||
//mPlot->replot();
|
||||
}
|
||||
|
||||
// 获取当前范围
|
||||
QCPRange TransparentDraggableResult::getRange()
|
||||
{
|
||||
return QCPRange(mRect->topLeft->coords().x(), mRect->bottomRight->coords().x());
|
||||
}
|
||||
|
||||
// 设置矩形颜色
|
||||
void TransparentDraggableResult::setColor(const QColor &color) {
|
||||
mRect->setBrush(QBrush(color));
|
||||
mRect->setPen(QPen(color.darker()));
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
// 删除框图
|
||||
void TransparentDraggableResult::deleteRect()
|
||||
{
|
||||
if(mPlot) {
|
||||
|
||||
// mRect->deleteLater();
|
||||
// mLeftHandle->deleteLater();
|
||||
// mRightHandle->deleteLater();
|
||||
// mPixmap->deleteLater();
|
||||
|
||||
mPlot->m_mapDraggable_Result.remove(m_strUuid);
|
||||
|
||||
mPlot->removeItem(mRect);
|
||||
mPlot->removeItem(mLeftHandle);
|
||||
mPlot->removeItem(mRightHandle);
|
||||
mPlot->removeItem(mPixmap);
|
||||
mPlot->removeItem(mItemTitle);
|
||||
|
||||
mPlot->replot();
|
||||
this->deleteLater();
|
||||
|
||||
//
|
||||
// //避免二次绘制框图
|
||||
// mPlot->m_bDrawRect = false;
|
||||
// mDragMode = DragNone;
|
||||
// //取消选中框
|
||||
// mPlot->selectionRect()->cancel();
|
||||
// mPlot->replot();
|
||||
// mPlot->selectionRect()->mActive=true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TransparentDraggableResult::initRect()
|
||||
{
|
||||
// 创建透明矩形
|
||||
mRect = new QCPItemRect(mPlot);
|
||||
mRect->setLayer("overlay"); // 确保在最上层
|
||||
mRect->setBrush(QBrush(QColor(255, 255, 255, 50))); // 半透明蓝色
|
||||
mRect->setPen(QPen(QColor(70, 70, 255, 200)));
|
||||
|
||||
// 创建左右边界控制点
|
||||
mLeftHandle = new QCPItemRect(mPlot);
|
||||
mLeftHandle->setLayer("overlay");
|
||||
mLeftHandle->setBrush(QBrush(Qt::red));
|
||||
mLeftHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
mRightHandle = new QCPItemRect(mPlot);
|
||||
mRightHandle->setLayer("overlay");
|
||||
mRightHandle->setBrush(QBrush(Qt::red));
|
||||
mRightHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
// 设置初始位置
|
||||
//double center = mPlot->xAxis->range().center();
|
||||
// setRange(center - 10, center + 10);
|
||||
|
||||
// 连接鼠标事件
|
||||
connect(mPlot, &QCustomPlot::mousePress, this, &TransparentDraggableResult::onMousePress);
|
||||
connect(mPlot, &QCustomPlot::mouseMove, this, &TransparentDraggableResult::onMouseMove);
|
||||
connect(mPlot, &QCustomPlot::mouseRelease, this, &TransparentDraggableResult::onMouseRelease);
|
||||
|
||||
mPixmap = new QCPItemPixmap(mPlot);
|
||||
//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::ptPlotCoords);
|
||||
//mItemTitle->position->setType(QCPItemPosition::ptAxisRectRatio);
|
||||
mItemTitle->position->setCoords(0.5, 0);
|
||||
mItemTitle->setLayer("overlay");
|
||||
}
|
||||
|
||||
void TransparentDraggableResult::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); // 矩形大小
|
||||
|
||||
// if(m_upDraggableResult)
|
||||
// {
|
||||
// // 右边界矩形控制点
|
||||
// m_upDraggableResult->mLeftHandle->topLeft->setParentAnchor(mRect->bottomLeft);
|
||||
// m_upDraggableResult->mLeftHandle->bottomRight->setParentAnchor(mRect->bottomRight);
|
||||
// m_upDraggableResult->mLeftHandle->topLeft->setCoords(-5, 5); // 矩形大小
|
||||
// m_upDraggableResult->mLeftHandle->bottomRight->setCoords(5, -5); // 矩形大小
|
||||
|
||||
// // 右边界矩形控制点
|
||||
// //mRect->topLeft->setParentAnchor(m_upDraggableResult->mRect->bottomLeft);
|
||||
// //m_upDraggableResult->mRect->topRight->setParentAnchor(mRect->bottomRight);
|
||||
|
||||
// // mRect->topLeft->setParentAnchor(m_upDraggableResult->mRect->bottomLeft);
|
||||
// // mRect->bottomRight->setParentAnchor(m_upDraggableResult->mRect->bottomRight);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
void TransparentDraggableResult::onDelRect()
|
||||
{
|
||||
//mDragMode = DragNone;
|
||||
//删除框图
|
||||
deleteRect();
|
||||
}
|
||||
|
||||
void TransparentDraggableResult::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();
|
||||
// QMenu menu(nullptr);
|
||||
// QAction *delAction = menu.addAction("删除框图");
|
||||
// //delAction->installEventFilter(this);
|
||||
// connect(delAction, &QAction::triggered, this, &TransparentDraggableResult::onDelRect);
|
||||
// QAction* pItem = menu.exec(event->globalPos());
|
||||
// if(pItem == delAction)
|
||||
// {
|
||||
// //event->accept();
|
||||
// int ii=0;
|
||||
// ii++;
|
||||
// }
|
||||
// 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;
|
||||
|
||||
//上方rect同步动
|
||||
if(m_upDraggableResult)
|
||||
{
|
||||
if(mDragMode==DragRight || mDragMode==DragRect)
|
||||
{
|
||||
m_upDraggableResult->mDragMode = DragLeft;
|
||||
m_upDraggableResult->mDragStartY = y;
|
||||
m_upDraggableResult->mDragStartRange = m_upDraggableResult->getRange();
|
||||
}
|
||||
}
|
||||
|
||||
//下方rect同步动
|
||||
if(m_downDraggableResult)
|
||||
{
|
||||
if(mDragMode==DragLeft || mDragMode==DragRect)
|
||||
{
|
||||
m_downDraggableResult->mDragMode = DragRight;
|
||||
m_downDraggableResult->mDragStartY = y;
|
||||
m_downDraggableResult->mDragStartRange = m_downDraggableResult->getRange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TransparentDraggableResult::onMouseMove_in(QMouseEvent *event)
|
||||
{
|
||||
//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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRange(newRange.lower, newRange.upper);
|
||||
}
|
||||
|
||||
void TransparentDraggableResult::onMouseMove_in_DragLeft(QMouseEvent *event)
|
||||
{
|
||||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());
|
||||
double dy = y - mDragStartY;
|
||||
|
||||
QCPRange newRange = mDragStartRange;
|
||||
double proposedLeft = mDragStartRange.lower + dy;
|
||||
// 确保不超出轴范围且不使宽度小于最小值
|
||||
newRange.lower = qBound(
|
||||
getMyLower(),
|
||||
proposedLeft,
|
||||
mDragStartRange.upper - mMinWidth);
|
||||
|
||||
|
||||
// 最终确保宽度不小于最小值(针对整体拖动的情况)
|
||||
if(newRange.size() < mMinWidth) {
|
||||
newRange.lower = newRange.upper - mMinWidth;
|
||||
}
|
||||
|
||||
setRange(newRange.lower, newRange.upper);
|
||||
}
|
||||
|
||||
|
||||
void TransparentDraggableResult::onMouseMove_in_DragRight(QMouseEvent *event)
|
||||
{
|
||||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());
|
||||
double dy = y - mDragStartY;
|
||||
|
||||
QCPRange newRange = mDragStartRange;
|
||||
double proposedRight = mDragStartRange.upper + dy;
|
||||
// 确保不超出轴范围且不使宽度小于最小值
|
||||
newRange.upper = qBound(
|
||||
mDragStartRange.lower + mMinWidth,
|
||||
proposedRight,
|
||||
getMyUpper());
|
||||
|
||||
// 最终确保宽度不小于最小值(针对整体拖动的情况)
|
||||
if(newRange.size() < mMinWidth) {
|
||||
newRange.upper = newRange.lower + mMinWidth;
|
||||
}
|
||||
setRange(newRange.lower, newRange.upper);
|
||||
}
|
||||
|
||||
void TransparentDraggableResult::onMouseMove(QMouseEvent *event)
|
||||
{
|
||||
if(mDragMode == DragNone) return;
|
||||
|
||||
event->accept();
|
||||
|
||||
onMouseMove_in(event);
|
||||
|
||||
//上方rect同步动
|
||||
if(m_upDraggableResult)
|
||||
{
|
||||
if(mDragMode==DragRight || mDragMode==DragRect)
|
||||
{
|
||||
//m_upDraggableResult->mDragMode = DragLeft;
|
||||
m_upDraggableResult->onMouseMove_in_DragLeft(event);
|
||||
}
|
||||
}
|
||||
|
||||
//下方rect同步动
|
||||
if(m_downDraggableResult)
|
||||
{
|
||||
if(mDragMode==DragLeft || mDragMode==DragRect)
|
||||
{
|
||||
//m_downDraggableResult->mDragMode = DragRight;
|
||||
m_downDraggableResult->onMouseMove_in_DragRight(event);
|
||||
}
|
||||
}
|
||||
|
||||
//后面统一刷新上方和下方rect
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
void TransparentDraggableResult::onMouseRelease_in(QMouseEvent *event)
|
||||
{
|
||||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||||
event->accept();
|
||||
//避免二次绘制框图
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void TransparentDraggableResult::onMouseRelease(QMouseEvent *event)
|
||||
{
|
||||
|
||||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||||
//上方rect同步动
|
||||
if(m_upDraggableResult)
|
||||
{
|
||||
if(mDragMode==DragRight || mDragMode==DragRect)
|
||||
{
|
||||
m_upDraggableResult->onMouseRelease_in(event);
|
||||
}
|
||||
}
|
||||
|
||||
//下方rect同步动
|
||||
if(m_downDraggableResult)
|
||||
{
|
||||
if(mDragMode==DragLeft || mDragMode==DragRect)
|
||||
{
|
||||
m_downDraggableResult->onMouseRelease_in(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMouseRelease_in(event);
|
||||
}
|
||||
|
||||
double TransparentDraggableResult::getMyLower()
|
||||
{
|
||||
double dLower = mPlot->xAxis->range().lower;
|
||||
double proposedLeft = mDragStartRange.lower;
|
||||
|
||||
TransparentDraggableResult *pDraggableRect =NULL;
|
||||
{
|
||||
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDraggable_Result.begin();
|
||||
while( it != mPlot->m_mapDraggable_Result.end() )
|
||||
{
|
||||
if(it.key() == m_strUuid)
|
||||
{
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
pDraggableRect = (TransparentDraggableResult*)it.value();
|
||||
//
|
||||
QCPRange tmpRange = pDraggableRect->getRange();
|
||||
if(tmpRange.upper >= dLower && tmpRange.upper <= proposedLeft)
|
||||
{
|
||||
dLower = tmpRange.upper;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
return dLower;
|
||||
}
|
||||
|
||||
double TransparentDraggableResult::getMyUpper()
|
||||
{
|
||||
double dUpper = mPlot->xAxis->range().upper;
|
||||
double proposedRight = mDragStartRange.upper;
|
||||
|
||||
TransparentDraggableResult *pDraggableRect =NULL;
|
||||
{
|
||||
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDraggable_Result.begin();
|
||||
while( it != mPlot->m_mapDraggable_Result.end() )
|
||||
{
|
||||
if(it.key() == m_strUuid)
|
||||
{
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
pDraggableRect = (TransparentDraggableResult*)it.value();
|
||||
//
|
||||
QCPRange tmpRange = pDraggableRect->getRange();
|
||||
if(tmpRange.lower <= dUpper && tmpRange.lower >= proposedRight)
|
||||
{
|
||||
dUpper = tmpRange.lower;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
return dUpper;
|
||||
}
|
||||
|
||||
|
|
@ -14,677 +14,57 @@ class TransparentDraggableResult : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TransparentDraggableResult(QMyCustomPlot *parentPlot, TransparentDraggableResult *upDraggableResult=nullptr, QString strUuid="", double minWidth = 1.0, QString strTitle = "")
|
||||
: QObject(parentPlot), mPlot(parentPlot), mstrTitle(strTitle), mMinWidth(minWidth)
|
||||
{
|
||||
m_upDraggableResult = upDraggableResult;
|
||||
m_strUuid = strUuid;
|
||||
//
|
||||
initRect();
|
||||
|
||||
//将自己,设置为上方rect的下方
|
||||
if(m_upDraggableResult)
|
||||
{
|
||||
m_upDraggableResult->m_downDraggableResult = this;
|
||||
}
|
||||
}
|
||||
explicit TransparentDraggableResult(QMyCustomPlot *parentPlot, TransparentDraggableResult *upDraggableResult=nullptr, QString strUuid="", double minWidth = 1.0, QString strTitle = "");
|
||||
|
||||
~TransparentDraggableResult() {
|
||||
if(mPlot) {
|
||||
// mPlot->removeItem(mRect);
|
||||
// mPlot->removeItem(mLeftHandle);
|
||||
// mPlot->removeItem(mRightHandle);
|
||||
}
|
||||
}
|
||||
~TransparentDraggableResult();
|
||||
|
||||
void 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 DrawSVGNormal(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout);
|
||||
//拉伸
|
||||
void 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 DrawSVGSteched(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout);
|
||||
//平铺
|
||||
void 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 DrawSVGTiled(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout);
|
||||
//设置最小宽度
|
||||
void setMinWidth(double minWidth){
|
||||
mMinWidth = minWidth;
|
||||
}
|
||||
|
||||
void setMinWidth(double minWidth);
|
||||
//设置标题
|
||||
void setTitle(QString strTitle){
|
||||
mstrTitle = strTitle;
|
||||
mItemTitle->setText(mstrTitle);
|
||||
mPlot->replot();
|
||||
}
|
||||
void setTitle(QString strTitle);
|
||||
|
||||
//设置解释结论
|
||||
void setResult(QString filePath){
|
||||
m_Result = filePath;
|
||||
//
|
||||
QString strLast = filePath.right(4);
|
||||
if(strLast.toLower()==".svg")
|
||||
{
|
||||
QString path,filename;
|
||||
GetWellNameAndPath(filePath, filename, path);
|
||||
QString basename = filename.left(filename.size()-4);
|
||||
|
||||
QString val=filePath;
|
||||
QImage image(320,160,QImage::Format_RGB32);
|
||||
QPainter painter(&image);
|
||||
QRectF fillRect(0,0,320,160);
|
||||
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->setPixmap(QPixmap(val)); // 设置图片
|
||||
|
||||
|
||||
// QSvgRenderer* svgRender = new QSvgRenderer();
|
||||
// svgRender->load(result);
|
||||
// //
|
||||
// QPixmap* pixmap = new QPixmap(10, 10);
|
||||
// pixmap->fill(Qt::transparent);//设置背景透明
|
||||
// QPainter p(pixmap);
|
||||
// svgRender->render(&p);
|
||||
// //
|
||||
// mPixmap->setPixmap(*pixmap); // 设置图片
|
||||
}
|
||||
else
|
||||
{
|
||||
mPixmap->setPixmap(QPixmap(filePath)); // 设置图片
|
||||
}
|
||||
|
||||
|
||||
mPlot->replot();
|
||||
}
|
||||
void setResult(QString filePath);
|
||||
|
||||
void drawResult(double left_Low, double right_Hight, double lY1, double lY2);
|
||||
// 设置矩形范围
|
||||
void setRange(double left_Low, double right_Hight) {
|
||||
if(left_Low >= right_Hight) return;
|
||||
|
||||
double lY1 = mPlot->yAxis->range().lower;//+10
|
||||
double lY2 = mPlot->yAxis->range().upper/4;
|
||||
mRect->topLeft->setCoords(left_Low, lY1);
|
||||
mRect->bottomRight->setCoords(right_Hight, lY2);
|
||||
|
||||
//位置与rect不一样,否则图像反转
|
||||
mPixmap->topLeft->setCoords(right_Hight, lY1);
|
||||
mPixmap->bottomRight->setCoords(left_Low, 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); // 设置文本在矩形中心位置
|
||||
|
||||
mItemTitle->position->setCoords((mRect->topLeft->coords().x() + mRect->bottomRight->coords().x())/2,
|
||||
lY2 + lY2/2);
|
||||
|
||||
//mRect->topLeft->setCoords(left, mPlot->yAxis->range().upper);
|
||||
//mRect->bottomRight->setCoords(right, mPlot->yAxis->range().lower);
|
||||
|
||||
updateHandles();
|
||||
//后面统一刷新上方和下方rect
|
||||
//mPlot->replot();
|
||||
}
|
||||
|
||||
void setRange(double left_Low, double right_Hight);
|
||||
// 获取当前范围
|
||||
QCPRange getRange() const {
|
||||
return QCPRange(mRect->topLeft->coords().x(), mRect->bottomRight->coords().x());
|
||||
}
|
||||
QCPRange getRange();
|
||||
|
||||
// 设置矩形颜色
|
||||
void setColor(const QColor &color) {
|
||||
mRect->setBrush(QBrush(color));
|
||||
mRect->setPen(QPen(color.darker()));
|
||||
mPlot->replot();
|
||||
}
|
||||
void setColor(const QColor &color);
|
||||
|
||||
// 删除框图
|
||||
void deleteRect() {
|
||||
if(mPlot) {
|
||||
|
||||
// mRect->deleteLater();
|
||||
// mLeftHandle->deleteLater();
|
||||
// mRightHandle->deleteLater();
|
||||
// mPixmap->deleteLater();
|
||||
|
||||
mPlot->m_mapDraggable_Result.remove(m_strUuid);
|
||||
|
||||
mPlot->removeItem(mRect);
|
||||
mPlot->removeItem(mLeftHandle);
|
||||
mPlot->removeItem(mRightHandle);
|
||||
mPlot->removeItem(mPixmap);
|
||||
mPlot->removeItem(mItemTitle);
|
||||
|
||||
mPlot->replot();
|
||||
this->deleteLater();
|
||||
|
||||
//
|
||||
// //避免二次绘制框图
|
||||
// mPlot->m_bDrawRect = false;
|
||||
// mDragMode = DragNone;
|
||||
// //取消选中框
|
||||
// mPlot->selectionRect()->cancel();
|
||||
// mPlot->replot();
|
||||
// mPlot->selectionRect()->mActive=true;
|
||||
}
|
||||
}
|
||||
void deleteRect();
|
||||
|
||||
signals:
|
||||
void rangeChanged(QCPRange newRange);
|
||||
|
||||
private:
|
||||
void initRect() {
|
||||
// 创建透明矩形
|
||||
mRect = new QCPItemRect(mPlot);
|
||||
mRect->setLayer("overlay"); // 确保在最上层
|
||||
mRect->setBrush(QBrush(QColor(100, 100, 255, 50))); // 半透明蓝色
|
||||
mRect->setPen(QPen(QColor(70, 70, 255, 200)));
|
||||
|
||||
// 创建左右边界控制点
|
||||
mLeftHandle = new QCPItemRect(mPlot);
|
||||
mLeftHandle->setLayer("overlay");
|
||||
mLeftHandle->setBrush(QBrush(Qt::red));
|
||||
mLeftHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
mRightHandle = new QCPItemRect(mPlot);
|
||||
mRightHandle->setLayer("overlay");
|
||||
mRightHandle->setBrush(QBrush(Qt::red));
|
||||
mRightHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
// 设置初始位置
|
||||
//double center = mPlot->xAxis->range().center();
|
||||
// setRange(center - 10, center + 10);
|
||||
|
||||
// 连接鼠标事件
|
||||
connect(mPlot, &QCustomPlot::mousePress, this, &TransparentDraggableResult::onMousePress);
|
||||
connect(mPlot, &QCustomPlot::mouseMove, this, &TransparentDraggableResult::onMouseMove);
|
||||
connect(mPlot, &QCustomPlot::mouseRelease, this, &TransparentDraggableResult::onMouseRelease);
|
||||
|
||||
mPixmap = new QCPItemPixmap(mPlot);
|
||||
//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::ptPlotCoords);
|
||||
//mItemTitle->position->setType(QCPItemPosition::ptAxisRectRatio);
|
||||
mItemTitle->position->setCoords(0.5, 0);
|
||||
mItemTitle->setLayer("overlay");
|
||||
}
|
||||
|
||||
void 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); // 矩形大小
|
||||
|
||||
// if(m_upDraggableResult)
|
||||
// {
|
||||
// // 右边界矩形控制点
|
||||
// m_upDraggableResult->mLeftHandle->topLeft->setParentAnchor(mRect->bottomLeft);
|
||||
// m_upDraggableResult->mLeftHandle->bottomRight->setParentAnchor(mRect->bottomRight);
|
||||
// m_upDraggableResult->mLeftHandle->topLeft->setCoords(-5, 5); // 矩形大小
|
||||
// m_upDraggableResult->mLeftHandle->bottomRight->setCoords(5, -5); // 矩形大小
|
||||
|
||||
// // 右边界矩形控制点
|
||||
// //mRect->topLeft->setParentAnchor(m_upDraggableResult->mRect->bottomLeft);
|
||||
// //m_upDraggableResult->mRect->topRight->setParentAnchor(mRect->bottomRight);
|
||||
|
||||
// // mRect->topLeft->setParentAnchor(m_upDraggableResult->mRect->bottomLeft);
|
||||
// // mRect->bottomRight->setParentAnchor(m_upDraggableResult->mRect->bottomRight);
|
||||
// }
|
||||
}
|
||||
void initRect();
|
||||
void updateHandles() ;
|
||||
|
||||
private slots:
|
||||
void onDelRect()
|
||||
{
|
||||
//mDragMode = DragNone;
|
||||
//删除框图
|
||||
deleteRect();
|
||||
}
|
||||
|
||||
// 事件过滤器处理函数
|
||||
// bool eventFilter(QObject* object, QEvent* event) {
|
||||
// if (event->type() == QEvent::MouseButtonPress) {
|
||||
// // 拦截操作
|
||||
// return true; // 阻止事件传递
|
||||
|
||||
//// if (object == action) {
|
||||
//// // 验证权限
|
||||
//// if (1) {
|
||||
//// // 允许操作
|
||||
//// action->trigger();
|
||||
//// } else {
|
||||
//// // 拦截操作
|
||||
//// return true; // 阻止事件传递
|
||||
//// }
|
||||
//// }
|
||||
// }
|
||||
// return false; // 默认不拦截其他事件
|
||||
// }
|
||||
|
||||
void 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();
|
||||
// QMenu menu(nullptr);
|
||||
// QAction *delAction = menu.addAction("删除框图");
|
||||
// //delAction->installEventFilter(this);
|
||||
// connect(delAction, &QAction::triggered, this, &TransparentDraggableResult::onDelRect);
|
||||
// QAction* pItem = menu.exec(event->globalPos());
|
||||
// if(pItem == delAction)
|
||||
// {
|
||||
// //event->accept();
|
||||
// int ii=0;
|
||||
// ii++;
|
||||
// }
|
||||
// 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;
|
||||
|
||||
//上方rect同步动
|
||||
if(m_upDraggableResult)
|
||||
{
|
||||
if(mDragMode==DragRight || mDragMode==DragRect)
|
||||
{
|
||||
m_upDraggableResult->mDragMode = DragLeft;
|
||||
m_upDraggableResult->mDragStartY = y;
|
||||
m_upDraggableResult->mDragStartRange = m_upDraggableResult->getRange();
|
||||
}
|
||||
}
|
||||
|
||||
//下方rect同步动
|
||||
if(m_downDraggableResult)
|
||||
{
|
||||
if(mDragMode==DragLeft || mDragMode==DragRect)
|
||||
{
|
||||
m_downDraggableResult->mDragMode = DragRight;
|
||||
m_downDraggableResult->mDragStartY = y;
|
||||
m_downDraggableResult->mDragStartRange = m_downDraggableResult->getRange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onMouseMove_in(QMouseEvent *event) {
|
||||
//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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRange(newRange.lower, newRange.upper);
|
||||
}
|
||||
|
||||
void onMouseMove_in_DragLeft(QMouseEvent *event) {
|
||||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());
|
||||
double dy = y - mDragStartY;
|
||||
|
||||
QCPRange newRange = mDragStartRange;
|
||||
double proposedLeft = mDragStartRange.lower + dy;
|
||||
// 确保不超出轴范围且不使宽度小于最小值
|
||||
newRange.lower = qBound(
|
||||
getMyLower(),
|
||||
proposedLeft,
|
||||
mDragStartRange.upper - mMinWidth);
|
||||
|
||||
|
||||
// 最终确保宽度不小于最小值(针对整体拖动的情况)
|
||||
if(newRange.size() < mMinWidth) {
|
||||
newRange.lower = newRange.upper - mMinWidth;
|
||||
}
|
||||
|
||||
setRange(newRange.lower, newRange.upper);
|
||||
}
|
||||
|
||||
|
||||
void onMouseMove_in_DragRight(QMouseEvent *event) {
|
||||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());
|
||||
double dy = y - mDragStartY;
|
||||
|
||||
QCPRange newRange = mDragStartRange;
|
||||
double proposedRight = mDragStartRange.upper + dy;
|
||||
// 确保不超出轴范围且不使宽度小于最小值
|
||||
newRange.upper = qBound(
|
||||
mDragStartRange.lower + mMinWidth,
|
||||
proposedRight,
|
||||
getMyUpper());
|
||||
|
||||
// 最终确保宽度不小于最小值(针对整体拖动的情况)
|
||||
if(newRange.size() < mMinWidth) {
|
||||
newRange.upper = newRange.lower + mMinWidth;
|
||||
}
|
||||
setRange(newRange.lower, newRange.upper);
|
||||
}
|
||||
|
||||
void onMouseMove(QMouseEvent *event) {
|
||||
if(mDragMode == DragNone) return;
|
||||
|
||||
event->accept();
|
||||
|
||||
onMouseMove_in(event);
|
||||
|
||||
//上方rect同步动
|
||||
if(m_upDraggableResult)
|
||||
{
|
||||
if(mDragMode==DragRight || mDragMode==DragRect)
|
||||
{
|
||||
//m_upDraggableResult->mDragMode = DragLeft;
|
||||
m_upDraggableResult->onMouseMove_in_DragLeft(event);
|
||||
}
|
||||
}
|
||||
|
||||
//下方rect同步动
|
||||
if(m_downDraggableResult)
|
||||
{
|
||||
if(mDragMode==DragLeft || mDragMode==DragRect)
|
||||
{
|
||||
//m_downDraggableResult->mDragMode = DragRight;
|
||||
m_downDraggableResult->onMouseMove_in_DragRight(event);
|
||||
}
|
||||
}
|
||||
|
||||
//后面统一刷新上方和下方rect
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
void onMouseRelease_in(QMouseEvent *event) {
|
||||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||||
event->accept();
|
||||
//避免二次绘制框图
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void onMouseRelease(QMouseEvent *event) {
|
||||
|
||||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||||
//上方rect同步动
|
||||
if(m_upDraggableResult)
|
||||
{
|
||||
if(mDragMode==DragRight || mDragMode==DragRect)
|
||||
{
|
||||
m_upDraggableResult->onMouseRelease_in(event);
|
||||
}
|
||||
}
|
||||
|
||||
//下方rect同步动
|
||||
if(m_downDraggableResult)
|
||||
{
|
||||
if(mDragMode==DragLeft || mDragMode==DragRect)
|
||||
{
|
||||
m_downDraggableResult->onMouseRelease_in(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMouseRelease_in(event);
|
||||
}
|
||||
|
||||
double getMyLower()
|
||||
{
|
||||
double dLower = mPlot->xAxis->range().lower;
|
||||
double proposedLeft = mDragStartRange.lower;
|
||||
|
||||
TransparentDraggableResult *pDraggableRect =NULL;
|
||||
{
|
||||
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDraggable_Result.begin();
|
||||
while( it != mPlot->m_mapDraggable_Result.end() )
|
||||
{
|
||||
if(it.key() == m_strUuid)
|
||||
{
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
pDraggableRect = (TransparentDraggableResult*)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;
|
||||
|
||||
TransparentDraggableResult *pDraggableRect =NULL;
|
||||
{
|
||||
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDraggable_Result.begin();
|
||||
while( it != mPlot->m_mapDraggable_Result.end() )
|
||||
{
|
||||
if(it.key() == m_strUuid)
|
||||
{
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
pDraggableRect = (TransparentDraggableResult*)it.value();
|
||||
//
|
||||
QCPRange tmpRange = pDraggableRect->getRange();
|
||||
if(tmpRange.lower <= dUpper && tmpRange.lower >= proposedRight)
|
||||
{
|
||||
dUpper = tmpRange.lower;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
return dUpper;
|
||||
}
|
||||
void onDelRect();
|
||||
void onMousePress(QMouseEvent *event);
|
||||
void onMouseMove(QMouseEvent *event);
|
||||
void onMouseRelease(QMouseEvent *event);
|
||||
//
|
||||
void onMouseMove_in(QMouseEvent *event);
|
||||
void onMouseMove_in_DragLeft(QMouseEvent *event);
|
||||
void onMouseMove_in_DragRight(QMouseEvent *event);
|
||||
void onMouseRelease_in(QMouseEvent *event);
|
||||
|
||||
double getMyLower();
|
||||
double getMyUpper();
|
||||
|
||||
private:
|
||||
QMyCustomPlot *mPlot;
|
||||
QCPItemRect *mRect;
|
||||
|
|
|
|||
729
logPlus/TransparentDraggableSwallCore.cpp
Normal file
729
logPlus/TransparentDraggableSwallCore.cpp
Normal file
|
|
@ -0,0 +1,729 @@
|
|||
#include "TransparentDraggableSwallCore.h"
|
||||
|
||||
extern double g_dPixelPerCm;//每厘米像素数
|
||||
//static GeoIndicatorGenerator m_drawGeo;
|
||||
|
||||
TransparentDraggableSwallCore::TransparentDraggableSwallCore(QMyCustomPlot *parentPlot, QString strUuid, double minWidth, QString strTitle)
|
||||
: QObject(parentPlot), mPlot(parentPlot), mstrTitle(strTitle), mMinWidth(minWidth)
|
||||
{
|
||||
m_strUuid = strUuid;
|
||||
//
|
||||
initRect();
|
||||
}
|
||||
|
||||
TransparentDraggableSwallCore::~TransparentDraggableSwallCore()
|
||||
{
|
||||
if(mPlot) {
|
||||
// mPlot->removeItem(mRect);
|
||||
// mPlot->removeItem(mLeftHandle);
|
||||
// mPlot->removeItem(mRightHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void TransparentDraggableSwallCore::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 TransparentDraggableSwallCore::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 TransparentDraggableSwallCore::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 TransparentDraggableSwallCore::setMinWidth(double minWidth)
|
||||
{
|
||||
mMinWidth = minWidth;
|
||||
}
|
||||
|
||||
//设置标题
|
||||
void TransparentDraggableSwallCore::setTitle(QString strTitle)
|
||||
{
|
||||
mstrTitle = strTitle;
|
||||
mItemTitle->setText(mstrTitle);
|
||||
//mPlot->replot();
|
||||
}
|
||||
|
||||
//设置解释结论
|
||||
void TransparentDraggableSwallCore::setLith(QString filePath)
|
||||
{
|
||||
m_Lith = filePath;
|
||||
}
|
||||
|
||||
void TransparentDraggableSwallCore::drawLith(double left_Low, double right_Hight, double lY1, double lY2)
|
||||
{
|
||||
if(m_Lith=="")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
double x1 = mPlot->xAxis->coordToPixel(left_Low);
|
||||
double x2 = mPlot->xAxis->coordToPixel((left_Low+right_Hight)/2);
|
||||
double y1 = mPlot->yAxis->coordToPixel(lY1);
|
||||
double y2 = mPlot->yAxis->coordToPixel(lY1+(lY2-lY1)/5);
|
||||
|
||||
bool bWidthBig = false;
|
||||
double newWidth = y2-y1;
|
||||
double newHeight = x1-x2;
|
||||
// if(newWidth>newHeight)
|
||||
// {
|
||||
// //取小,画正方形框
|
||||
// newWidth = newHeight;
|
||||
// bWidthBig = true;
|
||||
// }
|
||||
|
||||
//
|
||||
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);
|
||||
//
|
||||
//painter.setBrush(QBrush(QPixmap(colorPath)));
|
||||
// //颜色
|
||||
// QString strLastColor = m_Color.right(4);
|
||||
// if(strLastColor.toLower()==".svg")
|
||||
// {
|
||||
// //拉伸
|
||||
// DrawSVGSteched(&painter,m_Color,fillRect,0);
|
||||
// }
|
||||
|
||||
// bool isStrech=false;
|
||||
// QSvgRenderer m_SvgRenderer;
|
||||
// m_SvgRenderer.load(filePath);
|
||||
// if(!isStrech){
|
||||
// float oil_h = fillRect.width();
|
||||
// oil_h = (oil_h / 2 >= fillRect.height() / 2) ? fillRect.height() : oil_h;
|
||||
// float rect_y = fillRect.y() + fillRect.height() / 2 - oil_h / 2;
|
||||
// fillRect.setY(rect_y);
|
||||
// fillRect.setHeight(oil_h);
|
||||
// }
|
||||
// fillRect.setX(fillRect.x() + 1);
|
||||
// m_SvgRenderer.render(&painter, fillRect);
|
||||
|
||||
//拉伸
|
||||
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_Lith->setPixmap(QPixmap(val)); // 设置图片
|
||||
|
||||
|
||||
// QSvgRenderer* svgRender = new QSvgRenderer();
|
||||
// svgRender->load(result);
|
||||
// //
|
||||
// QPixmap* pixmap = new QPixmap(10, 10);
|
||||
// pixmap->fill(Qt::transparent);//设置背景透明
|
||||
// QPainter p(pixmap);
|
||||
// svgRender->render(&p);
|
||||
// //
|
||||
// mPixmap->setPixmap(*pixmap); // 设置图片
|
||||
}
|
||||
else
|
||||
{
|
||||
// QString val=filePath;
|
||||
// QImage image(47,16,QImage::Format_RGB32);
|
||||
// QPainter painter(&image);
|
||||
// QRectF fillRect(0,0,47,16);
|
||||
// painter.fillRect(fillRect, QColor(0, 0, 0, 0));
|
||||
// //
|
||||
// painter.setBrush(QBrush(QPixmap(colorPath)));
|
||||
|
||||
// QPixmap* pixmap = new QPixmap(filePath);
|
||||
// pixmap->fill(Qt::transparent);//设置背景透明
|
||||
// mPixmap_Lith->setPixmap(*pixmap); // 设置图片
|
||||
|
||||
//mPixmap_Lith->setPixmap(QPixmap(filePath)); // 设置图片
|
||||
|
||||
|
||||
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);
|
||||
// //颜色
|
||||
// QString strLastColor = m_Color.right(4);
|
||||
// if(strLastColor.toLower()==".svg")
|
||||
// {
|
||||
// //拉伸
|
||||
// DrawSVGSteched(&painter,m_Color,fillRect,0);
|
||||
// }
|
||||
//
|
||||
bool isOne=true;
|
||||
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
|
||||
|
||||
// mPixmap_Lith->topLeft->setCoords(right_Hight, lY1+(lY2-lY1)/4);
|
||||
// mPixmap_Lith->bottomRight->setCoords(left_Low, lY2);
|
||||
|
||||
//mPlot->replot();
|
||||
}
|
||||
|
||||
//设置m_Oil
|
||||
void TransparentDraggableSwallCore::setOil(QString filePath)
|
||||
{
|
||||
m_Oil = filePath;
|
||||
}
|
||||
|
||||
void TransparentDraggableSwallCore::drawOil(double left_Low, double right_Hight, double lY1, double lY2)
|
||||
{
|
||||
if(m_Oil=="")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
double x1 = mPlot->xAxis->coordToPixel((left_Low+right_Hight)/2);
|
||||
double x2 = mPlot->xAxis->coordToPixel(right_Hight);
|
||||
double y1 = mPlot->yAxis->coordToPixel(lY1);
|
||||
double y2 = mPlot->yAxis->coordToPixel(lY1+(lY2-lY1)/5);
|
||||
|
||||
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)); // 设置图片
|
||||
}
|
||||
|
||||
mPixmap_Oil->topLeft->setCoords(xNewRight, mPlot->yAxis->pixelToCoord(y1+1)); //right_Hight, lY1
|
||||
mPixmap_Oil->bottomRight->setCoords(xNewLeft, mPlot->yAxis->pixelToCoord(y2-1)); //left_Low
|
||||
|
||||
//mPlot->replot();
|
||||
}
|
||||
|
||||
|
||||
// 设置矩形范围
|
||||
void TransparentDraggableSwallCore::setRange(double left_Low, double right_Hight)
|
||||
{
|
||||
if(left_Low >= right_Hight) return;
|
||||
|
||||
double lY1 = mPlot->yAxis->range().lower;//+10
|
||||
double lY2 = mPlot->yAxis->range().upper;
|
||||
|
||||
mRect->topLeft->setCoords(left_Low, lY1);
|
||||
mRect->bottomRight->setCoords(right_Hight, lY1+(lY2-lY1)/3);
|
||||
|
||||
// //位置与rect不一样,否则图像反转
|
||||
// mPixmap_Color->topLeft->setCoords(right_Hight, lY1+(lY2-lY1)/4);
|
||||
// mPixmap_Color->bottomRight->setCoords(left_Low, lY2);
|
||||
//
|
||||
//mPixmap_Lith->topLeft->setCoords(right_Hight, lY1+(lY2-lY1)/4);
|
||||
//mPixmap_Lith->bottomRight->setCoords(left_Low, lY2);
|
||||
drawLith(left_Low, right_Hight, lY1, lY2);
|
||||
|
||||
//位置与rect不一样,否则图像反转
|
||||
//mPixmap_Oil->topLeft->setCoords(right_Hight, lY1);
|
||||
//mPixmap_Oil->bottomRight->setCoords(left_Low, lY1+(lY2-lY1)/4);
|
||||
drawOil(left_Low, right_Hight, lY1, lY2);
|
||||
|
||||
//mItemTitle->position->setCoords(0.5, 0.5);
|
||||
// 设置父锚点,定位点
|
||||
//mItemTitle->position->setParentAnchor(mRect->bottom);
|
||||
mItemTitle->position->setCoords(mRect->bottomRight->coords().x(), //(mRect->topLeft->coords().x() + mRect->bottomRight->coords().x())/2,
|
||||
lY1+(lY2-lY1)/4); //(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);
|
||||
|
||||
updateHandles();
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
// 获取当前范围
|
||||
QCPRange TransparentDraggableSwallCore::getRange()
|
||||
{
|
||||
return QCPRange(mRect->topLeft->coords().x(), mRect->bottomRight->coords().x());
|
||||
}
|
||||
|
||||
// 设置矩形颜色
|
||||
void TransparentDraggableSwallCore::setColor(const QColor &color)
|
||||
{
|
||||
mRect->setBrush(QBrush(color));
|
||||
mRect->setPen(QPen(color.darker()));
|
||||
mPlot->replot();
|
||||
}
|
||||
|
||||
// 删除框图
|
||||
void TransparentDraggableSwallCore::deleteRect()
|
||||
{
|
||||
if(mPlot) {
|
||||
|
||||
// mRect->deleteLater();
|
||||
// mLeftHandle->deleteLater();
|
||||
// mRightHandle->deleteLater();
|
||||
// mPixmap->deleteLater();
|
||||
|
||||
mPlot->m_mapDraggable_SwallCore.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);
|
||||
|
||||
mPlot->replot();
|
||||
this->deleteLater();
|
||||
|
||||
//
|
||||
// //避免二次绘制框图
|
||||
// mPlot->m_bDrawRect = false;
|
||||
// mDragMode = DragNone;
|
||||
// //取消选中框
|
||||
// mPlot->selectionRect()->cancel();
|
||||
// mPlot->replot();
|
||||
// mPlot->selectionRect()->mActive=true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TransparentDraggableSwallCore::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::red));
|
||||
// mLeftHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
// mRightHandle = new QCPItemRect(mPlot);
|
||||
// mRightHandle->setLayer("overlay");
|
||||
// mRightHandle->setBrush(QBrush(Qt::red));
|
||||
// mRightHandle->setPen(QPen(Qt::darkRed));
|
||||
|
||||
// 设置初始位置
|
||||
//double center = mPlot->xAxis->range().center();
|
||||
// setRange(center - 10, center + 10);
|
||||
|
||||
// 连接鼠标事件
|
||||
connect(mPlot, &QCustomPlot::mousePress, this, &TransparentDraggableSwallCore::onMousePress);
|
||||
connect(mPlot, &QCustomPlot::mouseMove, this, &TransparentDraggableSwallCore::onMouseMove);
|
||||
connect(mPlot, &QCustomPlot::mouseRelease, this, &TransparentDraggableSwallCore::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(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 TransparentDraggableSwallCore::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 TransparentDraggableSwallCore::onDelRect()
|
||||
{
|
||||
//mDragMode = DragNone;
|
||||
//删除框图
|
||||
deleteRect();
|
||||
}
|
||||
|
||||
void TransparentDraggableSwallCore::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();
|
||||
// QMenu menu(nullptr);
|
||||
// QAction *delAction = menu.addAction("删除框图");
|
||||
// //delAction->installEventFilter(this);
|
||||
// connect(delAction, &QAction::triggered, this, &TransparentDraggableResult::onDelRect);
|
||||
// QAction* pItem = menu.exec(event->globalPos());
|
||||
// if(pItem == delAction)
|
||||
// {
|
||||
// //event->accept();
|
||||
// int ii=0;
|
||||
// ii++;
|
||||
// }
|
||||
// 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;
|
||||
|
||||
}
|
||||
|
||||
void TransparentDraggableSwallCore::onMouseMove(QMouseEvent *event)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRange(newRange.lower, newRange.upper);
|
||||
|
||||
}
|
||||
|
||||
void TransparentDraggableSwallCore::onMouseRelease(QMouseEvent *event)
|
||||
{
|
||||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||||
event->accept();
|
||||
//避免二次绘制框图
|
||||
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 TransparentDraggableSwallCore::getMyLower()
|
||||
{
|
||||
double dLower = mPlot->xAxis->range().lower;
|
||||
double proposedLeft = mDragStartRange.lower;
|
||||
|
||||
TransparentDraggableSwallCore *pDraggableRect =NULL;
|
||||
{
|
||||
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDraggable_SwallCore.begin();
|
||||
while( it != mPlot->m_mapDraggable_SwallCore.end() )
|
||||
{
|
||||
if(it.key() == m_strUuid)
|
||||
{
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
pDraggableRect = (TransparentDraggableSwallCore*)it.value();
|
||||
//
|
||||
QCPRange tmpRange = pDraggableRect->getRange();
|
||||
if(tmpRange.upper >= dLower && tmpRange.upper <= proposedLeft)
|
||||
{
|
||||
dLower = tmpRange.upper;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
return dLower;
|
||||
}
|
||||
|
||||
double TransparentDraggableSwallCore::getMyUpper()
|
||||
{
|
||||
double dUpper = mPlot->xAxis->range().upper;
|
||||
double proposedRight = mDragStartRange.upper;
|
||||
|
||||
TransparentDraggableSwallCore *pDraggableRect =NULL;
|
||||
{
|
||||
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDraggable_SwallCore.begin();
|
||||
while( it != mPlot->m_mapDraggable_SwallCore.end() )
|
||||
{
|
||||
if(it.key() == m_strUuid)
|
||||
{
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
pDraggableRect = (TransparentDraggableSwallCore*)it.value();
|
||||
//
|
||||
QCPRange tmpRange = pDraggableRect->getRange();
|
||||
if(tmpRange.lower <= dUpper && tmpRange.lower >= proposedRight)
|
||||
{
|
||||
dUpper = tmpRange.lower;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
return dUpper;
|
||||
}
|
||||
97
logPlus/TransparentDraggableSwallCore.h
Normal file
97
logPlus/TransparentDraggableSwallCore.h
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#ifndef TRANSPARENTDRAGGABLESWALLCORE_H
|
||||
#define TRANSPARENTDRAGGABLESWALLCORE_H
|
||||
|
||||
#include <QObject>
|
||||
#include "qmycustomplot.h"
|
||||
#include <QString>
|
||||
#include <QMenu>
|
||||
#include "geometryutils.h"
|
||||
#include <QSvgRenderer>
|
||||
#include "GeoIndicatorGenerator.h"
|
||||
|
||||
#pragma execution_character_set("utf-8") // 强制指定执行字符集为 UTF-8
|
||||
|
||||
|
||||
class TransparentDraggableSwallCore : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TransparentDraggableSwallCore(QMyCustomPlot *parentPlot, QString strUuid="", double minWidth = 1.0, QString strTitle = "");
|
||||
|
||||
~TransparentDraggableSwallCore();
|
||||
|
||||
void DrawSVGNormal(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout);
|
||||
//拉伸
|
||||
void DrawSVGSteched(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout);
|
||||
//平铺
|
||||
void DrawSVGTiled(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout);
|
||||
//设置最小宽度
|
||||
void setMinWidth(double minWidth);
|
||||
//设置标题
|
||||
void setTitle(QString strTitle);
|
||||
|
||||
//设置解释结论
|
||||
void setLith(QString filePath);
|
||||
void drawLith(double left_Low, double right_Hight, double lY1, double lY2);
|
||||
|
||||
//设置m_Oil
|
||||
void setOil(QString filePath);
|
||||
void drawOil(double left_Low, double right_Hight, double lY1, double lY2);
|
||||
|
||||
// 设置矩形范围
|
||||
void setRange(double left_Low, double right_Hight);
|
||||
// 获取当前范围
|
||||
QCPRange getRange();
|
||||
|
||||
// 设置矩形颜色
|
||||
void setColor(const QColor &color);
|
||||
|
||||
// 删除框图
|
||||
void deleteRect();
|
||||
|
||||
signals:
|
||||
void rangeChanged(QCPRange newRange);
|
||||
|
||||
private:
|
||||
void initRect();
|
||||
void updateHandles() ;
|
||||
|
||||
private slots:
|
||||
void onDelRect();
|
||||
void onMousePress(QMouseEvent *event);
|
||||
void onMouseMove(QMouseEvent *event);
|
||||
void onMouseRelease(QMouseEvent *event);
|
||||
double getMyLower();
|
||||
double getMyUpper();
|
||||
|
||||
private:
|
||||
QMyCustomPlot *mPlot;
|
||||
QCPItemRect *mRect;
|
||||
// QCPItemRect *mLeftHandle;
|
||||
// QCPItemRect *mRightHandle;
|
||||
|
||||
QCPItemPixmap *mPixmap_Lith;
|
||||
QCPItemPixmap *mPixmap_Oil;
|
||||
//QCPItemPixmap *mPixmap_Color;
|
||||
QCPItemText *mItemTitle;
|
||||
QString mstrTitle="";
|
||||
QString m_strUuid = "";
|
||||
|
||||
QString m_Lith;
|
||||
QString m_Oil;
|
||||
//QString m_Color;
|
||||
int m_ind;
|
||||
|
||||
GeoIndicatorGenerator m_drawGeo;
|
||||
|
||||
enum DragMode { DragNone, DragLeft, DragRight, DragRect };
|
||||
DragMode mDragMode = DragNone;
|
||||
//double mDragStartX = 0;
|
||||
double mDragStartY = 0;
|
||||
QCPRange mDragStartRange;
|
||||
|
||||
// 添加最小宽度成员变量
|
||||
double mMinWidth;
|
||||
};
|
||||
|
||||
#endif // TRANSPARENTDRAGGABLESWALLCORE_H
|
||||
|
|
@ -30,6 +30,9 @@ extern int g_iCanZoom ;
|
|||
extern double g_dPixelPerCm;//每厘米像素数
|
||||
extern int g_iScale;
|
||||
|
||||
extern int g_iSupport3D;
|
||||
|
||||
|
||||
extern void AppendConsole(Priority priority, const QString &output);
|
||||
|
||||
//曲线绘制(多个)
|
||||
|
|
@ -262,7 +265,15 @@ void FormDraw::s_addWave(QString strUuid, QString strSlfName, QString strWellNam
|
|||
// curv->setSizePolicy(policy);
|
||||
|
||||
curv->show();
|
||||
initWave(curv, strSlfName, strWaveName);
|
||||
if(g_iSupport3D)
|
||||
{
|
||||
initWave_3D(curv, strSlfName, strWaveName);
|
||||
}
|
||||
else
|
||||
{
|
||||
initWave(curv, strSlfName, strWaveName);
|
||||
}
|
||||
|
||||
connect(curv, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(s_mouseWheel(QWheelEvent*)));
|
||||
|
||||
//
|
||||
|
|
@ -272,7 +283,9 @@ 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" || strLineName == "WORDS_RELUST" || strLineName == "RESULT")
|
||||
if(strLineName == "FRAC_HOLE.TABLE" || strLineName == "WORDS_RELUST" || strLineName == "RESULT"
|
||||
|| strLineName == "GEO_LITH" || strLineName == "SWALL_CORE"
|
||||
|| strLineName == "GUJING1_RESULT" || strLineName == "GUJING2_RESULT" || strLineName == "GUJING3_RESULT")
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -350,6 +363,22 @@ void FormDraw::s_addTableLine(QString strUuid, QString strSlfName, QString strWe
|
|||
//解释结论
|
||||
initResult(curv, strSlfName, strLineName);
|
||||
}
|
||||
else if(strLineName == "GEO_LITH")
|
||||
{
|
||||
//录井剖面
|
||||
initGeoLith(curv, strSlfName, strLineName);
|
||||
}
|
||||
else if(strLineName == "SWALL_CORE")
|
||||
{
|
||||
//井壁取心
|
||||
initSwallCore(curv, strSlfName, strLineName);
|
||||
}
|
||||
else if(strLineName == "GUJING1_RESULT" || strLineName == "GUJING2_RESULT" || strLineName == "GUJING3_RESULT")
|
||||
{
|
||||
//固井结论
|
||||
initGujing(curv, strSlfName, strLineName);
|
||||
}
|
||||
|
||||
connect(curv, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(s_mouseWheel(QWheelEvent*)));
|
||||
|
||||
//
|
||||
|
|
@ -1008,7 +1037,7 @@ double GetData(int RepCode,char *buffer)
|
|||
void FormDraw::initWave(QMyCustomPlot *widget, QString strSlfName, QString strWaveName)
|
||||
{
|
||||
CLogIO *logio=new CLogIO();
|
||||
logio->Open(strSlfName.toStdString().c_str(),CSlfIO::modeRead);
|
||||
logio->Open(strSlfName.toStdString().c_str(), CSlfIO::modeRead);
|
||||
//
|
||||
int index=logio->OpenWave(strWaveName.toStdString().c_str());
|
||||
if(index<0) {
|
||||
|
|
@ -1112,6 +1141,320 @@ void FormDraw::initWave(QMyCustomPlot *widget, QString strSlfName, QString strWa
|
|||
}
|
||||
}
|
||||
|
||||
// 添加色标:
|
||||
QCPColorScale *colorScale = new QCPColorScale(widget);
|
||||
colorMap->setColorScale(colorScale); // 将颜色图与色标关联
|
||||
// 将颜色贴图的“颜色渐变”设置为其中一个预设
|
||||
//colorMap->setGradient(QCPColorGradient::gpPolar);//gpJet);
|
||||
// 我们还可以创建一个QCPColorGradient实例并向其中添加自己的颜色
|
||||
// 渐变,请参阅QCPColorGradient的文档以获取可能的效果.
|
||||
int nIndex=11;
|
||||
QVector<MyColorItem> colorList;
|
||||
bool inpolation = true;
|
||||
int iColorNum = getSystemColor(nIndex, colorList, inpolation);
|
||||
//
|
||||
QCPColorGradient gradient;
|
||||
for(int i=0; i<iColorNum; i++)
|
||||
{
|
||||
double dbTmpIndex=(double)(i+1)/iColorNum;
|
||||
gradient.setColorStopAt(dbTmpIndex, colorList[i].color); // x% 位置的颜色
|
||||
}
|
||||
colorMap->setGradient(gradient);
|
||||
// 重新缩放数据维度(颜色),以使所有数据点都位于颜色渐变显示的范围内:
|
||||
colorMap->rescaleDataRange();
|
||||
|
||||
//----调色板--------
|
||||
// widget->plotLayout()->addElement(0, 1, colorScale); // 将其添加到主轴矩形的右侧
|
||||
// colorScale->setType(QCPAxis::atRight); // 刻度应为垂直条,刻度线/坐标轴标签右侧(实际上,右侧已经是默认值)
|
||||
// colorScale->axis()->setLabel("Magnetic Field Strength");
|
||||
// //确保轴rect和色标同步其底边距和顶边距(以便它们对齐):
|
||||
// QCPMarginGroup *marginGroup = new QCPMarginGroup(widget);
|
||||
// widget->axisRect()->setMarginGroup(QCP::msBottom|QCP::msTop, marginGroup);
|
||||
// colorScale->setMarginGroup(QCP::msBottom|QCP::msTop, marginGroup);
|
||||
|
||||
// 重新缩放键(x)和值(y)轴,以便可以看到整个颜色图:
|
||||
//widget->rescaleAxes();
|
||||
|
||||
QString strAliasName = "";
|
||||
QString strUnit = "";
|
||||
QColor newlineColor=QColor(0,0,0);
|
||||
double width=2;
|
||||
QString strScaleType = "";
|
||||
//道-对象
|
||||
m_formTrack->Add(strSlfName, m_strWellName, m_strTrackName, strWaveName, strAliasName, strUnit, newlineColor, width, _nSamples, 0, strScaleType, "waveObject");
|
||||
}
|
||||
|
||||
void FormDraw::initWave_3D(QMyCustomPlot *widget, QString strSlfName, QString strWaveName)
|
||||
{
|
||||
CLogIO *logio=new CLogIO();
|
||||
logio->Open(strSlfName.toStdString().c_str(), CSlfIO::modeRead);
|
||||
//
|
||||
int index=logio->OpenWave(strWaveName.toStdString().c_str());
|
||||
if(index<0) {
|
||||
delete logio;
|
||||
return;
|
||||
}
|
||||
|
||||
Slf_WAVE _wave;
|
||||
logio->GetWaveInfo(index, &_wave);
|
||||
float _SDep,_EDep,_Rlev;
|
||||
_SDep = _wave.StartDepth;
|
||||
_EDep = _wave.EndDepth;
|
||||
// _SDep = 0.0 - g_iY2;
|
||||
// _EDep = 0.0 - g_iY1;
|
||||
_Rlev = _wave.DepLevel;
|
||||
int m_Record=(float)(fabs((_EDep-_SDep)/_Rlev+0.5));
|
||||
|
||||
int _nSamples = _wave.TimeSamples;
|
||||
|
||||
char *value=new char[(_nSamples+1)*m_Record*_wave.CodeLen+1];
|
||||
logio->ReadWave(index,_SDep,m_Record,(void *)value);
|
||||
logio->CloseWave(index);
|
||||
delete logio;
|
||||
|
||||
bool bFistValue=false;
|
||||
float vmax = -9999;//(float)_nSamples;
|
||||
float vmin = -9999;
|
||||
//
|
||||
double** wavedata;
|
||||
wavedata = new double*[_nSamples];
|
||||
for(int kk = 0;kk<_nSamples;kk++){
|
||||
wavedata[kk] = new double[m_Record];
|
||||
}
|
||||
|
||||
for (int i=0; i<m_Record; i++)
|
||||
{
|
||||
for(int kk = 0;kk<_nSamples;kk++)
|
||||
{
|
||||
double val = GetData(_wave.RepCode,(char *)&value[(kk)*_wave.CodeLen+i*_nSamples*_wave.CodeLen]);
|
||||
wavedata[kk][i] = val;
|
||||
if(val==-9999)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(bFistValue==false)
|
||||
{
|
||||
//最大值,最小值默认采用第一个有效值
|
||||
bFistValue=true;
|
||||
vmax = vmin = val;
|
||||
}
|
||||
//
|
||||
if(vmax<val)vmax=val;
|
||||
if(vmin>val)vmin=val;
|
||||
}
|
||||
}
|
||||
delete[] value;
|
||||
|
||||
// vmax = (float)_nSamples;
|
||||
// vmin = 0;
|
||||
|
||||
// g_iY1 = 0.0 -_EDep;
|
||||
// g_iY2 = 0.0 -_SDep;
|
||||
//------------------------
|
||||
widget->m_iX1 = vmin;
|
||||
widget->m_iX2 = vmax;
|
||||
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;
|
||||
|
||||
//
|
||||
// 横向点数,全部绘制
|
||||
int nPoint = _nSamples;
|
||||
nPoint = nPoint / 2;
|
||||
// 初始化
|
||||
float *flSin,*flCos;
|
||||
QPointF *pt;
|
||||
flSin = new float[_nSamples+1];
|
||||
flCos = new float[_nSamples+1];
|
||||
pt = new QPointF[_nSamples+1];
|
||||
//
|
||||
float m_flWjMaxFactor=0.6; //外径最大位置占道的比例
|
||||
int iMyWidth = widget->axisRect(0)->width();
|
||||
// 最大外径宽度
|
||||
float r = m_flWjMaxFactor*(iMyWidth-0)/2;
|
||||
//
|
||||
float centerX = (iMyWidth+0)/2.0;
|
||||
float angle = 3.0*3.1415926/2.0;
|
||||
float xspeed = (3.1415926/(nPoint-1)); // 半圆
|
||||
float x=-r;
|
||||
float m_flVFactor = 0.5;
|
||||
float centerY = 0;
|
||||
float y;
|
||||
for (int j=0;j<nPoint; j++)
|
||||
{
|
||||
// 第一种方法:按角度平均分配,图像中间部分有些不真实
|
||||
//x = sin(angle) * r;
|
||||
//y = cos(angle) * r*m_flVFactor;
|
||||
|
||||
//方法2 :按横向等间距分配,图像边缘部分不太好
|
||||
// flCos[j] = cos(angle);
|
||||
// flSin[j] = sin(angle);
|
||||
y = cos(angle)*r*m_flVFactor;
|
||||
|
||||
pt[j].setX(centerX + x);
|
||||
pt[j].setY(centerY + y);
|
||||
angle += xspeed;
|
||||
x += (float)(r*2./(nPoint-1.));
|
||||
}
|
||||
|
||||
//
|
||||
// 最大外径宽度
|
||||
float *fl_x_Coord = new float[_nSamples+1];
|
||||
float r_Coord = m_flWjMaxFactor*(_nSamples-0)/2;
|
||||
float centerX_Coord = (_nSamples+0)/2.0;
|
||||
float x_Coord=-r_Coord;
|
||||
for (int j=0;j<nPoint; j++)
|
||||
{
|
||||
fl_x_Coord[j] = (centerX + x_Coord);
|
||||
x_Coord += (float)(r_Coord*2./(nPoint-1.));
|
||||
}
|
||||
|
||||
//---------------------------------
|
||||
//转换新值
|
||||
double** wavedataNew;
|
||||
wavedataNew = new double*[_nSamples];
|
||||
for(int kk = 0;kk<_nSamples;kk++){
|
||||
wavedataNew[kk] = new double[m_Record];
|
||||
}
|
||||
//初始化
|
||||
for (int i=0; i<m_Record; i++)
|
||||
{
|
||||
for(int kk = 0;kk<_nSamples;kk++)
|
||||
{
|
||||
wavedataNew[kk][i] = vmin;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_Record ; i++)
|
||||
{
|
||||
int d=1;
|
||||
for (int j=0; j<nPoint-d; j+=d)
|
||||
{
|
||||
|
||||
float tempValue = -(_SDep + _Rlev*i);
|
||||
|
||||
double lY1 = fl_x_Coord[j]; //
|
||||
double lY2 = fl_x_Coord[j+d]; //
|
||||
//double lY1 = widget->yAxis->pixelToCoord(pt[j].x()); //+10 fl_x_Coord[j]; //
|
||||
//double lY2 = widget->yAxis->pixelToCoord(pt[j+d].x()); //fl_x_Coord[j+d]; //
|
||||
double left_Low = widget->xAxis->pixelToCoord( widget->xAxis->coordToPixel(tempValue)+pt[j].y());// + widget->xAxis->pixelToCoord(pt[j].y());
|
||||
double right_Hight = widget->xAxis->pixelToCoord( widget->xAxis->coordToPixel(tempValue + _Rlev)+pt[j+1].y());// + widget->xAxis->pixelToCoord(pt[j+1].y());
|
||||
|
||||
int kkPos = (lY1+lY2)/2;
|
||||
int iPos = fabs(left_Low + right_Hight + 2*_SDep)/(2*_Rlev);
|
||||
if(kkPos>=_nSamples || kkPos<0 || iPos>=m_Record || iPos<0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
wavedataNew[kkPos][iPos] = wavedata[j][i];
|
||||
}
|
||||
//--------------
|
||||
kkPos = lY1;
|
||||
iPos = fabs(left_Low + _SDep)/_Rlev;
|
||||
if(kkPos>=_nSamples || kkPos<0 || iPos>=m_Record || iPos<0)
|
||||
{
|
||||
qDebug() << "kkPos=" << QString::number(kkPos) << ",iPos=" << QString::number(iPos) << "j=" << QString::number(j) << ",i=" << QString::number(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
wavedataNew[kkPos][iPos] = wavedata[j][i];
|
||||
|
||||
//qDebug() << "kkPos=" << QString::number(kkPos) << ",iPos=" << QString::number(iPos) << "j=" << QString::number(j) << ",i=" << QString::number(i) << ",wavedata[j][i]=" << QString::number(wavedata[j][i]);
|
||||
}
|
||||
|
||||
//--------
|
||||
kkPos = lY2;
|
||||
iPos = fabs(right_Hight + _SDep)/_Rlev;
|
||||
if(kkPos>=_nSamples || kkPos<0 || iPos>=m_Record || iPos<0)
|
||||
{
|
||||
qDebug() << "kkPos=" << QString::number(kkPos) << ",iPos=" << QString::number(iPos) << "j=" << QString::number(j) << ",i=" << QString::number(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
wavedataNew[kkPos][iPos] = wavedata[j][i];
|
||||
|
||||
//qDebug() << "kkPos=" << QString::number(kkPos) << ",iPos=" << QString::number(iPos) << "j=" << QString::number(j) << ",i=" << QString::number(i) << ",wavedata[j][i]=" << QString::number(wavedata[j][i]);
|
||||
}
|
||||
// //----
|
||||
// kkPos = pt[j].x()+0.5;
|
||||
// iPos = i+pt[j].y();
|
||||
// if(kkPos>=_nSamples || kkPos<0 || iPos>=m_Record || iPos<0)
|
||||
// {
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// wavedataNew[kkPos][iPos] = wavedata[j][i];
|
||||
// }
|
||||
// //----
|
||||
// kkPos = pt[j].x()-0.5;
|
||||
// iPos = i+pt[j].y();
|
||||
// if(kkPos>=_nSamples || kkPos<0 || iPos>=m_Record || iPos<0)
|
||||
// {
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// wavedataNew[kkPos][iPos] = wavedata[j][i];
|
||||
// }
|
||||
// //----
|
||||
// kkPos = pt[j].x();
|
||||
// iPos = i+pt[j].y()+0.5;
|
||||
// if(kkPos>=_nSamples || kkPos<0 || iPos>=m_Record || iPos<0)
|
||||
// {
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// wavedataNew[kkPos][iPos] = wavedata[j][i];
|
||||
// }
|
||||
// //----
|
||||
// kkPos = pt[j].x();
|
||||
// iPos = i+pt[j].y()-0.5;
|
||||
// if(kkPos>=_nSamples || kkPos<0 || iPos>=m_Record || iPos<0)
|
||||
// {
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// wavedataNew[kkPos][iPos] = wavedata[j][i];
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------
|
||||
// set up the QCPColorMap:
|
||||
QCPColorMap *colorMap = new QCPColorMap(widget->xAxis, widget->yAxis);
|
||||
int nx = m_Record;
|
||||
int ny = _nSamples;
|
||||
colorMap->data()->setSize(nx, ny); // 我们希望彩色地图有nx*ny的数据点
|
||||
//colorMap->data()->setRange(QCPRange(g_iY1, g_iY2), QCPRange(vmin, vmax)); // 并在键(x)和值(y)维上跨越坐标范围-4..4
|
||||
colorMap->data()->setRange(QCPRange(0-_EDep, 0-_SDep), QCPRange(vmin, vmax));
|
||||
// :现在,我们通过访问颜色贴图的QCPColorMapData实例来分配一些数据:
|
||||
//double x, y, z;
|
||||
for (int xIndex=0; xIndex<nx; ++xIndex)
|
||||
{
|
||||
for (int yIndex=0; yIndex<ny; ++yIndex)
|
||||
{
|
||||
if(wavedataNew[yIndex][xIndex]==-9999)
|
||||
{
|
||||
colorMap->data()->setCell(nx-xIndex-1, yIndex, vmin);
|
||||
continue;
|
||||
}
|
||||
//colorMap->data()->setCell(xIndex, yIndex, wavedata[yIndex][xIndex]);
|
||||
colorMap->data()->setCell(nx-xIndex-1, yIndex, wavedataNew[yIndex][xIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 添加色标:
|
||||
QCPColorScale *colorScale = new QCPColorScale(widget);
|
||||
|
|
@ -1154,9 +1497,10 @@ void FormDraw::initWave(QMyCustomPlot *widget, QString strSlfName, QString strWa
|
|||
QString strScaleType = "";
|
||||
//道-对象
|
||||
m_formTrack->Add(strSlfName, m_strWellName, m_strTrackName, strWaveName, strAliasName, strUnit, newlineColor, width, _nSamples, 0, strScaleType, "waveObject");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FormDraw::initWave2(QMyCustomPlot *widget, QString strSlfName, QString strWaveName)
|
||||
{
|
||||
CLogIO *logio=new CLogIO();
|
||||
|
|
@ -1594,6 +1938,7 @@ void FormDraw::initResult(QMyCustomPlot *widget, QString strSlfName, QString str
|
|||
|
||||
}
|
||||
|
||||
|
||||
bool FormDraw::LoadFromSLF_Result(QMyCustomPlot *widget, QString strSlfName, QString strLineName)
|
||||
{
|
||||
static bool isrun=false;
|
||||
|
|
@ -1911,6 +2256,434 @@ bool FormDraw::LoadFromSLF_Result(QMyCustomPlot *widget, QString strSlfName, QSt
|
|||
return true;
|
||||
}
|
||||
|
||||
//录井剖面
|
||||
void FormDraw::initGeoLith(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_GeoLith(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_GeoLith(QMyCustomPlot *widget, QString strSlfName, QString strLineName)
|
||||
{
|
||||
CMemRdWt *logio=new CMemRdWt();
|
||||
if(!logio->Open(strSlfName.toStdString().c_str(),CSlfIO::modeRead))
|
||||
{
|
||||
delete logio;
|
||||
return false;
|
||||
}
|
||||
int iIndex=logio->OpenTable(strLineName.toStdString().c_str());
|
||||
if(iIndex>-1) {
|
||||
int len=logio->GetTableRecordLength(iIndex);
|
||||
int sl=sizeof(GeoLith_DATA);
|
||||
if(sl>len) len=sl;
|
||||
GeoLith_DATA *m_Result;
|
||||
m_Result=(GeoLith_DATA *)new char[len+1];
|
||||
int count=logio->GetTableRecordCount(iIndex);
|
||||
for(int i=0;i<count;i++) {
|
||||
memset(m_Result,0,len);
|
||||
logio->ReadTable(iIndex,i+1,m_Result);
|
||||
//
|
||||
QMap<QString,QString> OilOrder;
|
||||
QMap<QString,QString> LithOrder;
|
||||
QMap<QString,QString> ColorOrder;
|
||||
QMap<QString,QString> ColorInds;
|
||||
//
|
||||
LithOrder=GetZoneOrder(QString("GeoLith"));
|
||||
OilOrder=GetZoneOrder(QString("CoreOil"));
|
||||
ColorOrder=GetZoneOrder(QString("CoreColor"));
|
||||
ColorInds=GetZoneOrder(QString("ColorInd"));
|
||||
|
||||
QString iconshotname="";
|
||||
QString IntLith = QString::number(m_Result->Lith);
|
||||
if(IntLith=="0") {
|
||||
iconshotname="";
|
||||
}
|
||||
else
|
||||
{
|
||||
iconshotname=LithOrder.key(IntLith);
|
||||
}
|
||||
|
||||
//
|
||||
QString Lith = "";
|
||||
if(iconshotname!="")
|
||||
Lith=::GetMudSymbolDir()+""+iconshotname+".svg";
|
||||
int len=2;
|
||||
int pos=Lith.indexOf(".//");
|
||||
if(pos<0) pos=Lith.indexOf("./");
|
||||
else len=3;
|
||||
QString svg;
|
||||
if(pos==0)
|
||||
{
|
||||
svg=QCoreApplication::applicationDirPath()+ QDir::separator();
|
||||
svg+=Lith.mid(len-1);
|
||||
}
|
||||
else svg=Lith;
|
||||
QDir ss;
|
||||
if(!ss.exists(svg))
|
||||
{
|
||||
QString path=svg.left(svg.lastIndexOf('.')+1);
|
||||
svg=path+"png";
|
||||
}
|
||||
Lith=svg;
|
||||
|
||||
//
|
||||
QString Oil = "";
|
||||
iconshotname=OilOrder.key(QString::number(m_Result->Oil));
|
||||
if(iconshotname!="")
|
||||
Oil=::GetGasSymbolDir()+""+iconshotname+".svg";
|
||||
len=2;
|
||||
pos=Oil.indexOf(".//");
|
||||
if(pos<0) pos=Oil.indexOf("./");
|
||||
else len=3;
|
||||
if(pos==0)
|
||||
{
|
||||
svg=QCoreApplication::applicationDirPath()+ QDir::separator();
|
||||
svg+=Oil.mid(len-1);
|
||||
}
|
||||
else svg=Oil;
|
||||
if(!ss.exists(svg))
|
||||
{
|
||||
QString path=svg.left(svg.lastIndexOf('.')+1);
|
||||
svg=path+"png";
|
||||
}
|
||||
Oil=svg;
|
||||
|
||||
//
|
||||
QString Color = "";
|
||||
int ind=ColorInds.value(QString::number(m_Result->Color)).toInt();
|
||||
if (ind>-1&&ind<ColorOrder.size())
|
||||
{
|
||||
Color=::GetColorSymbolDir()+""+ColorOrder.key(QString::number(ind))+".svg";
|
||||
}
|
||||
else {
|
||||
Color=::GetColorSymbolDir()+"空白.svg";
|
||||
}
|
||||
|
||||
//
|
||||
widget->addGeoLithToPlot(-m_Result->EDEP, -m_Result->SDEP, Lith, Oil, Color);
|
||||
}
|
||||
logio->CloseTable(iIndex);
|
||||
delete m_Result;
|
||||
}
|
||||
delete logio;
|
||||
return true;
|
||||
}
|
||||
|
||||
//井壁取心
|
||||
void FormDraw::initSwallCore(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_SwallCore(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_SwallCore(QMyCustomPlot *widget, QString strSlfName, QString strLineName)
|
||||
{
|
||||
WALLCORE_DATA m_Result;
|
||||
CMemRdWt *logio=new CMemRdWt();
|
||||
if(strSlfName==""||!logio->Open(strSlfName.toStdString().c_str(),CSlfIO::modeRead))
|
||||
{
|
||||
delete logio;
|
||||
// QMessageBox::information(NULL,"提示","SLF文件打开失败,请检查!!",QMessageBox::Yes);
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList liths;
|
||||
QStringList oils;
|
||||
QStringList colors;
|
||||
QStringList colorinds;
|
||||
|
||||
QString cs=GetConfPath();
|
||||
QString color;
|
||||
for(int j=0;j<4;j++)
|
||||
{
|
||||
if(j==0) color=cs+"corecolor.ini";
|
||||
else if(j==1) color=cs+"corelith.ini";
|
||||
else if(j==2) color=cs+"coreoil.ini";
|
||||
else color=cs+"colorind.ini";
|
||||
FILE *fp=fopen(color.toStdString().c_str(),"rt");
|
||||
QStringList ss;
|
||||
char buf[100];
|
||||
if(fp) {
|
||||
while(!feof(fp)) {
|
||||
fscanf(fp,"%s",buf);
|
||||
ss.append(buf);
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
if(j==0) colors=ss;
|
||||
else if(j==1) liths=ss;
|
||||
else if(j==2) oils=ss;
|
||||
else colorinds=ss;
|
||||
}
|
||||
|
||||
//
|
||||
int iIndex=logio->OpenTable(strLineName.toStdString().c_str());
|
||||
if(iIndex>-1) {
|
||||
int count=logio->GetTableRecordCount(iIndex);
|
||||
for(int i=0;i<count;i++) {
|
||||
memset(&m_Result,0,sizeof(WALLCORE_DATA));
|
||||
logio->ReadTable(iIndex,i+1,&m_Result);
|
||||
double top=m_Result.Depth;
|
||||
double bottom=m_Result.Depth;
|
||||
|
||||
QString LithologyImage="";
|
||||
QString OilGasImage="";
|
||||
QString ColorImage="";
|
||||
|
||||
//
|
||||
if(m_Result.CoreLith<1) {
|
||||
LithologyImage="";
|
||||
}
|
||||
else if (liths.size()>=m_Result.CoreLith)
|
||||
{
|
||||
LithologyImage=::GetSymbolDir()+"/取心岩性符号/"+liths[m_Result.CoreLith-1]+".svg";
|
||||
QDir ss(LithologyImage);
|
||||
if(!ss.exists()) {
|
||||
LithologyImage=::GetSymbolDir()+"/取心岩性符号/"+liths[m_Result.CoreLith-1]+".png";
|
||||
}
|
||||
}
|
||||
if (m_Result.CoreOil>0&&oils.size()>=m_Result.CoreOil)
|
||||
{
|
||||
OilGasImage=::GetGasSymbolDir()+""+oils[m_Result.CoreOil-1]+".svg";
|
||||
}
|
||||
else {
|
||||
OilGasImage="";
|
||||
}
|
||||
int ind=colorinds.indexOf(QString::number(m_Result.CoreColor));
|
||||
if (ind>-1&&ind<colors.size())
|
||||
{
|
||||
ColorImage=::GetColorSymbolDir()+""+colors[ind]+".svg";
|
||||
}
|
||||
else {
|
||||
ColorImage="";
|
||||
}
|
||||
float depth = m_Result.Depth;
|
||||
float width = 1;
|
||||
float Sideleft = m_Result.left;
|
||||
if(m_Result.width<=0)
|
||||
{
|
||||
width = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = m_Result.width;
|
||||
}
|
||||
if(Sideleft<0) Sideleft=0;
|
||||
if(width<=0) width=1;
|
||||
|
||||
//
|
||||
widget->addSwallCoreToPlot(-m_Result.Depth, LithologyImage, OilGasImage, ColorImage, Sideleft, width, ind);
|
||||
}
|
||||
logio->CloseTable(iIndex);
|
||||
}
|
||||
delete logio;
|
||||
return true;
|
||||
}
|
||||
|
||||
//固井结论
|
||||
void FormDraw::initGujing(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_Gujing(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_Gujing(QMyCustomPlot *widget, QString strSlfName, QString strLineName)
|
||||
{
|
||||
CMemRdWt *logio=new CMemRdWt();
|
||||
if(!logio->Open(strSlfName.toStdString().c_str(),CSlfIO::modeRead))
|
||||
{
|
||||
delete logio;
|
||||
// QMessageBox::information(NULL,"提示","SLF文件打开失败,请检查!!",QMessageBox::Yes);
|
||||
return false;
|
||||
}
|
||||
|
||||
QString configfile=GetConfPath()+GetOilFieldName()+"GujingOrder.ini";
|
||||
QStringList lines;
|
||||
QFile file( configfile );
|
||||
if ( file.open( QIODevice::ReadOnly ) ) {
|
||||
QTextStream stream( &file );
|
||||
stream.setCodec("UTF-8"); // 设置UTF-8编码
|
||||
QString line;
|
||||
int n = 1;
|
||||
while ( !stream.atEnd() ) {
|
||||
line = stream.readLine(); // 不包括“\n”的一行文本
|
||||
lines += line;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
QMap<QString,QString> zoneOrder;
|
||||
for(int i=0;i<lines.size();i++){
|
||||
zoneOrder.insert(lines[i],QString::number(i));
|
||||
}
|
||||
|
||||
int iIndex=logio->OpenTable(strLineName.toStdString().c_str());
|
||||
if(iIndex>-1) {
|
||||
int len=logio->GetTableRecordLength(iIndex);
|
||||
int sl=sizeof(GUJING_DATA);
|
||||
if(sl>len) len=sl;
|
||||
GUJING_DATA *m_Result;
|
||||
m_Result=(GUJING_DATA *)new char[len+1];
|
||||
int count=logio->GetTableRecordCount(iIndex);
|
||||
for(int i=0;i<count;i++) {
|
||||
memset(m_Result,0,len);
|
||||
logio->ReadTable(iIndex,i+1,m_Result);
|
||||
|
||||
int NO = m_Result->NO;
|
||||
float SDEP = m_Result->SDEP;
|
||||
float EDEP = m_Result->EDEP;
|
||||
int RESULT = m_Result->RESULT;
|
||||
QString result = "";
|
||||
|
||||
//
|
||||
QString iconshotname=zoneOrder.key(QString::number(m_Result->RESULT));
|
||||
if(iconshotname!="")
|
||||
result=::GetGujingSymbolDir()+iconshotname+".svg";
|
||||
int len=2;
|
||||
int pos=result.indexOf(".//");
|
||||
if(pos<0) pos=result.indexOf("./");
|
||||
else len=3;
|
||||
QString svg;
|
||||
if(pos==0)
|
||||
{
|
||||
svg=QCoreApplication::applicationDirPath()+ QDir::separator();
|
||||
svg+=result.mid(len-1);
|
||||
}
|
||||
else svg=result;
|
||||
QDir ss;
|
||||
if(!ss.exists(svg))
|
||||
{
|
||||
QString path=svg.left(svg.lastIndexOf('.')+1);
|
||||
svg=path+"png";
|
||||
}
|
||||
result=QDir::toNativeSeparators(svg);
|
||||
|
||||
//显示固井
|
||||
widget->addGujingToPlot(-EDEP, -SDEP, result);
|
||||
}
|
||||
logio->CloseTable(iIndex);
|
||||
delete m_Result;
|
||||
}
|
||||
delete logio;
|
||||
return true;
|
||||
}
|
||||
|
||||
void FormDraw::CalcDipWidth(int nColumn,float *flWidth,float factor,int x1,int x2,float flHoriRatio)
|
||||
{
|
||||
float scale ;
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ public:
|
|||
|
||||
//波列
|
||||
void initWave(QMyCustomPlot *widget, QString strSlfName, QString strWaveName);
|
||||
void initWave_3D(QMyCustomPlot *widget, QString strSlfName, QString strWaveName);
|
||||
void initWave2(QMyCustomPlot *widget, QString strSlfName, QString strWaveName);
|
||||
|
||||
//表格曲线
|
||||
|
|
@ -142,6 +143,19 @@ public:
|
|||
void initResult(QMyCustomPlot *widget, QString strSlfName, QString strLineName);
|
||||
bool LoadFromSLF_Result(QMyCustomPlot *widget, QString strSlfName, QString strLineName);
|
||||
|
||||
//录井剖面
|
||||
void initGeoLith(QMyCustomPlot *widget, QString strSlfName, QString strLineName);
|
||||
bool LoadFromSLF_GeoLith(QMyCustomPlot *widget, QString strSlfName, QString strLineName);
|
||||
|
||||
//井壁取心
|
||||
void initSwallCore(QMyCustomPlot *widget, QString strSlfName, QString strLineName);
|
||||
bool LoadFromSLF_SwallCore(QMyCustomPlot *widget, QString strSlfName, QString strLineName);
|
||||
|
||||
//固井结论
|
||||
void initGujing(QMyCustomPlot *widget, QString strSlfName, QString strLineName);
|
||||
bool LoadFromSLF_Gujing(QMyCustomPlot *widget, QString strSlfName, QString strLineName);
|
||||
|
||||
|
||||
signals:
|
||||
//void sig_AddLine(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName);
|
||||
|
||||
|
|
|
|||
|
|
@ -215,7 +215,9 @@ void FormInfo::paintEvent(QPaintEvent* event)
|
|||
painter.drawText(rect.left(), rect.top()+rect.height()/3, rect.width(), rect.height()/3, Qt::AlignCenter, m_strUnit);
|
||||
}
|
||||
|
||||
if(m_strType=="tableObject" && (m_strLineName=="WORDS_RELUST" || m_strLineName == "RESULT"))
|
||||
if(m_strType=="tableObject" && (m_strLineName=="WORDS_RELUST" || m_strLineName == "RESULT"
|
||||
|| m_strLineName == "GEO_LITH"|| m_strLineName == "SWALL_CORE"
|
||||
|| m_strLineName == "GUJING1_RESULT" || m_strLineName == "GUJING2_RESULT" || m_strLineName == "GUJING3_RESULT") )
|
||||
{
|
||||
//文字结论,不绘制左右范围
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,7 +193,9 @@ 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" || strLineName == "WORDS_RELUST" || strLineName == "RESULT")
|
||||
if(strLineName == "FRAC_HOLE.TABLE" || strLineName == "WORDS_RELUST" || strLineName == "RESULT"
|
||||
|| strLineName == "GEO_LITH" || strLineName == "SWALL_CORE"
|
||||
|| strLineName == "GUJING1_RESULT" || strLineName == "GUJING2_RESULT" || strLineName == "GUJING3_RESULT")
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,11 +30,17 @@ SOURCES += \
|
|||
../CallManage/CallManage.cpp \
|
||||
../common/geometryutils.cpp \
|
||||
ConsoleOutputWidget.cpp \
|
||||
GeoIndicatorGenerator.cpp \
|
||||
InDefTableDlg.cpp \
|
||||
InterfaceWidget.cpp \
|
||||
PropertyWidget.cpp \
|
||||
QCPSizeHandle.cpp \
|
||||
QCPSizeHandleManager.cpp \
|
||||
TransparentDraggableGeoLith.cpp \
|
||||
TransparentDraggableGujing.cpp \
|
||||
TransparentDraggableRect.cpp \
|
||||
TransparentDraggableResult.cpp \
|
||||
TransparentDraggableSwallCore.cpp \
|
||||
backgrounddelegate.cpp \
|
||||
customtabbar.cpp \
|
||||
customtabwidget.cpp \
|
||||
|
|
@ -65,13 +71,17 @@ HEADERS += \
|
|||
../common/geometryutils.h \
|
||||
ConsoleOutputWidget.h \
|
||||
DraggablePixmap.h \
|
||||
GeoIndicatorGenerator.h \
|
||||
InDefTableDlg.h \
|
||||
InterfaceWidget.h \
|
||||
PropertyWidget.h \
|
||||
QCPSizeHandle.h \
|
||||
QCPSizeHandleManager.h \
|
||||
TransparentDraggableGeoLith.h \
|
||||
TransparentDraggableGujing.h \
|
||||
TransparentDraggableRect.h \
|
||||
TransparentDraggableResult.h \
|
||||
TransparentDraggableSwallCore.h \
|
||||
backgrounddelegate.h \
|
||||
customtabbar.h \
|
||||
customtabwidget.h \
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ QString g_prjname="";
|
|||
|
||||
//是否隐藏刻度
|
||||
int g_iShow = 0;
|
||||
//是否支持波列3D
|
||||
int g_iSupport3D=0;
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
|
|
@ -223,7 +225,9 @@ void MainWindow::initToolBar()
|
|||
|
||||
connect(m_newprojectAc, &QAction::triggered, this, &MainWindow::s_New);
|
||||
connect(m_openprojectAc, &QAction::triggered, this, &MainWindow::s_Open);
|
||||
connect(m_wellsectionwindowAc, &QAction::triggered, this, &MainWindow::s_showView);//s_Risize
|
||||
connect(m_wellsectionwindowAc, &QAction::triggered, this, &MainWindow::s_showView);
|
||||
connect(m_developmentAc, &QAction::triggered, this, &MainWindow::s_development);
|
||||
|
||||
// connect(m_compileAc, &QAction::triggered, this, &MainWindow::s_AddOne);
|
||||
// connect(m_runAc, &QAction::triggered, this, &MainWindow::s_SaveImage);
|
||||
// connect(m_debugAc, &QAction::triggered, this, &MainWindow::s_DrawImg);
|
||||
|
|
@ -416,6 +420,19 @@ void MainWindow::s_showView()
|
|||
// searchThread->Open(fileFull);
|
||||
}
|
||||
|
||||
//开发工具
|
||||
void MainWindow::s_development()
|
||||
{
|
||||
//暂时用作切换3d绘制波列图的切换按钮
|
||||
if(g_iSupport3D==0)
|
||||
{
|
||||
g_iSupport3D=1;
|
||||
}
|
||||
else {
|
||||
g_iSupport3D=0;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::s_Risize()
|
||||
{
|
||||
emit CallManage::getInstance()->sig_Risize();
|
||||
|
|
|
|||
|
|
@ -86,6 +86,8 @@ public slots:
|
|||
|
||||
//可视解释
|
||||
void s_showView();
|
||||
//开发工具
|
||||
void s_development();
|
||||
|
||||
void s_ShowCurve(QString strSlfName, QString strName);//曲线数据查看
|
||||
void s_ShowTable(QString strSlfName, QString strName);//表格数据查看
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
#include "geometryutils.h"
|
||||
#include "TransparentDraggableRect.h"
|
||||
#include "TransparentDraggableResult.h"
|
||||
#include "TransparentDraggableGeoLith.h"
|
||||
#include "TransparentDraggableSwallCore.h"
|
||||
#include "TransparentDraggableGujing.h"
|
||||
#include "qtcommonclass.h"
|
||||
|
||||
//是否隐藏刻度
|
||||
|
|
@ -240,7 +243,7 @@ void QMyCustomPlot::addImageToPlot(double left_Low, double right_Hight, const QS
|
|||
// 设置初始范围
|
||||
dragRect->setRange(left_Low, right_Hight);
|
||||
// 可选:设置颜色
|
||||
dragRect->setColor(QColor(255, 100, 100, 80)); // 半透明红色
|
||||
dragRect->setColor(QColor(255, 255, 255, 80)); // 半透明红色
|
||||
//最小宽度
|
||||
dragRect->setMinWidth(0.1);
|
||||
|
||||
|
|
@ -257,7 +260,7 @@ void QMyCustomPlot::addTextToPlot(double left_Low, double right_Hight, const QSt
|
|||
// 设置初始范围
|
||||
dragRect->setRange(left_Low, right_Hight);
|
||||
// 可选:设置颜色
|
||||
dragRect->setColor(QColor(255, 100, 100, 80)); // 半透明红色
|
||||
dragRect->setColor(QColor(255, 255, 255, 80)); // 半透明红色
|
||||
//最小宽度
|
||||
dragRect->setMinWidth(0.1);
|
||||
dragRect->setTitle(strText);
|
||||
|
|
@ -280,18 +283,94 @@ void QMyCustomPlot::addResultToPlot(double left_Low, double right_Hight, QStrin
|
|||
|
||||
// 在初始化代码中
|
||||
TransparentDraggableResult *dragRect = new TransparentDraggableResult(this, upDragRect, strUuid);
|
||||
//图片,提前设值,后面setRange改变
|
||||
dragRect->setResult(myResult);
|
||||
// 设置初始范围
|
||||
dragRect->setRange(left_Low, right_Hight);
|
||||
// 可选:设置颜色
|
||||
dragRect->setColor(QColor(255, 100, 100, 80)); // 半透明红色
|
||||
dragRect->setColor(QColor(255, 255, 255, 80)); // 半透明红色
|
||||
//最小宽度
|
||||
dragRect->setMinWidth(0.1);
|
||||
dragRect->setResult(myResult);
|
||||
dragRect->setTitle(strText);
|
||||
|
||||
m_mapDraggable_Result[strUuid] = dragRect;
|
||||
}
|
||||
|
||||
void QMyCustomPlot::addSwallCoreToPlot(double Depth, QString LithologyImage, QString OilGasImage, QString ColorImage, double Sideleft, double width, int ind)
|
||||
{
|
||||
QtCommonClass *qtCommon = new QtCommonClass(this);
|
||||
QString strUuid = qtCommon->getUUid();
|
||||
|
||||
// 在初始化代码中
|
||||
TransparentDraggableSwallCore *dragRect = new TransparentDraggableSwallCore(this, strUuid);
|
||||
//图片,提前设值,后面setRange改变
|
||||
dragRect->setOil(OilGasImage);
|
||||
dragRect->setLith(LithologyImage);
|
||||
dragRect->setTitle(QString::number(ind));
|
||||
|
||||
// 设置初始范围
|
||||
double h = 40;
|
||||
double x1 = this->xAxis->coordToPixel(Depth);
|
||||
//
|
||||
double Depth2 = this->xAxis->pixelToCoord(x1-h);
|
||||
dragRect->setRange(Depth, Depth2);
|
||||
// 可选:设置颜色
|
||||
dragRect->setColor(QColor(255, 255, 255, 80)); // 半透明红色255, 100, 100, 80
|
||||
//最小宽度
|
||||
dragRect->setMinWidth(0.1);
|
||||
//dragRect->setColor(myColor);
|
||||
|
||||
m_mapDraggable_SwallCore[strUuid] = dragRect;
|
||||
|
||||
//刷新
|
||||
this->replot();
|
||||
}
|
||||
|
||||
void QMyCustomPlot::addGeoLithToPlot(double left_Low, double right_Hight, const QString myLith, const QString myOil, const QString myColor)
|
||||
{
|
||||
QtCommonClass *qtCommon = new QtCommonClass(this);
|
||||
QString strUuid = qtCommon->getUUid();
|
||||
|
||||
// 在初始化代码中
|
||||
TransparentDraggableGeoLith *dragRect = new TransparentDraggableGeoLith(this, strUuid);
|
||||
//图片,提前设值,后面setRange改变
|
||||
dragRect->setOil(myOil);
|
||||
dragRect->setLith(myLith, myColor);
|
||||
|
||||
// 设置初始范围
|
||||
dragRect->setRange(left_Low, right_Hight);
|
||||
// 可选:设置颜色
|
||||
dragRect->setColor(QColor(255, 255, 255, 80)); // 半透明红色255, 100, 100, 80
|
||||
//最小宽度
|
||||
dragRect->setMinWidth(0.1);
|
||||
//dragRect->setColor(myColor);
|
||||
|
||||
m_mapDraggable_GeoLith[strUuid] = dragRect;
|
||||
|
||||
//刷新
|
||||
this->replot();
|
||||
}
|
||||
|
||||
void QMyCustomPlot::addGujingToPlot(double left_Low, double right_Hight, const QString strResult)
|
||||
{
|
||||
QtCommonClass *qtCommon = new QtCommonClass(this);
|
||||
QString strUuid = qtCommon->getUUid();
|
||||
|
||||
// 在初始化代码中
|
||||
TransparentDraggableGujing *dragRect = new TransparentDraggableGujing(this, strUuid);
|
||||
//图片,提前设值,后面setRange改变
|
||||
dragRect->setResult(strResult);
|
||||
// 设置初始范围
|
||||
dragRect->setRange(left_Low, right_Hight);
|
||||
// 可选:设置颜色
|
||||
dragRect->setColor(QColor(255, 255, 255, 80)); // 半透明红色
|
||||
//最小宽度
|
||||
dragRect->setMinWidth(0.1);
|
||||
//dragRect->setTitle(strText);
|
||||
|
||||
m_mapDraggable_Gujing[strUuid] = dragRect;
|
||||
}
|
||||
|
||||
void QMyCustomPlot::onResetZoom()
|
||||
{
|
||||
|
||||
|
|
@ -1088,7 +1167,7 @@ void QMyCustomPlot::s_ChangeFillMode(QString strUuid, QString strSlfName, QStrin
|
|||
|
||||
|
||||
void QMyCustomPlot::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)
|
||||
double newLeftScale, double newRightScale, QString strScaleType, QColor &newlineColor, double width, Qt::PenStyle lineStyle)
|
||||
{
|
||||
//AppendConsole(PAI_INFO, "FormDraw addRandomGraph");
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,9 @@ public:
|
|||
|
||||
QMap<QString, QObject*> m_mapDraggableRect;
|
||||
QMap<QString, QObject*> m_mapDraggable_Result;
|
||||
QMap<QString, QObject*> m_mapDraggable_GeoLith;
|
||||
QMap<QString, QObject*> m_mapDraggable_SwallCore;
|
||||
QMap<QString, QObject*> m_mapDraggable_Gujing;
|
||||
|
||||
public slots:
|
||||
void slot_time();
|
||||
|
|
@ -69,12 +72,18 @@ public:
|
|||
void init(QString strName, QVector<double> x, QVector<double> y);
|
||||
void addImageToPlot(double left_Low, double right_Hight, const QString imagePath);
|
||||
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);
|
||||
double newLeftScale, double newRightScale, QString strScaleType, QColor &newlineColor, double width, Qt::PenStyle lineStyle);
|
||||
|
||||
void addTextToPlot(double left_Low, double right_Hight, const QString strText);
|
||||
|
||||
void addResultToPlot(double left_Low, double right_Hight, QString myResult, QString &strUuid, QString strText="");
|
||||
|
||||
void addGeoLithToPlot(double left_Low, double right_Hight, const QString myLith, const QString myOil, const QString myColor);
|
||||
|
||||
void addSwallCoreToPlot(double Depth, QString LithologyImage, QString OilGasImage, QString ColorImage, double Sideleft, double width, int ind);
|
||||
|
||||
void addGujingToPlot(double left_Low, double right_Hight, const QString strResult);
|
||||
|
||||
public slots:
|
||||
void s_LineClicked(int index);
|
||||
void onResetZoom();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user