From 1f1383af9c6dd438a0b1a01b378c6a3c811492bf Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Sun, 12 Oct 2025 21:37:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E8=BD=AF=E4=BB=B6=E6=9E=B6?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MapPresent/MapPresent.cpp | 77 ++++++++++----------------------------- MapPresent/MapPresent.h | 23 +++++++++--- 2 files changed, 38 insertions(+), 62 deletions(-) diff --git a/MapPresent/MapPresent.cpp b/MapPresent/MapPresent.cpp index 2d2bb62..f51239d 100644 --- a/MapPresent/MapPresent.cpp +++ b/MapPresent/MapPresent.cpp @@ -6,26 +6,8 @@ #include #include #include - - -class OptionGroup { -private: - PresentOption _bind_opt; - std::shared_ptr _next_group; - -public: - OptionGroup(const PresentOption& opt, std::shared_ptr next = nullptr) - :_bind_opt(opt), _next_group(next) { - } - - std::shared_ptr nextGet() const { - return _next_group; - } - const PresentOption& optionGet() const { - return _bind_opt; - } -}; - +#include +#include MapPresent::MapPresent(QWidget* parent /*= nullptr*/) @@ -35,7 +17,7 @@ MapPresent::MapPresent(QWidget* parent /*= nullptr*/) _center_index.col = 0; auto delegate = new BasicUnitDelegate(this); - _present_delegate[delegate->unitType()] = delegate; + _type_present_delegate[delegate->unitType()] = delegate; connect(this, &MapPresent::mouseOut, delegate, &BasicUnitDelegate::hotClear); connect(this, &MapPresent::mouseHover, delegate, &BasicUnitDelegate::hotIndexSet); connect(delegate, &BasicUnitDelegate::updateRequest, [=]() { this->update(); }); @@ -46,15 +28,10 @@ MapPresent::MapPresent(QWidget* parent /*= nullptr*/) PresentIndex MapPresent::indexGet(const QPointF& pos) const { QList templist; - for (auto unit_g : _visible_unit_groups) { - while (unit_g) { - auto unit = unit_g->optionGet(); + for (auto unit : _visible_units) { + if (unit.outline.contains(pos)) { + templist << unit; - if (unit.outline.contains(pos)) { - templist << unit; - } - - unit_g = unit_g->nextGet(); } } @@ -95,33 +72,26 @@ QRectF MapPresent::outlineGet(const PresentIndex& idx) const return QRectF(target_center.toPointF(), QSizeF(ap_len * 2, ap_len * 2)); } -#include -#include void MapPresent::paintEvent(QPaintEvent* ev) { QWidget::paintEvent(ev); - UnitPresentDelegate& t = *_present_delegate[0]; + UnitPresentDelegate& t = *_type_present_delegate[0]; QPainter p(this); - for (auto opt_g : _visible_unit_groups) { - while (opt_g) { - p.save(); + for (auto opt : _visible_units) { + p.save(); - auto opt = opt_g->optionGet(); - auto rect = opt.outline; - p.translate(rect.topLeft()); - rect.moveTo(0, 0); + auto rect = opt.outline; + p.translate(rect.topLeft()); + rect.moveTo(0, 0); - auto clip_path = BasicUnitDelegate::clipPathGet(rect); - p.setClipPath(clip_path); + auto clip_path = BasicUnitDelegate::clipPathGet(rect); + p.setClipPath(clip_path); - opt.outline = rect; - t.paint(&p, opt); + opt.outline = rect; + t.paint(&p, opt); - p.restore(); - - opt_g = opt_g->nextGet(); - } + p.restore(); } } @@ -165,30 +135,23 @@ PresentOption AssumeOpt(PresentIndex index, QRectF rf) { } void MapPresent::visible_units_tidy() { - _visible_unit_groups.clear(); + _visible_units.clear(); QRectF curr_outline = this->rect(); - _visible_unit_groups << std::make_shared( - AssumeOpt(_center_index, outlineGet(_center_index)) - ); + _visible_units << AssumeOpt(_center_index, outlineGet(_center_index)); int visible_count = 1, deduce_x = 1; while (visible_count) { visible_count = 0; - std::shared_ptr prev_g = nullptr; auto siblings = siblingsGet(_center_index, deduce_x++); for (auto unit : siblings) { auto visible_rect = outlineGet(unit); if (curr_outline.intersects(visible_rect)) { - prev_g = std::make_shared(AssumeOpt(unit, visible_rect), prev_g); + _visible_units << AssumeOpt(unit, visible_rect); visible_count++; } } - - if (prev_g) { - _visible_unit_groups << prev_g; - } } // TODO 构建快速测试组织结构 diff --git a/MapPresent/MapPresent.h b/MapPresent/MapPresent.h index 592b1a7..ef7c0c5 100644 --- a/MapPresent/MapPresent.h +++ b/MapPresent/MapPresent.h @@ -69,9 +69,8 @@ signals: void updateRequest(const PresentIndex &idx); }; -class OptionGroup; /// -/// 基础地图绘制 +/// 基础瓦片地图绘制 /// class MAPPRESENT_EXPORT MapPresent : public QWidget { @@ -91,13 +90,27 @@ private: PresentIndex _center_index; // =================================== - QList> _visible_unit_groups; + /// + /// 试图核心索引 + /// + QList _visible_units; + /// + /// 可视化单元整理 + /// void visible_units_tidy(); - + /// + /// 可视化索引填充 + /// + /// + /// + /// QList item_supply(const PresentIndex& a, const PresentIndex& b) const; // =================================== - QHash _present_delegate; + /// + /// 类型化绘制委托 + /// + QHash _type_present_delegate; public: