Skip to content

Commit

Permalink
Signed-off-by: tanjunkiat <tanjunkiat@outlook.sg>
Browse files Browse the repository at this point in the history
Introducing lift delete button
  • Loading branch information
TanJunKiat committed Sep 18, 2024
1 parent f5d1381 commit 7a55fbd
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
44 changes: 44 additions & 0 deletions rmf_traffic_editor/gui/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,50 @@ bool Level::delete_selected()
return true;
}

bool Level::delete_lift_vertex(std::string lift_name)
{
int selected_vertex_idx = -1;
for (int i = 0; i < static_cast<int>(vertices.size()); i++)
{
if (vertices[i].params.count("lift_cabin")){
if (vertices[i].params["lift_cabin"].value_string == lift_name)
{
selected_vertex_idx = i;
break;
}
}
}

if (selected_vertex_idx >= 0)
{
edges.erase(
std::remove_if(
edges.begin(),
edges.end(),
[selected_vertex_idx](const Edge& edge)
{
if (edge.start_idx == selected_vertex_idx || edge.end_idx == selected_vertex_idx){
return true;
}
else
return false;
}),
edges.end());

for (Edge& edge : edges)
{
if (edge.start_idx > selected_vertex_idx)
edge.start_idx--;
if (edge.end_idx > selected_vertex_idx)
edge.end_idx--;
}

vertices.erase(vertices.begin() + selected_vertex_idx);
}

return true;
}

void Level::get_selected_items(
std::vector<Level::SelectedItem>& items)
{
Expand Down
1 change: 1 addition & 0 deletions rmf_traffic_editor/gui/level.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class Level

bool can_delete_current_selection();
bool delete_selected();
bool delete_lift_vertex(std::string lift_name);
void calculate_scale(const CoordinateSystem& coordinate_system);
void clear_selection();

Expand Down
30 changes: 27 additions & 3 deletions rmf_traffic_editor/gui/lift_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <QtWidgets>

LiftTable::LiftTable()
: TableList()
: TableList(3)
{
const QStringList labels = { "Name", "" };
const QStringList labels = { "Name", "", ""};
setHorizontalHeaderLabels(labels);
}

Expand All @@ -45,6 +45,9 @@ void LiftTable::update(Building& building)
QPushButton* edit_button = new QPushButton("Edit...", this);
setCellWidget(i, 1, edit_button);

QPushButton* delete_button = new QPushButton("Delete", this);
setCellWidget(i, 2, delete_button);

connect(
edit_button,
&QAbstractButton::clicked,
Expand All @@ -65,18 +68,39 @@ void LiftTable::update(Building& building)
&LiftDialog::redraw,
[this]() { emit redraw(); });
});

connect(
delete_button,
&QAbstractButton::clicked,
[this, &building, i]()
{
for (size_t j = 0; j < building.lifts.size(); j++)
{
if(j==i){
auto lift_name = building.lifts[j].name;
for (auto& level : building.levels){
level.delete_lift_vertex(lift_name);
}
building.lifts.erase(building.lifts.begin() + i);
break;
}
}
update(building);
emit redraw();
});
}

// we'll use the last row for the "Add" button
const int last_row_idx = static_cast<int>(building.lifts.size());
setCellWidget(last_row_idx, 0, nullptr);
setCellWidget(last_row_idx, 1, nullptr);
setItem(
last_row_idx,
0,
new QTableWidgetItem(
QString::fromStdString("")));
QPushButton* add_button = new QPushButton("Add...", this);
setCellWidget(last_row_idx, 1, add_button);
setCellWidget(last_row_idx, 2, add_button);
connect(
add_button, &QAbstractButton::clicked,
[this, &building]()
Expand Down

0 comments on commit 7a55fbd

Please sign in to comment.