添加了站点编号

This commit is contained in:
jackfiled 2022-06-28 22:55:00 +08:00
parent 2a5b4b3841
commit 3ab2edf65c
3 changed files with 23 additions and 3 deletions

View File

@ -7,6 +7,7 @@
#include "QGraphicsScene" #include "QGraphicsScene"
#include "QGraphicsPixmapItem" #include "QGraphicsPixmapItem"
#include "QGraphicsSimpleTextItem"
#include "PosPair.h" #include "PosPair.h"
#include "BusWidget.h" #include "BusWidget.h"
@ -18,7 +19,6 @@ public:
/** /**
* *
* @param stop_node_number
*/ */
explicit SceneManager(); explicit SceneManager();
~SceneManager(); ~SceneManager();
@ -42,6 +42,8 @@ private:
*/ */
QGraphicsPixmapItem *pixmap_items; QGraphicsPixmapItem *pixmap_items;
QGraphicsSimpleTextItem *name_items;
/** /**
* *
*/ */

View File

@ -61,7 +61,8 @@ int PosPair::GetBusPosX() const
} }
else if(pos_x >= stop_begin_x + stop_rail_width) else if(pos_x >= stop_begin_x + stop_rail_width)
{ {
result = pos_x + stop_bus_distance; // 最下面一行得加上站点图片的高度
result = pos_x + stop_bus_distance + 100;
} }
else else
{ {
@ -81,7 +82,8 @@ int PosPair::GetBusPosY() const
} }
else if(pos_y >= stop_begin_y + stop_rail_width) else if(pos_y >= stop_begin_y + stop_rail_width)
{ {
result = pos_y + stop_bus_distance; // 最右边一行得加上站点图片的宽度
result = pos_y + stop_bus_distance + 30;
} }
else else
{ {

View File

@ -10,6 +10,7 @@ SceneManager::SceneManager()
stop_node_number = 0; stop_node_number = 0;
pixmap_items = nullptr; pixmap_items = nullptr;
stop_pos_pairs = nullptr; stop_pos_pairs = nullptr;
name_items = nullptr;
rect_item = new QGraphicsRectItem; rect_item = new QGraphicsRectItem;
bus = new BusWidget; bus = new BusWidget;
@ -38,6 +39,7 @@ void SceneManager::SetStopScene(int node_number)
stop_node_number = node_number; stop_node_number = node_number;
pixmap_items = new QGraphicsPixmapItem[stop_node_number]; pixmap_items = new QGraphicsPixmapItem[stop_node_number];
stop_pos_pairs = new PosPair[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); int stop_space_length = stop_pos_pairs->GetStopSpaceLength(stop_node_number);
double stop_scale = 0.15; 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); 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); bus->ResetBusPos(stop_pos_pairs, node_number);
scene->addItem(bus->item); scene->addItem(bus->item);
@ -78,6 +88,12 @@ void SceneManager::ClearStopScene()
scene->removeItem(&pixmap_items[i]); 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 []pixmap_items;
delete []stop_pos_pairs; delete []stop_pos_pairs;
} }