diff --git a/Include/nmNum/nmPlot/nmObjPointTool.h b/Include/nmNum/nmPlot/nmObjPointTool.h index cd01f4d3..b7046f9f 100644 --- a/Include/nmNum/nmPlot/nmObjPointTool.h +++ b/Include/nmNum/nmPlot/nmObjPointTool.h @@ -2,6 +2,8 @@ #include "nmObjToolBase.h" +class nmObjPoint; + // 数值试井绘图对象之工具(点) class NM_PLOT_EXPORT nmObjPointTool : public nmObjToolBase { @@ -25,6 +27,9 @@ public: protected: + // 仅绘制点位拖动预览,由调用方控制拖动时机和光标。 + void paintMovePreview(QPainter* painter, nmObjPoint& point); + // 根据鼠标当前选择情况确定不同的光标类型 virtual Qt::CursorShape getCursorBy(const int& nOption, \ const int& nSubIndex) override; diff --git a/Include/nmNum/nmPlot/nmObjPointWell.h b/Include/nmNum/nmPlot/nmObjPointWell.h index 2d7a68c3..e62b212d 100644 --- a/Include/nmNum/nmPlot/nmObjPointWell.h +++ b/Include/nmNum/nmPlot/nmObjPointWell.h @@ -27,8 +27,10 @@ class NM_PLOT_EXPORT nmObjPointWell : public nmObjPoint { ZxSubAxisY* pAxisY) override; // 设置Tools virtual void initTools() override; - // 击中后,ButtonUp后的处理 - // pt1:鼠标Down点,pt2:鼠标Up点 + // 以固定视口像素范围命中井点,地图缩放不改变可点中的范围。 + virtual bool _runHitTest(const QPointF& pt, int& nOption, int& nSubIndex) override; + + // 松手后提交井点移动,成功后才同步实际井位和关联裂缝。 virtual bool runMove(const QPointF& pt1, const QPointF& pt2) override; protected: @@ -64,7 +66,7 @@ class NM_PLOT_EXPORT nmObjPointWell : public nmObjPoint { // 创建新井 void createWell(); - // 编辑井 + // 地图可编辑时打开井参数窗口。 void editWell(); // 获取井的圆心和半径 QVector getWellInformation(); diff --git a/Include/nmNum/nmPlot/nmObjPointWellTool.h b/Include/nmNum/nmPlot/nmObjPointWellTool.h index c76fdeaf..0ee97fd0 100644 --- a/Include/nmNum/nmPlot/nmObjPointWellTool.h +++ b/Include/nmNum/nmPlot/nmObjPointWellTool.h @@ -10,6 +10,15 @@ class NM_PLOT_EXPORT nmObjPointWellTool : public nmObjPointTool public: nmObjPointWellTool(); - // 双击 + // 双击井点时按地图只读状态决定是否打开参数编辑。 virtual bool onLeftDoubleClick(const QPointF& pt) override; + + // 只有井点可移动且正在拖动时才显示位置预览。 + virtual void onPaint(QPainter* painter, const ZxPaintParam& param) override; + +protected: + // 将井点悬停交给公共光标流程。 + virtual Qt::CursorShape getCursorBy(const int& nOption, const int& nSubIndex) override; + // 井点拖动使用整体平移的张手和握手光标。 + virtual Qt::CursorShape interactionCursor(int nOption, int nSubIndex, bool dragging) const override; }; diff --git a/Src/nmNum/nmPlot/nmObjPointTool.cpp b/Src/nmNum/nmPlot/nmObjPointTool.cpp index b24e1b51..19826aed 100644 --- a/Src/nmNum/nmPlot/nmObjPointTool.cpp +++ b/Src/nmNum/nmPlot/nmObjPointTool.cpp @@ -119,24 +119,22 @@ void nmObjPointTool::onPaint(QPainter* painter, const ZxPaintParam& param) { if (m_oHitOption == OHO_Point) { - painter->save(); - - QPointF pt1 = getCurrentPos(); - double r = pObj->getDotRadius(); - int nStyle = pObj->getDotStyle(); - bool bFilling = pObj->getDotFilling(); - QColor clr = pObj->getDotColor(); - ZxDrawHelper::drawPoint(painter, pt1, nStyle, - r, !bFilling, clr); + paintMovePreview(painter, *pObj); Qt::CursorShape o = getCursorBy((int)m_oHitOption, pObj->m_nHitIndex); changeCursor(o); - - painter->restore(); } } } } +void nmObjPointTool::paintMovePreview(QPainter* painter, nmObjPoint& point) +{ + painter->save(); + ZxDrawHelper::drawPoint(painter, getCurrentPos(), point.getDotStyle(), point.getDotRadius(), + !point.getDotFilling(), point.getDotColor()); + painter->restore(); +} + Qt::CursorShape nmObjPointTool::getCursorBy(const int& nOption, \ const int& nSubIndex) { diff --git a/Src/nmNum/nmPlot/nmObjPointWell.cpp b/Src/nmNum/nmPlot/nmObjPointWell.cpp index 29b4c234..7da7dee9 100644 --- a/Src/nmNum/nmPlot/nmObjPointWell.cpp +++ b/Src/nmNum/nmPlot/nmObjPointWell.cpp @@ -2,6 +2,7 @@ //#include #include +#include #include "IxPtyPano.h" #include "ZxSubAxisX.h" @@ -9,6 +10,7 @@ #include "zxLogInstance.h" #include "ZxPlot.h" +#include "ZxRenderView.h" #include "ZxObjText.h" #include "ZxDataWell.h" @@ -86,17 +88,42 @@ void nmObjPointWell::initTools() nmObjBase::initTools(); } -bool nmObjPointWell::runMove(const QPointF &pt1, const QPointF &pt2) +bool nmObjPointWell::_runHitTest(const QPointF& pt, int& nOption, int& nSubIndex) { - nmObjPoint::runMove(pt1, pt2); + nOption = -1; + nSubIndex = -1; + if (m_vecPoints.isEmpty() || m_pAxisX == nullptr || m_pAxisY == nullptr || + !nmObjBase::_runHitTest(pt, nOption, nSubIndex)) { + return false; + } - // 更新井的位置信息 - if(m_pGraphicBinder) { - QPointF newLocation = this->getValueOf(pt2); - m_pGraphicBinder->syncWellMoveFromGraphic(this, m_enumWellType, newLocation); + ZxRenderView* view = getView(); + if (view == nullptr) { + return false; + } + const QPointF delta = view->mapFromScene(pt) - view->mapFromScene(getCenterPos()); + const qreal distanceSquared = delta.x() * delta.x() + delta.y() * delta.y(); + if (!qIsFinite(distanceSquared) || distanceSquared > NodeHitRadiusPixels * NodeHitRadiusPixels) { + return false; } - if (m_pGraphicBinder) { + nOption = OHO_Point; + nSubIndex = 0; + return true; +} + +bool nmObjPointWell::runMove(const QPointF& pt1, const QPointF& pt2) +{ + if (isReadOnly() || isLockPos() || m_oHitOption != OHO_Point || m_vecPoints.isEmpty()) { + return false; + } + if (!nmObjPoint::runMove(pt1, pt2)) { + return false; + } + + if (m_pGraphicBinder != nullptr) { + // 使用图元提交后的模型坐标,避免鼠标位置与实际井位不一致。 + m_pGraphicBinder->syncWellMoveFromGraphic(this, m_enumWellType, getPtValueOf(0)); m_pGraphicBinder->notifyDataChanged(); } return true; @@ -282,7 +309,7 @@ void nmObjPointWell::createWell() void nmObjPointWell::editWell() { - if (m_pGraphicBinder == nullptr) { + if (isReadOnly() || m_pGraphicBinder == nullptr) { return; } diff --git a/Src/nmNum/nmPlot/nmObjPointWellTool.cpp b/Src/nmNum/nmPlot/nmObjPointWellTool.cpp index 9cb03ee2..14b9ef38 100644 --- a/Src/nmNum/nmPlot/nmObjPointWellTool.cpp +++ b/Src/nmNum/nmPlot/nmObjPointWellTool.cpp @@ -1,8 +1,6 @@ #include -//#include "ZxBaseUtil.h" - -#include "nmDefines.h" +#include "nmDataLogFile.h" #include "nmObjPointWell.h" #include "nmObjPointWellTool.h" @@ -10,23 +8,48 @@ nmObjPointWellTool::nmObjPointWellTool() { setText(tr("nObjPointWellTool")); m_oNot = NMOT_Point_Well; + enableInteractionCursor(); + enableEscapeCancellation(); } -bool nmObjPointWellTool::onLeftDoubleClick(const QPointF &pt) +bool nmObjPointWellTool::onLeftDoubleClick(const QPointF& pt) { - if (NULL != m_pObj) { - int nOption = -1; - int nIndex = -1; - if (m_pObj->_runHitTest(pt, nOption, nIndex)) { - // yours own codes - nmObjPointWell* pObj = dynamic_cast(m_pObj); - if (pObj == nullptr) { - return nmObjToolBase::onLeftDoubleClick(pt); - } - NM_DATA_LOG_FILE(pObj->getWellID()); - pObj->editWell(); - return true; + nmObjPointWell* well = dynamic_cast(m_pObj); + int option = -1; + int index = -1; + if (well != nullptr && well->_runHitTest(pt, option, index)) { + if (!well->isReadOnly()) { + NM_DATA_LOG_FILE(well->getWellID()); + well->editWell(); } + return true; } return nmObjToolBase::onLeftDoubleClick(pt); } + +void nmObjPointWellTool::onPaint(QPainter* painter, const ZxPaintParam& param) +{ + if (m_pObj == nullptr) { + nmObjPointTool::onPaint(painter, param); + return; + } + + nmObjPointWell* well = dynamic_cast(m_pObj); + if (well != nullptr && well->isSelected() && well->isVisible() && + !well->isReadOnly() && !well->isLockPos() && m_oHitOption == OHO_Point && + m_bTracking && isLeftDown() && !isClick()) { + paintMovePreview(painter, *well); + } +} + +Qt::CursorShape nmObjPointWellTool::getCursorBy(const int& nOption, const int& nSubIndex) +{ + return nmObjToolBase::getCursorBy(nOption, nSubIndex); +} + +Qt::CursorShape nmObjPointWellTool::interactionCursor(int nOption, int nSubIndex, bool dragging) const +{ + // 拖井点是整体平移,复用位置锁定、只读和手形光标规则。 + const ObjHitOption moveOption = nOption == OHO_Point ? OHO_Bound : OHO_None; + return nmObjToolBase::interactionCursor(moveOption, nSubIndex, dragging); +}