67 lines
2.8 KiB
C++
67 lines
2.8 KiB
C++
#pragma once
|
||
#include <functional>
|
||
#include <vector>
|
||
|
||
#include <QObject>
|
||
#include <QPoint>
|
||
#include <QPointF>
|
||
#include <QPointer>
|
||
#include <Qt> // Qt::FocusPolicy
|
||
|
||
class QwtPlot;
|
||
|
||
namespace geopro::app {
|
||
|
||
class ContourDrawOverlay;
|
||
|
||
// I9 图上绘形工具:开启后在等值面图上用鼠标采集几何,实时预览,完成后回调数据坐标点。
|
||
// 复刻原版 contour overlay 绘制交互(先弹窗选类型→再图上画→drawingComplete):
|
||
// markType 1 点 / 4 文字:单击落点立即完成;
|
||
// markType 2 线:逐点单击,双击或回车结束(≥2 点);
|
||
// markType 3 面:逐点单击,双击或回车闭合(≥3 点)。
|
||
// Esc 取消。绘制时事件优先于 LivePanner/hover 消费(开启期间禁用平移)。
|
||
// 不拥有 plot(外部持有,QPointer 守护);overlay 父=canvas 随之析构。
|
||
class ContourDrawTool : public QObject {
|
||
Q_OBJECT
|
||
public:
|
||
// xAxis/yAxis:等值面所在轴(GridDataChartView 为 xBottom/yLeft)。
|
||
ContourDrawTool(QwtPlot* plot, int xAxis, int yAxis, QObject* parent = nullptr);
|
||
|
||
// 完成回调:参数为数据坐标点序列(已按类型归一化:点/文字 1 点,线≥2,面≥3)。
|
||
void setOnComplete(std::function<void(const std::vector<QPointF>&)> cb) { onComplete_ = std::move(cb); }
|
||
// 取消回调(Esc / 右键 / 外部 cancel):调用方据此恢复 UI(如重新开放工具条)。
|
||
void setOnCancel(std::function<void()> cb) { onCancel_ = std::move(cb); }
|
||
|
||
// 开始绘制指定标注类型("1".."4" 对应整数)。会重置已采集点并显示提示。
|
||
void begin(int markType);
|
||
// 外部强制取消(不触发 onCancel_)。
|
||
void cancel();
|
||
bool isActive() const { return active_; }
|
||
|
||
protected:
|
||
bool eventFilter(QObject* obj, QEvent* ev) override;
|
||
|
||
private:
|
||
QPointF toData(const QPoint& canvasPos) const; // 像素 → 数据坐标
|
||
void addVertex(const QPoint& canvasPos);
|
||
void finish(); // 校验最少点数 → onComplete_
|
||
void refreshOverlay(); // 把当前已落点(数据坐标)映射回像素喂给 overlay 预览
|
||
|
||
QPointer<QwtPlot> plot_;
|
||
int xAxis_;
|
||
int yAxis_;
|
||
std::function<void(const std::vector<QPointF>&)> onComplete_;
|
||
std::function<void()> onCancel_;
|
||
|
||
ContourDrawOverlay* overlay_ = nullptr; // 父=canvas
|
||
bool active_ = false;
|
||
int markType_ = 0;
|
||
std::vector<QPointF> dataPts_; // 已采集点(数据坐标)
|
||
QPoint lastCursor_; // 当前光标(橡皮筋预览到此)
|
||
Qt::FocusPolicy savedFocus_ = Qt::NoFocus; // begin 前 canvas 焦点策略(退出还原)
|
||
bool savedFocusValid_ = false;
|
||
void restoreCanvas(); // 退出绘制态:还原光标/焦点策略 + 隐藏 overlay
|
||
};
|
||
|
||
} // namespace geopro::app
|