From 3ab2edf65c9af35d4288ee4c583e291d285df97f Mon Sep 17 00:00:00 2001 From: jackfiled Date: Tue, 28 Jun 2022 22:55:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E7=AB=99=E7=82=B9?= =?UTF-8?q?=E7=BC=96=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/mainScene.h | 4 +++- src/PosPair.cpp | 6 ++++-- src/mainScene.cpp | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/mainScene.h b/include/mainScene.h index c9f5bd8..c8efcd3 100644 --- a/include/mainScene.h +++ b/include/mainScene.h @@ -7,6 +7,7 @@ #include "QGraphicsScene" #include "QGraphicsPixmapItem" +#include "QGraphicsSimpleTextItem" #include "PosPair.h" #include "BusWidget.h" @@ -18,7 +19,6 @@ public: /** * 构造函数,同时生成站点 - * @param stop_node_number 站点的数量 */ explicit SceneManager(); ~SceneManager(); @@ -42,6 +42,8 @@ private: */ QGraphicsPixmapItem *pixmap_items; + QGraphicsSimpleTextItem *name_items; + /** * 每个站点的所在位置 */ diff --git a/src/PosPair.cpp b/src/PosPair.cpp index f34ba30..58f4f28 100644 --- a/src/PosPair.cpp +++ b/src/PosPair.cpp @@ -61,7 +61,8 @@ int PosPair::GetBusPosX() const } else if(pos_x >= stop_begin_x + stop_rail_width) { - result = pos_x + stop_bus_distance; + // 最下面一行得加上站点图片的高度 + result = pos_x + stop_bus_distance + 100; } else { @@ -81,7 +82,8 @@ int PosPair::GetBusPosY() const } else if(pos_y >= stop_begin_y + stop_rail_width) { - result = pos_y + stop_bus_distance; + // 最右边一行得加上站点图片的宽度 + result = pos_y + stop_bus_distance + 30; } else { diff --git a/src/mainScene.cpp b/src/mainScene.cpp index fd3a484..a5b3f72 100644 --- a/src/mainScene.cpp +++ b/src/mainScene.cpp @@ -10,6 +10,7 @@ SceneManager::SceneManager() stop_node_number = 0; pixmap_items = nullptr; stop_pos_pairs = nullptr; + name_items = nullptr; rect_item = new QGraphicsRectItem; bus = new BusWidget; @@ -38,6 +39,7 @@ void SceneManager::SetStopScene(int node_number) stop_node_number = node_number; pixmap_items = new QGraphicsPixmapItem[stop_node_number]; stop_pos_pairs = new PosPair[stop_node_number]; + name_items = new QGraphicsSimpleTextItem[stop_node_number]; int stop_space_length = stop_pos_pairs->GetStopSpaceLength(stop_node_number); double stop_scale = 0.15; @@ -65,6 +67,14 @@ void SceneManager::SetStopScene(int node_number) pixmap_items[i].setPos(stop_pos_pairs[i].pos_x, stop_pos_pairs[i].pos_y); } + for(int i = 0; i < stop_node_number; i++) + { + name_items[i].setText(QString::number(i + 1)); + name_items[i].setPos(stop_pos_pairs[i].pos_x + 30, stop_pos_pairs[i].pos_y); + + scene->addItem(&name_items[i]); + } + // 设置公交车图像 bus->ResetBusPos(stop_pos_pairs, node_number); scene->addItem(bus->item); @@ -78,6 +88,12 @@ void SceneManager::ClearStopScene() scene->removeItem(&pixmap_items[i]); } + for(int i = 0; i < stop_node_number; i++) + { + scene->removeItem(&name_items[i]); + } + + delete []name_items; delete []pixmap_items; delete []stop_pos_pairs; }