优化解释结论道绘图,支持同一个结论的上下rect框联动,上方拖动会带动下方变化
This commit is contained in:
parent
d512c3cac9
commit
fcce4f565a
|
|
@ -14,12 +14,19 @@ class TransparentDraggableResult : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit TransparentDraggableResult(QMyCustomPlot *parentPlot, QString strUuid="", double minWidth = 1.0, QString strTitle = "")
|
explicit TransparentDraggableResult(QMyCustomPlot *parentPlot, TransparentDraggableResult *upDraggableResult=nullptr, QString strUuid="", double minWidth = 1.0, QString strTitle = "")
|
||||||
: QObject(parentPlot), mPlot(parentPlot), mstrTitle(strTitle), mMinWidth(minWidth)
|
: QObject(parentPlot), mPlot(parentPlot), mstrTitle(strTitle), mMinWidth(minWidth)
|
||||||
{
|
{
|
||||||
|
m_upDraggableResult = upDraggableResult;
|
||||||
m_strUuid = strUuid;
|
m_strUuid = strUuid;
|
||||||
//
|
//
|
||||||
initRect();
|
initRect();
|
||||||
|
|
||||||
|
//将自己,设置为上方rect的下方
|
||||||
|
if(m_upDraggableResult)
|
||||||
|
{
|
||||||
|
m_upDraggableResult->m_downDraggableResult = this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~TransparentDraggableResult() {
|
~TransparentDraggableResult() {
|
||||||
|
|
@ -91,7 +98,8 @@ public:
|
||||||
//mRect->bottomRight->setCoords(right, mPlot->yAxis->range().lower);
|
//mRect->bottomRight->setCoords(right, mPlot->yAxis->range().lower);
|
||||||
|
|
||||||
updateHandles();
|
updateHandles();
|
||||||
mPlot->replot();
|
//后面统一刷新上方和下方rect
|
||||||
|
//mPlot->replot();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前范围
|
// 获取当前范围
|
||||||
|
|
@ -196,8 +204,23 @@ private:
|
||||||
mRightHandle->topLeft->setParentAnchor(mRect->bottomLeft);
|
mRightHandle->topLeft->setParentAnchor(mRect->bottomLeft);
|
||||||
mRightHandle->bottomRight->setParentAnchor(mRect->bottomRight);
|
mRightHandle->bottomRight->setParentAnchor(mRect->bottomRight);
|
||||||
mRightHandle->topLeft->setCoords(-5, 5); // 矩形大小
|
mRightHandle->topLeft->setCoords(-5, 5); // 矩形大小
|
||||||
mRightHandle->bottomRight->setCoords(5, -5); // 矩形大小
|
mRightHandle->bottomRight->setCoords(5, -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);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
@ -229,44 +252,40 @@ private slots:
|
||||||
// }
|
// }
|
||||||
|
|
||||||
void onMousePress(QMouseEvent *event) {
|
void onMousePress(QMouseEvent *event) {
|
||||||
if(event->button() != Qt::LeftButton)//右键
|
// //右键
|
||||||
{
|
// if(event->button() != Qt::LeftButton)
|
||||||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());//x轴展示深度
|
// {
|
||||||
QCPRange currentRange = getRange();
|
// double y = mPlot->xAxis->pixelToCoord(event->pos().y());//x轴展示深度
|
||||||
if(mLeftHandle->selectTest(event->pos(), false) < 5) {
|
// QCPRange currentRange = getRange();
|
||||||
mDragMode = DragNone;
|
// if(mLeftHandle->selectTest(event->pos(), false) < 5) {
|
||||||
}
|
// mDragMode = DragNone;
|
||||||
else if(mRightHandle->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) {
|
// //else if(x >= currentRange.lower && x <= currentRange.upper) {
|
||||||
mDragMode = DragNone;
|
// else if(y >= currentRange.lower && y <= currentRange.upper) {
|
||||||
}
|
// mDragMode = DragNone;
|
||||||
else {
|
// }
|
||||||
mDragMode = DragNone;
|
// else {
|
||||||
return;
|
// mDragMode = DragNone;
|
||||||
}
|
// return;
|
||||||
|
// }
|
||||||
//event->accept();
|
// //event->accept();
|
||||||
|
// QMenu menu(nullptr);
|
||||||
QMenu menu(nullptr);
|
// QAction *delAction = menu.addAction("删除框图");
|
||||||
QAction *delAction = menu.addAction("删除框图");
|
// //delAction->installEventFilter(this);
|
||||||
//delAction->installEventFilter(this);
|
// connect(delAction, &QAction::triggered, this, &TransparentDraggableResult::onDelRect);
|
||||||
connect(delAction, &QAction::triggered, this, &TransparentDraggableResult::onDelRect);
|
|
||||||
|
|
||||||
// QAction* pItem = menu.exec(event->globalPos());
|
// QAction* pItem = menu.exec(event->globalPos());
|
||||||
// if(pItem == delAction)
|
// if(pItem == delAction)
|
||||||
// {
|
// {
|
||||||
// //event->accept();
|
// //event->accept();
|
||||||
|
|
||||||
// int ii=0;
|
// int ii=0;
|
||||||
// ii++;
|
// ii++;
|
||||||
// }
|
// }
|
||||||
menu.exec(event->globalPos());
|
// menu.exec(event->globalPos());
|
||||||
|
// return;
|
||||||
return;
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
|
|
||||||
|
|
@ -297,21 +316,38 @@ private slots:
|
||||||
mDragStartY = y;
|
mDragStartY = y;
|
||||||
mDragStartRange = currentRange;
|
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(QMouseEvent *event) {
|
void onMouseMove_in(QMouseEvent *event) {
|
||||||
if(mDragMode == DragNone) return;
|
|
||||||
|
|
||||||
event->accept();
|
|
||||||
|
|
||||||
//double x = mPlot->xAxis->pixelToCoord(event->pos().x());
|
//double x = mPlot->xAxis->pixelToCoord(event->pos().x());
|
||||||
//double dx = x - mDragStartX;
|
//double dx = x - mDragStartX;
|
||||||
|
|
||||||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());
|
double y = mPlot->xAxis->pixelToCoord(event->pos().y());
|
||||||
double dy = y - mDragStartY;
|
double dy = y - mDragStartY;
|
||||||
|
|
||||||
QCPRange newRange = mDragStartRange;
|
QCPRange newRange = mDragStartRange;
|
||||||
|
|
||||||
switch(mDragMode) {
|
switch(mDragMode) {
|
||||||
case DragLeft: {
|
case DragLeft: {
|
||||||
//double proposedLeft = mDragStartRange.lower + dx;
|
//double proposedLeft = mDragStartRange.lower + dx;
|
||||||
|
|
@ -341,7 +377,7 @@ private slots:
|
||||||
double center = mDragStartRange.center() + dy;
|
double center = mDragStartRange.center() + dy;
|
||||||
newRange.lower = center - width/2;
|
newRange.lower = center - width/2;
|
||||||
newRange.upper = center + width/2;
|
newRange.upper = center + width/2;
|
||||||
|
|
||||||
// 检查是否超出轴范围
|
// 检查是否超出轴范围
|
||||||
if(newRange.lower < getMyLower()) {
|
if(newRange.lower < getMyLower()) {
|
||||||
newRange.lower = getMyLower();
|
newRange.lower = getMyLower();
|
||||||
|
|
@ -366,7 +402,7 @@ private slots:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// //取整数(方便显示统计,左右边界整数显示。)
|
// //取整数(方便显示统计,左右边界整数显示。)
|
||||||
// newRange.lower = (int)newRange.lower;
|
// newRange.lower = (int)newRange.lower;
|
||||||
// QCPRange rangeByFile = mPlot->xAxis->range();
|
// QCPRange rangeByFile = mPlot->xAxis->range();
|
||||||
|
|
@ -374,7 +410,7 @@ private slots:
|
||||||
// {
|
// {
|
||||||
// newRange.upper = (int)newRange.upper;
|
// newRange.upper = (int)newRange.upper;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// 最终确保宽度不小于最小值(针对整体拖动的情况)
|
// 最终确保宽度不小于最小值(针对整体拖动的情况)
|
||||||
if(newRange.size() < mMinWidth) {
|
if(newRange.size() < mMinWidth) {
|
||||||
if(mDragMode == DragRect) {
|
if(mDragMode == DragRect) {
|
||||||
|
|
@ -391,13 +427,84 @@ private slots:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setRange(newRange.lower, newRange.upper);
|
|
||||||
|
|
||||||
|
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(QMouseEvent *event) {
|
void onMouseRelease_in(QMouseEvent *event) {
|
||||||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||||||
event->accept();
|
event->accept();
|
||||||
//避免二次绘制框图
|
//避免二次绘制框图
|
||||||
mPlot->m_bDrawRect = false;
|
mPlot->m_bDrawRect = false;
|
||||||
|
|
@ -408,11 +515,36 @@ private slots:
|
||||||
// mPlot->graph(0)->setSelection(emptySelection);
|
// mPlot->graph(0)->setSelection(emptySelection);
|
||||||
// mPlot->replot();
|
// mPlot->replot();
|
||||||
|
|
||||||
//取消选中框
|
// //取消选中框
|
||||||
mPlot->selectionRect()->cancel();
|
// mPlot->selectionRect()->cancel();
|
||||||
mPlot->replot();
|
// mPlot->replot();
|
||||||
mPlot->selectionRect()->mActive=true;
|
// 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 getMyLower()
|
||||||
|
|
@ -484,6 +616,8 @@ private:
|
||||||
QString mstrTitle="";
|
QString mstrTitle="";
|
||||||
QString m_strUuid = "";
|
QString m_strUuid = "";
|
||||||
|
|
||||||
|
TransparentDraggableResult *m_upDraggableResult=nullptr;
|
||||||
|
TransparentDraggableResult *m_downDraggableResult=nullptr;
|
||||||
QString m_Result;
|
QString m_Result;
|
||||||
|
|
||||||
enum DragMode { DragNone, DragLeft, DragRight, DragRect };
|
enum DragMode { DragNone, DragLeft, DragRight, DragRect };
|
||||||
|
|
|
||||||
|
|
@ -1704,17 +1704,51 @@ bool FormDraw::LoadFromSLF_Result(QMyCustomPlot *widget, QString strSlfName, QSt
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
QString strUuid = "";
|
||||||
if(result != "" && m_Result->MDepth1!=0) {
|
if(result != "" && m_Result->MDepth1!=0) {
|
||||||
widget->addResultToPlot(-m_Result->MDepth1, -m_Result->StartDepth, result);
|
widget->addResultToPlot(-m_Result->MDepth1, -m_Result->StartDepth, result, strUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result1 != "" && m_Result->MDepth2!=0) {
|
if(result1 != "" && m_Result->MDepth2!=0) {
|
||||||
widget->addResultToPlot(-m_Result->MDepth2, -m_Result->MDepth1, result1);
|
widget->addResultToPlot(-m_Result->MDepth2, -m_Result->MDepth1, result1, strUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result2 != "" && m_Result->MDepth3!=0) {
|
if(result2 != "" && m_Result->MDepth3!=0) {
|
||||||
widget->addResultToPlot(-m_Result->MDepth3, -m_Result->MDepth2, result2);
|
widget->addResultToPlot(-m_Result->MDepth3, -m_Result->MDepth2, result2, strUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(result3 != "" && m_Result->MDepth4!=0) {
|
||||||
|
widget->addResultToPlot(-m_Result->MDepth4, -m_Result->MDepth3, result3, strUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result4 != "" && m_Result->MDepth5!=0) {
|
||||||
|
widget->addResultToPlot(-m_Result->MDepth5, -m_Result->MDepth4, result4, strUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result5 != "" && m_Result->MDepth6!=0) {
|
||||||
|
widget->addResultToPlot(-m_Result->MDepth6, -m_Result->MDepth5, result5, strUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result6 != "" && m_Result->MDepth6!=0) {
|
||||||
|
widget->addResultToPlot(-m_Result->MDepth7, -m_Result->MDepth6, result6, strUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result7 != "" && m_Result->MDepth8!=0) {
|
||||||
|
widget->addResultToPlot(-m_Result->MDepth8, -m_Result->MDepth7, result7, strUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result8 != "" && m_Result->MDepth9!=0) {
|
||||||
|
widget->addResultToPlot(-m_Result->MDepth9, -m_Result->MDepth8, result8, strUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result9 != "" && m_Result->MDepth10!=0) {
|
||||||
|
widget->addResultToPlot(-m_Result->MDepth10, -m_Result->MDepth9, result9, strUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result10 != "" && m_Result->MDepth10!=0) {
|
||||||
|
widget->addResultToPlot(-m_Result->EndDepth, -m_Result->MDepth10, result10, strUuid);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
logio->CloseTable(iIndex);
|
logio->CloseTable(iIndex);
|
||||||
delete pstr;
|
delete pstr;
|
||||||
|
|
|
||||||
|
|
@ -265,13 +265,21 @@ void QMyCustomPlot::addTextToPlot(double left_Low, double right_Hight, const QSt
|
||||||
m_mapDraggableRect[strUuid] = dragRect;
|
m_mapDraggableRect[strUuid] = dragRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMyCustomPlot::addResultToPlot(double left_Low, double right_Hight, QString myResult)
|
void QMyCustomPlot::addResultToPlot(double left_Low, double right_Hight, QString myResult, QString &strUuid)
|
||||||
{
|
{
|
||||||
|
//获取上方Rect
|
||||||
|
TransparentDraggableResult *upDragRect = nullptr;
|
||||||
|
if(strUuid!="")
|
||||||
|
{
|
||||||
|
upDragRect = (TransparentDraggableResult *)m_mapDraggable_Result[strUuid];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
QtCommonClass *qtCommon = new QtCommonClass(this);
|
QtCommonClass *qtCommon = new QtCommonClass(this);
|
||||||
QString strUuid = qtCommon->getUUid();
|
strUuid = qtCommon->getUUid();
|
||||||
|
|
||||||
// 在初始化代码中
|
// 在初始化代码中
|
||||||
TransparentDraggableResult *dragRect = new TransparentDraggableResult(this, strUuid);
|
TransparentDraggableResult *dragRect = new TransparentDraggableResult(this, upDragRect, strUuid);
|
||||||
// 设置初始范围
|
// 设置初始范围
|
||||||
dragRect->setRange(left_Low, right_Hight);
|
dragRect->setRange(left_Low, right_Hight);
|
||||||
// 可选:设置颜色
|
// 可选:设置颜色
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ public:
|
||||||
|
|
||||||
void addTextToPlot(double left_Low, double right_Hight, const QString strText);
|
void addTextToPlot(double left_Low, double right_Hight, const QString strText);
|
||||||
|
|
||||||
void addResultToPlot(double left_Low, double right_Hight, QString myResult);
|
void addResultToPlot(double left_Low, double right_Hight, QString myResult, QString &strUuid);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void s_LineClicked(int index);
|
void s_LineClicked(int index);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user