56 QStringList columns{
"Provider",
"Name",
"X [mm]",
"Y [mm]",
"Yaw [\u00b0]"};
57 setColumnCount(columns.size());
58 setHorizontalHeaderLabels(columns);
59 horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
60 horizontalHeader()->setVisible(
true);
62 setEditTriggers(QAbstractItemView::NoEditTriggers);
63 setSortingEnabled(
true);
65 setAlternatingRowColors(
true);
67 setSelectionMode(QAbstractItemView::SingleSelection);
68 setSelectionBehavior(QAbstractItemView::SelectRows);
74 setContextMenuPolicy(Qt::CustomContextMenu);
118 const int precision = 2;
121 setSortingEnabled(
false);
123 int row = this->row(vertex.attrib().tableWidgetItem);
125 QString locationProviderDisplayName =
126 QString::fromStdString(vertex.attrib().getProviderName());
128 QString locationDisplayName = QString::fromStdString(vertex.attrib().getLocationName());
129 if (vertex.attrib().changed)
131 locationDisplayName +=
"*";
133 item(row, 0)->setText(locationProviderDisplayName);
134 item(row, 1)->setText(locationDisplayName);
135 item(row, 1)->setData(Qt::UserRole,
136 QString::fromStdString(vertex.attrib().getLocationName()));
137 item(row, 2)->setText(QString::number(pose(0, 3), format, precision));
138 item(row, 3)->setText(QString::number(pose(1, 3), format, precision));
139 item(row, 4)->setText(QString::number(
getYawAngleDegree(pose), format, precision));
141 setSortingEnabled(
true);
145 font.setBold(vertex.attrib().highlighted);
146 for (
int col = 0; col < columnCount(); ++col)
148 auto* item = this->item(row, col);
186 if (items.size() == 0)
188 QAction* action = menu.addSection(
"No locations selected");
189 action->setEnabled(
false);
193 if (items.size() == 2)
195 menu.addSection(
"Selected pair of locations");
198 std::sort(items.begin(),
200 [](QTableWidgetItem* first, QTableWidgetItem* second)
201 { return _nameOf(first) < _nameOf(second); });
202 QTableWidgetItem* first = items[0];
203 QTableWidgetItem* second = items[1];
205 connect(menu.addAction(
"Add edge '" + _nameOf(first) +
"' " +
utils::arrowRight +
" '" +
206 _nameOf(second) +
"'"),
209 connect(menu.addAction(
"Add edge '" + _nameOf(first) +
"' " +
utils::arrowLeft +
" '" +
210 _nameOf(second) +
"'"),
213 connect(menu.addAction(
"Add edges '" + _nameOf(first) +
"' " +
utils::arrowBoth +
" '" +
214 _nameOf(second) +
"'"),
216 [
this, first, second]()
221 if (items.size() > 0)
223 QString edges = items.size() == 1 ?
"edge" :
"edges";
224 QString desc = items.size() == 1 ?
"'" + _nameOf(items[0]) +
"'"
225 : QString::number(items.size()) +
" locations";
227 if (items.size() == 1)
230 menu.addSection(
"Selected single location " + desc);
234 menu.addSection(
"Selected bulk of " + desc);
237 using Item = QTableWidgetItem;
238 using ListOfEdges = QList<QPair<Item*, Item*>>;
240 std::function<void(ListOfEdges & edges, Item * selected, Item * action)>;
242 auto addBulkAddEdgeActions = [
this, &items](QMenu* submenu, AppendFunc appendFunc)
244 if (items.size() == rowCount())
246 QAction* a = submenu->addAction(
"No other locations");
247 a->setDisabled(
true);
249 for (
int row = 0; row < rowCount(); ++row)
251 QTableWidgetItem* action = this->item(row, 0);
252 if (items.count(action) == 0)
254 QAction* a = submenu->addAction(_nameOf(action));
258 [
this, items, action, appendFunc]()
260 QList<QPair<QTableWidgetItem*, QTableWidgetItem*>> edges;
261 for (
auto* selected : items)
263 appendFunc(edges, selected, action);
271 addBulkAddEdgeActions(
273 [](ListOfEdges& edges, Item* selected, Item* action)
274 { edges.append(QPair{selected, action}); });
275 addBulkAddEdgeActions(
276 menu.addMenu(
"Add " + edges +
" " + desc +
" " +
utils::arrowLeft +
" ..."),
277 [](ListOfEdges& edges, Item* selected, Item* action)
278 { edges.append(QPair{action, selected}); });
279 addBulkAddEdgeActions(
280 menu.addMenu(
"Add " + edges +
" " + desc +
" " +
utils::arrowBoth +
" ..."),
281 [](ListOfEdges& edges, Item* selected, Item* action)
283 edges.append(QPair{selected, action});
284 edges.append(QPair{action, selected});
288 auto connectBulkRemoveEdgeAction =
289 [
this, &items](QAction* action, utils::EdgeDirection edgeDirection)
294 [
this, items, edgeDirection]()
295 { emit edgeRemovalRequested(items, edgeDirection); });
298 connectBulkRemoveEdgeAction(
299 menu.addAction(
"Remove all edges " + utils::arrowRight +
" " + desc),
300 utils::EdgeDirection::To);
301 connectBulkRemoveEdgeAction(
302 menu.addAction(
"Remove all edges " + utils::arrowLeft +
" " + desc),
303 utils::EdgeDirection::From);
304 connectBulkRemoveEdgeAction(
305 menu.addAction(
"Remove all edges " + utils::arrowBoth +
" " + desc),
306 utils::EdgeDirection::Bidirectional);
310 menu.addSection(
"Manage Locations");
311 connect(menu.addAction(
"Create new location ..."),
314 [
this]() { emit newVertexRequested(); });
316 menu.exec(mapToGlobal(pos));