Skip to content

Commit

Permalink
Addition of delete button for lift table
Browse files Browse the repository at this point in the history
  • Loading branch information
TanJunKiat committed Sep 19, 2024
1 parent cb1056d commit b232973
Show file tree
Hide file tree
Showing 3 changed files with 74 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)
{
std::vector<int> selected_vertex_idxes;
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_idxes.push_back(i);
}
}
}

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

for (Edge& edge : edges)
{
if (edge.start_idx > idx)
edge.start_idx--;
if (edge.end_idx > idx)
edge.end_idx--;
}
vertices.erase(vertices.begin() + 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
32 changes: 29 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,41 @@ 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 b232973

Please sign in to comment.