#pragma once #include "mappresent_global.h" #include #include /// /// 绘制索引 /// struct MAPPRESENT_EXPORT PresentIndex { /// /// 行号 /// int row = INT_MAX; /// /// 列号 /// int col = INT_MAX; bool isValid() const; PresentIndex& operator+=(const PresentIndex& other); bool operator!=(const PresentIndex& other) const; bool operator==(const PresentIndex& other) const; }; /// /// 绘制选项 /// struct PresentOption { /// /// 当前所绘制索引 /// PresentIndex index; /// /// 当前绘制外缘 /// QRectF outline; PresentOption& operator=(const PresentOption& other); }; /// /// 单元绘制委托 /// class UnitPresentDelegate : public QObject { Q_OBJECT public: UnitPresentDelegate(QObject* parent = nullptr); virtual ~UnitPresentDelegate() = default; /// /// 匹配单元类型 /// /// virtual int unitType() const = 0; /// /// 绘制本单元瓦片 /// /// /// virtual void paint(QPainter* p, const PresentOption& option) = 0; signals: /// /// 更新通知/重绘请求 /// void updateRequest(const PresentIndex &idx); }; class OptionGroup; /// /// 基础地图绘制 /// class MAPPRESENT_EXPORT MapPresent : public QWidget { Q_OBJECT private: /// /// 初级区域矩形变长 /// const float _primitive_region_square_len = 100; /// /// 缩放倍数 /// short _scale_times = 1; /// /// 当前瓦片地图中心索引 /// PresentIndex _center_index; // =================================== QList> _visible_units; void visibleUnitsTidy(); QList siblingsGet(const PresentIndex& center, uint16_t dist = 1) const; QList itemFills(const PresentIndex& a, const PresentIndex& b) const; // =================================== QHash _present_delegate; public: MapPresent(QWidget* parent = nullptr); /// /// 通过widget上定位获取绘制索引 /// /// /// PresentIndex indexGet(const QPointF& pos) const; /// /// 通过绘制索引获取指定单元外接矩形 /// /// /// QRectF outlineGet(const PresentIndex& idx) const; signals: void mouseIn(); void mouseOut(); void mouseHover(const PresentIndex& unit_index); protected: void paintEvent(QPaintEvent* ev) override; void resizeEvent(QResizeEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; void enterEvent(QEvent* event) override; void leaveEvent(QEvent* event) override; };