996 lines
25 KiB
C++
996 lines
25 KiB
C++
#include "TransparentGroupResult.h"
|
||
#include "TransparentDraggableResult.h"
|
||
#include "PropertyWidget.h"
|
||
|
||
extern double g_dPixelPerCm;//每厘米像素数
|
||
|
||
TransparentGroupResult::TransparentGroupResult(QMyCustomPlot *parentPlot, TransparentGroupResult *upDraggableResult, QString strUuid, double minWidth, QString strTitle)
|
||
: QObject(parentPlot), mPlot(parentPlot), mstrTitle(strTitle), mMinWidth(minWidth)
|
||
{
|
||
m_strUuid = strUuid;
|
||
//
|
||
initRect();
|
||
|
||
}
|
||
|
||
TransparentGroupResult::~TransparentGroupResult()
|
||
{
|
||
if(mPlot) {
|
||
// mPlot->removeItem(mRect);
|
||
// mPlot->removeItem(mLeftHandle);
|
||
// mPlot->removeItem(mRightHandle);
|
||
}
|
||
}
|
||
|
||
void TransparentGroupResult::addResultToPlot(double left_Low, double right_Hight, QString myResult, QString &strUuid, int ninsertIdx)
|
||
{
|
||
//获取上方Rect
|
||
TransparentDraggableResult *upDragRect = nullptr;
|
||
if (strUuid != "")
|
||
{
|
||
upDragRect = (TransparentDraggableResult *)m_mapDraggable_Result[strUuid];
|
||
}
|
||
|
||
strUuid = getUUid();
|
||
|
||
// 在初始化代码中
|
||
TransparentDraggableResult *dragRect = new TransparentDraggableResult(mPlot, upDragRect, strUuid);
|
||
dragRect->setShowProperty(m_nConclusionProportion, m_nShowPos);
|
||
//图片,提前设值,后面setRange改变
|
||
dragRect->setResult(myResult);
|
||
// 设置初始范围
|
||
dragRect->setRange(left_Low, right_Hight);
|
||
// 可选:设置颜色
|
||
//dragRect->setColor(QColor(255, 0, 0, 80)); // 半透明红色
|
||
//最小宽度
|
||
dragRect->setMinWidth(0.1);
|
||
//dragRect->setTitle(strText);
|
||
|
||
if (ninsertIdx < 0)
|
||
m_vecResult << strUuid;
|
||
else
|
||
{
|
||
// 插入设置上下Result
|
||
int newIdx = ninsertIdx + 1;
|
||
if (newIdx < m_vecResult.size())
|
||
{
|
||
TransparentDraggableResult* pret = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(m_vecResult.at(newIdx)));
|
||
if (pret)
|
||
{
|
||
pret->setUpResult(dragRect);
|
||
}
|
||
}
|
||
m_vecResult.insert(newIdx, strUuid);
|
||
}
|
||
m_mapDraggable_Result[strUuid] = dragRect;
|
||
}
|
||
|
||
QString TransparentGroupResult::getIconName(const QMap<QString, QString>& zoneOrder, const QString& result_str, int nidx, double dMDepth)
|
||
{
|
||
QString result = "";
|
||
QString iconshotname = "";
|
||
if (result_str.length() == 1)
|
||
{
|
||
if (nidx > 0)
|
||
return result;
|
||
|
||
if (result_str.length() > 0 && dMDepth)
|
||
iconshotname = zoneOrder.key(result_str.at(0));
|
||
else
|
||
iconshotname = zoneOrder.key(result_str);
|
||
}
|
||
else
|
||
{
|
||
if (dMDepth != 0) {
|
||
if (result_str.length() > nidx)
|
||
iconshotname = zoneOrder.key(result_str.at(nidx));
|
||
|
||
}
|
||
}
|
||
|
||
if (iconshotname != "") {
|
||
result = ::GetOilSymbolDir() + iconshotname + ".svg";
|
||
QDir fexit;
|
||
if (!fexit.exists(result))
|
||
result = ::GetOilSymbolDir() + iconshotname + ".png";
|
||
}
|
||
return result;
|
||
}
|
||
|
||
void TransparentGroupResult::addAllResultToPlot(LAYER_DATA* pResult)
|
||
{
|
||
QMap<QString, QString> zoneOrder = GetZoneOrder();//初始化ZoneOrder 层序号根据层位名来,配置文件在conf\\RESULT.txt
|
||
|
||
m_Remark = GBKToUTF8(pResult->Description10);
|
||
m_nResult = pResult->Result;
|
||
//
|
||
QDir fexit;
|
||
QString result_str = QString::number(pResult->Result);
|
||
|
||
QVector<float> vecDepth;
|
||
vecDepth << pResult->MDepth1 << pResult->MDepth1;
|
||
vecDepth << pResult->MDepth2 << pResult->MDepth3 << pResult->MDepth4 << pResult->MDepth5;
|
||
vecDepth << pResult->MDepth6 << pResult->MDepth7 << pResult->MDepth8 << pResult->MDepth9 << pResult->MDepth10;
|
||
|
||
QString strUuid = "";
|
||
for (int i = 0; i < vecDepth.size()-1; i++)
|
||
{
|
||
QString result = getIconName(zoneOrder, result_str, i, vecDepth.at(i));
|
||
|
||
if (result != "")
|
||
{
|
||
double dEnd = vecDepth.at(i + 1);
|
||
double dStart = vecDepth.at(i);
|
||
if (i == 0)
|
||
{
|
||
dStart= pResult->StartDepth;
|
||
}
|
||
if (dEnd != 0)
|
||
{
|
||
//第一个加Zone解释层号
|
||
this->addResultToPlot(-dEnd, -dStart, result, strUuid);
|
||
}
|
||
else
|
||
{
|
||
this->addResultToPlot(-pResult->EndDepth, -dStart, result, strUuid);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
void TransparentGroupResult::removeAllResult()
|
||
{
|
||
mPlot->m_mapDragGroup.remove(m_strUuid);
|
||
for (int i = 0; i < m_vecResult.size(); i++)
|
||
{
|
||
TransparentDraggableResult* pret = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(m_vecResult.at(i)));
|
||
if (pret == NULL)
|
||
continue;
|
||
pret->deleteRect(false);
|
||
}
|
||
m_vecResult.clear();
|
||
m_mapDraggable_Result.clear();
|
||
this->deleteRect();
|
||
}
|
||
|
||
//设置最小宽度
|
||
void TransparentGroupResult::setMinWidth(double minWidth)
|
||
{
|
||
mMinWidth = minWidth;
|
||
}
|
||
|
||
//设置标题
|
||
void TransparentGroupResult::setTitle(QString strTitle)
|
||
{
|
||
mstrTitle = strTitle;
|
||
mItemTitle->setText(mstrTitle);
|
||
//mPlot->replot();
|
||
}
|
||
|
||
QString TransparentGroupResult::getTitle()
|
||
{
|
||
return mstrTitle;
|
||
}
|
||
|
||
void TransparentGroupResult::setRemark(QString remark)
|
||
{
|
||
m_Remark = remark;
|
||
}
|
||
|
||
QString TransparentGroupResult::getRemark()
|
||
{
|
||
return m_Remark;
|
||
}
|
||
|
||
int TransparentGroupResult::getNResult()
|
||
{
|
||
return m_nResult;
|
||
}
|
||
|
||
//设置解释结论
|
||
void TransparentGroupResult::setResult(QString filePath)
|
||
{
|
||
m_Result = filePath;
|
||
}
|
||
|
||
// 设置矩形范围
|
||
void TransparentGroupResult::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)/2;
|
||
mRect->topLeft->setCoords(left_Low, lY1);
|
||
mRect->bottomRight->setCoords(right_Hight, mPlot->yAxis->range().upper);
|
||
|
||
mItemTitle->position->setCoords((mRect->topLeft->coords().x() + mRect->bottomRight->coords().x())/2,
|
||
lY2 + lY2/2);
|
||
|
||
updateHandles();
|
||
}
|
||
|
||
void TransparentGroupResult::setDragRange(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) / 2;
|
||
mDragRect->topLeft->setCoords(left_Low, lY1);
|
||
mDragRect->bottomRight->setCoords(right_Hight, mPlot->yAxis->range().upper);
|
||
}
|
||
|
||
// 获取当前范围
|
||
QCPRange TransparentGroupResult::getRange()
|
||
{
|
||
return QCPRange(mRect->topLeft->coords().x(), mRect->bottomRight->coords().x());
|
||
}
|
||
|
||
void TransparentGroupResult::setGroupConclusionProportion(int nCopr)
|
||
{
|
||
if (nCopr > 0)
|
||
{
|
||
m_nConclusionProportion = nCopr;
|
||
}
|
||
|
||
QObjectList objList = m_mapDraggable_Result.values();
|
||
for (int i = 0; i < objList.size(); i++)
|
||
{
|
||
TransparentDraggableResult* p = qobject_cast<TransparentDraggableResult*>(objList.at(i));
|
||
if (p)
|
||
{
|
||
p->setShowProperty(m_nConclusionProportion, m_nShowPos, true);
|
||
}
|
||
}
|
||
}
|
||
|
||
void TransparentGroupResult::setGroupShowPos(int nSPos)
|
||
{
|
||
if (nSPos > 0)
|
||
{
|
||
m_nShowPos = nSPos;
|
||
}
|
||
|
||
QObjectList objList = m_mapDraggable_Result.values();
|
||
for (int i = 0; i < objList.size(); i++)
|
||
{
|
||
TransparentDraggableResult* p = qobject_cast<TransparentDraggableResult*>(objList.at(i));
|
||
if (p)
|
||
{
|
||
p->setShowProperty(m_nConclusionProportion, m_nShowPos, true);
|
||
}
|
||
}
|
||
}
|
||
|
||
void TransparentGroupResult::setFloorVisible(bool bs)
|
||
{
|
||
mItemTitle->setRotation(90);
|
||
mItemTitle->setVisible(bs);
|
||
mPlot->replot();
|
||
}
|
||
|
||
void TransparentGroupResult::setFloorFont(QFont f)
|
||
{
|
||
mItemTitle->setFont(f);
|
||
mPlot->replot();
|
||
}
|
||
|
||
void TransparentGroupResult::setFloorRot(double dr)
|
||
{
|
||
mItemTitle->setRotation(dr);
|
||
mPlot->replot();
|
||
}
|
||
|
||
void TransparentGroupResult::setDragRect(int dMode, double dragVal)
|
||
{
|
||
QCPRange mDragStartRange = getRange();
|
||
QCPRange newRange = mDragStartRange;
|
||
|
||
switch (dMode) {
|
||
case DragLeft: {
|
||
//double proposedLeft = mDragStartRange.lower + dx;
|
||
double proposedLeft = dragVal;
|
||
// 确保不超出轴范围且不使宽度小于最小值
|
||
newRange.lower = qBound(
|
||
//mPlot->xAxis->range().lower,
|
||
getMyLower(),
|
||
proposedLeft,
|
||
mDragStartRange.upper - mMinWidth);
|
||
break;
|
||
}
|
||
case DragRight: {
|
||
//double proposedRight = mDragStartRange.upper + dx;
|
||
double proposedRight = dragVal;
|
||
// 确保不超出轴范围且不使宽度小于最小值
|
||
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() + dragVal;
|
||
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;
|
||
}
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
// 最终确保宽度不小于最小值(针对整体拖动的情况)
|
||
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);
|
||
|
||
if (m_vecResult.size() == 1)
|
||
{
|
||
TransparentDraggableResult* pret = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(m_vecResult.at(0)));
|
||
if (pret)
|
||
{
|
||
pret->setRange(newRange.lower, newRange.upper);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (mDragMode == DragRect)
|
||
{
|
||
float offset = mDragStartRange.lower - getRange().lower;
|
||
for (int i = 0; i < m_vecResult.size(); i++)
|
||
{
|
||
TransparentDraggableResult* pret = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(m_vecResult.at(i)));
|
||
if (pret == NULL)
|
||
continue;
|
||
QCPRange rg = pret->getRange();
|
||
pret->setRange(rg.lower - offset, rg.upper - offset);
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
TransparentDraggableResult* pret = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(m_vecResult.at(0)));
|
||
if (pret)
|
||
{
|
||
pret->setRange(pret->getRange().lower, newRange.upper);
|
||
}
|
||
pret = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(m_vecResult.last()));
|
||
if (pret)
|
||
{
|
||
pret->setRange(newRange.lower, pret->getRange().upper);
|
||
}
|
||
}
|
||
}
|
||
mPlot->replot();
|
||
}
|
||
|
||
void TransparentGroupResult::setDragResult(int nidx, QString strResult)
|
||
{
|
||
if (nidx < 0 || nidx >= m_vecResult.size())
|
||
return;
|
||
|
||
const QString& uid = m_vecResult.at(nidx);
|
||
TransparentDraggableResult* pDrag = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(uid));
|
||
if (pDrag == NULL)
|
||
return;
|
||
pDrag->setResult(strResult);
|
||
pDrag->setShowProperty(m_nConclusionProportion, m_nShowPos, true);
|
||
}
|
||
|
||
void TransparentGroupResult::setDragDepth(int nidx, double dDepth)
|
||
{
|
||
if (nidx < 0 || nidx >= m_vecResult.size())
|
||
return;
|
||
|
||
const QString& uid = m_vecResult.at(nidx);
|
||
TransparentDraggableResult* pDrag = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(uid));
|
||
if (pDrag == NULL)
|
||
return;
|
||
QCPRange rg = pDrag->getRange();
|
||
pDrag->setRange(rg.lower, -dDepth, true);
|
||
|
||
// 上方TransparentDraggableResult,Rect更新
|
||
TransparentDraggableResult* upDrag = pDrag->getUpResult();
|
||
if (upDrag)
|
||
{
|
||
QCPRange rg = upDrag->getRange();
|
||
upDrag->setRange(-dDepth, rg.upper, true);
|
||
}
|
||
}
|
||
|
||
// 删除框图
|
||
void TransparentGroupResult::deleteRect()
|
||
{
|
||
if(mPlot) {
|
||
|
||
mPlot->m_mapDraggable_Result.remove(m_strUuid);
|
||
|
||
mPlot->removeItem(mRect);
|
||
mPlot->removeItem(mLeftHandle);
|
||
mPlot->removeItem(mRightHandle);
|
||
mPlot->removeItem(mItemTitle);
|
||
mPlot->removeItem(mDragLine);
|
||
|
||
mPlot->replot();
|
||
this->deleteLater();
|
||
|
||
}
|
||
}
|
||
|
||
|
||
void TransparentGroupResult::setSelectRect(bool bselect)
|
||
{
|
||
m_bSelect = bselect;
|
||
if (bselect)
|
||
{
|
||
mRect->setBrush(QColor(255, 0, 0, 80));
|
||
mRect->setPen(QPen(Qt::black, 1, Qt::DashLine));
|
||
}
|
||
else
|
||
{
|
||
mRect->setBrush(Qt::NoBrush);
|
||
mRect->setPen(Qt::NoPen);
|
||
}
|
||
mPlot->replot();
|
||
}
|
||
|
||
bool TransparentGroupResult::getSelect()
|
||
{
|
||
return m_bSelect;
|
||
}
|
||
|
||
int TransparentGroupResult::getDraggableResultIndex(double depth)
|
||
{
|
||
int nidx = -1;
|
||
// 根据depth获取当前深度的DraggableResult索引
|
||
// upper---- 上
|
||
// lower---- 下
|
||
TransparentDraggableResult* pDret = NULL;
|
||
for (int i = 0; i < m_vecResult.size(); i++)
|
||
{
|
||
TransparentDraggableResult* pret = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(m_vecResult.at(i)));
|
||
if (pret == NULL)
|
||
continue;
|
||
QCPRange rg = pret->getRange();
|
||
if (depth <= rg.upper && depth >= rg.lower)
|
||
{
|
||
nidx = i;
|
||
pDret = pret;
|
||
break;
|
||
}
|
||
}
|
||
return nidx;
|
||
}
|
||
|
||
void TransparentGroupResult::segmentationInnerLayer(double depth)
|
||
{
|
||
// 根据depth获取当前深度的DraggableResult索引
|
||
// upper---- 上
|
||
// lower---- 下
|
||
int nidx = this->getDraggableResultIndex(depth);
|
||
if (nidx < 0)
|
||
return;
|
||
TransparentDraggableResult* pDret = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(m_vecResult.at(nidx)));
|
||
if (pDret == NULL)
|
||
return;
|
||
|
||
QCPRange rg = pDret->getRange();
|
||
// 分割层内层修改下边界坐标
|
||
pDret->setRange(depth, rg.upper);
|
||
QString strUuid = pDret->getUuid();
|
||
// 新增层
|
||
this->addResultToPlot(rg.lower, depth, ::GetOilSymbolDir() + "油层.svg", strUuid, nidx);
|
||
mPlot->replot();
|
||
}
|
||
|
||
void TransparentGroupResult::segmentationIndependentLayer(double depth)
|
||
{
|
||
int nidx = -1;
|
||
// 根据depth获取当前深度的DraggableResult索引
|
||
// upper---- 上
|
||
// lower---- 下
|
||
TransparentDraggableResult* pDret = NULL;
|
||
for (int i = 0; i < m_vecResult.size(); i++)
|
||
{
|
||
TransparentDraggableResult* pret = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(m_vecResult.at(i)));
|
||
if (pret == NULL)
|
||
continue;
|
||
QCPRange rg = pret->getRange();
|
||
if (depth <= rg.upper && depth >= rg.lower)
|
||
{
|
||
nidx = i;
|
||
pDret = pret;
|
||
break;
|
||
}
|
||
}
|
||
if (nidx < 0 || pDret == NULL)
|
||
return;
|
||
}
|
||
|
||
void TransparentGroupResult::splitIndependentLayer()
|
||
{
|
||
for (int i = 0; i < m_vecResult.size(); i++)
|
||
{
|
||
TransparentDraggableResult* pret = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(m_vecResult.at(i)));
|
||
if (pret == NULL)
|
||
continue;
|
||
QCPRange rg = pret->getRange();
|
||
QString strUuid = "";
|
||
TransparentGroupResult* pNew = mPlot->addResultGroup(rg.lower, rg.upper, strUuid);
|
||
pNew->addResultToPlot(rg.lower, rg.upper, pret->getResult(), strUuid);
|
||
}
|
||
}
|
||
|
||
int TransparentGroupResult::getCursor()
|
||
{
|
||
if (m_bMoveRect)
|
||
{
|
||
return 2;
|
||
}
|
||
if (m_bArrow)
|
||
{
|
||
return 1;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
QString TransparentGroupResult::getOilGasConclusion(int nidx)
|
||
{
|
||
QString ret = "";
|
||
if (nidx >= m_vecResult.size())
|
||
return ret;
|
||
|
||
const QString& uid = m_vecResult.at(nidx);
|
||
|
||
TransparentDraggableResult* pDrag = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(uid));
|
||
if (pDrag == NULL)
|
||
return ret;
|
||
|
||
QFileInfo fileInfo(pDrag->getResult());
|
||
return fileInfo.baseName();
|
||
}
|
||
|
||
QString TransparentGroupResult::getOilGasDepth(int nidx)
|
||
{
|
||
QString ret = "";
|
||
if (nidx >= m_vecResult.size())
|
||
return ret;
|
||
|
||
const QString& uid = m_vecResult.at(nidx);
|
||
|
||
TransparentDraggableResult* pDrag = qobject_cast<TransparentDraggableResult*>(m_mapDraggable_Result.value(uid));
|
||
if (pDrag == NULL)
|
||
return ret;
|
||
|
||
return QString("%1").arg(-pDrag->getRange().upper);
|
||
}
|
||
|
||
const QVector<QString>& TransparentGroupResult::getVecResult()
|
||
{
|
||
return m_vecResult;
|
||
}
|
||
|
||
const QMap<QString, QObject*>& TransparentGroupResult::getMapDraggable_Result()
|
||
{
|
||
return m_mapDraggable_Result;
|
||
}
|
||
|
||
void TransparentGroupResult::initRect()
|
||
{
|
||
// 创建透明矩形
|
||
mDragRect = new QCPItemRect(mPlot);
|
||
mDragRect->setLayer("overlay"); // 确保在最上层
|
||
mDragRect->setBrush(Qt::NoBrush);
|
||
mDragRect->setPen(QPen(Qt::red, 1, Qt::DashDotDotLine));
|
||
mDragRect->setVisible(false);
|
||
|
||
mDragLine = new QCPItemStraightLine(mPlot);
|
||
mDragLine->setPen(QPen(Qt::red, 1));
|
||
mDragLine->setVisible(false);
|
||
|
||
// 创建透明矩形
|
||
mRect = new QCPItemRect(mPlot);
|
||
mRect->setLayer("overlay"); // 确保在最上层
|
||
mRect->setBrush(Qt::NoBrush);
|
||
mRect->setPen(Qt::NoPen);
|
||
|
||
// 创建左右边界控制点
|
||
mLeftHandle = new QCPItemRect(mPlot);
|
||
mLeftHandle->setLayer("overlay");
|
||
mLeftHandle->setBrush(Qt::NoBrush);
|
||
mLeftHandle->setPen(Qt::NoPen);
|
||
|
||
mRightHandle = new QCPItemRect(mPlot);
|
||
mRightHandle->setLayer("overlay");
|
||
mRightHandle->setBrush(Qt::NoBrush);
|
||
mRightHandle->setPen(Qt::NoPen);
|
||
|
||
// 连接鼠标事件
|
||
connect(mPlot, &QCustomPlot::mousePress, this, &TransparentGroupResult::onMousePress);
|
||
connect(mPlot, &QCustomPlot::mouseMove, this, &TransparentGroupResult::onMouseMove);
|
||
connect(mPlot, &QCustomPlot::mouseRelease, this, &TransparentGroupResult::onMouseRelease);
|
||
|
||
// mPixmap = new QCPItemPixmap(mPlot);
|
||
// //mPixmap->setPixmap(QPixmap(":/image/file.png")); // 设置图片
|
||
// mPixmap->setScaled(true, Qt::IgnoreAspectRatio); // 设置缩放方式
|
||
// mPixmap->setLayer("overlay"); // 确保在最上层
|
||
// QPen pen = QPen(Qt::black);
|
||
// pen.setWidth(1);
|
||
// mPixmap->setPen(pen);
|
||
|
||
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 TransparentGroupResult::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); // 矩形大小
|
||
}
|
||
|
||
TransparentDraggableResult* TransparentGroupResult::getSelectItemResult(QPoint pt)
|
||
{
|
||
TransparentDraggableResult* pret = NULL;
|
||
QObjectList objList = m_mapDraggable_Result.values();
|
||
for (int i = 0; i < objList.size(); i++)
|
||
{
|
||
TransparentDraggableResult* p = qobject_cast<TransparentDraggableResult*>(objList.at(i));
|
||
if (p && p->getLeftHandle())
|
||
{
|
||
if (p->getLeftHandle()->selectTest(pt, false) < 5) {
|
||
pret = p;
|
||
break;
|
||
}
|
||
|
||
}
|
||
}
|
||
return pret;
|
||
}
|
||
|
||
void TransparentGroupResult::onDelRect()
|
||
{
|
||
//mDragMode = DragNone;
|
||
//删除框图
|
||
deleteRect();
|
||
}
|
||
|
||
void TransparentGroupResult::onMousePress(QMouseEvent *event)
|
||
{
|
||
event->accept();
|
||
if (!mPlot->getIsEditor())
|
||
return;
|
||
|
||
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 = DragLeft;
|
||
}
|
||
else if (mRightHandle->selectTest(event->pos(), false) < 5) {
|
||
mDragMode = DragRight;
|
||
}
|
||
else
|
||
{
|
||
TransparentDraggableResult* p = this->getSelectItemResult(event->pos());
|
||
if (p)
|
||
{
|
||
m_pDragResult = p;
|
||
mDragMode = DragItem;
|
||
currentRange = p->getRange();
|
||
}
|
||
else if (y >= currentRange.lower && y <= currentRange.upper)
|
||
{
|
||
mDragMode = DragRect;
|
||
}
|
||
else
|
||
{
|
||
mDragMode = DragNone;
|
||
|
||
if (event->modifiers() & Qt::ControlModifier) {
|
||
//qDebug() << "鼠标点击时按住了Ctrl键";
|
||
}
|
||
else
|
||
setSelectRect(false);
|
||
return;
|
||
}
|
||
}
|
||
setSelectRect(true);
|
||
|
||
//mDragStartX = x;
|
||
mDragStartY = y;
|
||
mDragStartRange = currentRange;
|
||
}
|
||
}
|
||
|
||
void TransparentGroupResult::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 = proposedLeft;
|
||
break;
|
||
}
|
||
case DragRight: {
|
||
//double proposedRight = mDragStartRange.upper + dx;
|
||
double proposedRight = mDragStartRange.upper + dy;
|
||
// 确保不超出轴范围且不使宽度小于最小值
|
||
newRange.upper = proposedRight;
|
||
break;
|
||
}
|
||
case DragItem: {
|
||
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;
|
||
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
// 最终确保宽度不小于最小值(针对整体拖动的情况)
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (abs(dy) > 0.2)
|
||
{
|
||
if (mDragMode == DragItem)
|
||
{
|
||
mDragLine->setVisible(true);
|
||
mDragLine->point1->setCoords(mDragStartRange.upper+dy, 0);
|
||
mDragLine->point2->setCoords(mDragStartRange.upper+dy, 1);
|
||
}
|
||
else
|
||
{
|
||
mDragRect->setVisible(true);
|
||
setDragRange(newRange.lower, newRange.upper);
|
||
}
|
||
}
|
||
//setRange(newRange.lower, newRange.upper);
|
||
}
|
||
|
||
void TransparentGroupResult::onMouseMove(QMouseEvent *event)
|
||
{
|
||
if (!mPlot->getIsEditor())
|
||
return;
|
||
if (mDragMode == DragRect)
|
||
{
|
||
m_bMoveRect = true;
|
||
}
|
||
else if (mLeftHandle->selectTest(event->pos(), false) < 5
|
||
|| mRightHandle->selectTest(event->pos(), false) < 5
|
||
|| this->getSelectItemResult(event->pos())
|
||
|| (mDragMode > DragNone && mDragMode <= DragItem))
|
||
{
|
||
m_bArrow = true;
|
||
m_bMoveRect = false;
|
||
}
|
||
else
|
||
{
|
||
m_bArrow = false;
|
||
m_bMoveRect = false;
|
||
}
|
||
|
||
if(mDragMode == DragNone) return;
|
||
|
||
event->accept();
|
||
|
||
onMouseMove_in(event);
|
||
|
||
//后面统一刷新上方和下方rect
|
||
mPlot->replot();
|
||
}
|
||
|
||
void TransparentGroupResult::onMouseRelease_in(QMouseEvent *event)
|
||
{
|
||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||
event->accept();
|
||
//避免二次绘制框图
|
||
mPlot->m_bDrawRect = false;
|
||
//emit rangeChanged(getRange());
|
||
mDragMode = DragNone;
|
||
}
|
||
}
|
||
|
||
void TransparentGroupResult::onMouseRelease(QMouseEvent *event)
|
||
{
|
||
if (!mPlot->getIsEditor())
|
||
return;
|
||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||
{
|
||
double low = mRect->topLeft->coords().x();
|
||
double hight = mRect->bottomRight->coords().x();
|
||
PropertyService()->initJieshiItemProperty(this, low, hight, m_Result);
|
||
}
|
||
if (mDragRect->visible())
|
||
{
|
||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());
|
||
double dy = y - mDragStartY;
|
||
|
||
QCPRange newRange = mDragStartRange;
|
||
|
||
double dval = dy;
|
||
switch (mDragMode) {
|
||
case DragLeft: {
|
||
dval = mDragStartRange.lower + dy;
|
||
break;
|
||
}
|
||
case DragRight: {
|
||
dval = mDragStartRange.upper + dy;
|
||
break;
|
||
}
|
||
case DragRect: {
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
this->setDragRect(mDragMode, dval);
|
||
|
||
mDragRect->setVisible(false);
|
||
mDragLine->setVisible(false);
|
||
}
|
||
else if (mDragLine->visible())
|
||
{
|
||
if (mDragMode == DragItem)
|
||
{
|
||
if (m_pDragResult)
|
||
{
|
||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());
|
||
double dy = y - mDragStartY;
|
||
|
||
QCPRange rg = m_pDragResult->getRange();
|
||
m_pDragResult->setRange(rg.lower, rg.upper + dy);
|
||
|
||
TransparentDraggableResult* upr = m_pDragResult->getUpResult();
|
||
if (upr)
|
||
{
|
||
QCPRange rg = upr->getRange();
|
||
upr->setRange(rg.lower + dy, rg.upper);
|
||
}
|
||
m_pDragResult = NULL;
|
||
}
|
||
mDragLine->setVisible(false);
|
||
}
|
||
}
|
||
mPlot->replot();
|
||
mPlot->SaveToSLF_Result();
|
||
}
|
||
|
||
onMouseRelease_in(event);
|
||
}
|
||
|
||
double TransparentGroupResult::getMyLower()
|
||
{
|
||
double dLower = mPlot->xAxis->range().lower;
|
||
double proposedLeft = mDragStartRange.lower;
|
||
|
||
TransparentGroupResult *pDraggableRect =NULL;
|
||
{
|
||
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDragGroup.begin();
|
||
while( it != mPlot->m_mapDragGroup.end() )
|
||
{
|
||
if(it.key() == m_strUuid)
|
||
{
|
||
it++;
|
||
continue;
|
||
}
|
||
pDraggableRect = (TransparentGroupResult*)it.value();
|
||
//
|
||
QCPRange tmpRange = pDraggableRect->getRange();
|
||
if(tmpRange.upper >= dLower && tmpRange.upper <= proposedLeft)
|
||
{
|
||
dLower = tmpRange.upper;
|
||
}
|
||
it++;
|
||
}
|
||
}
|
||
|
||
return dLower;
|
||
}
|
||
|
||
double TransparentGroupResult::getMyUpper()
|
||
{
|
||
double dUpper = mPlot->xAxis->range().upper;
|
||
double proposedRight = mDragStartRange.upper;
|
||
|
||
TransparentGroupResult *pDraggableRect =NULL;
|
||
{
|
||
QMap<QString,QObject *>::Iterator it = mPlot->m_mapDragGroup.begin();
|
||
while( it != mPlot->m_mapDragGroup.end() )
|
||
{
|
||
if(it.key() == m_strUuid)
|
||
{
|
||
it++;
|
||
continue;
|
||
}
|
||
pDraggableRect = (TransparentGroupResult*)it.value();
|
||
//
|
||
QCPRange tmpRange = pDraggableRect->getRange();
|
||
if(tmpRange.lower <= dUpper && tmpRange.lower >= proposedRight)
|
||
{
|
||
dUpper = tmpRange.lower;
|
||
}
|
||
it++;
|
||
}
|
||
}
|
||
|
||
return dUpper;
|
||
}
|
||
|