25 #include <QHeaderView>
38 QStringList columns{
"Name",
"X [mm]",
"Y [mm]",
"Yaw [\u00b0]"};
39 setColumnCount(columns.size());
40 setHorizontalHeaderLabels(columns);
41 horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
42 horizontalHeader()->setVisible(
true);
44 setEditTriggers(QAbstractItemView::NoEditTriggers);
45 setSortingEnabled(
true);
47 setAlternatingRowColors(
true);
53 setContextMenuPolicy(Qt::CustomContextMenu);
61 setSortingEnabled(
false);
63 QTableWidgetItem* result =
nullptr;
68 for (
int col = 0; col < 4; ++col)
71 QTableWidgetItem* item =
new QTableWidgetItem{};
72 setItem(row, col, item);
76 item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
86 setSortingEnabled(
true);
97 const int precision = 2;
100 setSortingEnabled(
false);
103 int row = this->row(vertex.attrib().tableWidgetItem);
105 QString displayName = QString::fromStdString(vertex.attrib().getName());
106 if (vertex.attrib().changed)
110 item(row, 0)->setText(displayName);
111 item(row, 0)->setData(Qt::UserRole, QString::fromStdString(vertex.attrib().getName()));
112 item(row, 1)->setText(QString::number(pose(0, 3), format, precision));
113 item(row, 2)->setText(QString::number(pose(1, 3), format, precision));
114 item(row, 3)->setText(QString::number(
getYawAngleDegree(pose), format, precision));
116 setSortingEnabled(
true);
120 font.setBold(vertex.attrib().highlighted);
121 for (
int col = 0; col < 4; ++col)
123 auto* item = this->item(row, col);
126 item->setData(Qt::BackgroundRole, bgColor);
134 if (currentItem() == vertex.attrib().tableWidgetItem)
136 setCurrentItem(
nullptr);
139 removeRow(row(vertex.attrib().tableWidgetItem));
140 vertex.attrib().tableWidgetItem =
nullptr;
143 QList<QTableWidgetItem*>
150 VertexTableWidget::_nameOf(QTableWidgetItem* item)
152 return item->data(Qt::UserRole).toString();
161 if (items.size() == 0)
163 QAction* action = menu.addSection(
"No locations selected");
164 action->setEnabled(
false);
168 if (items.size() == 2)
170 menu.addSection(
"Selected pair of locations");
173 std::sort(items.begin(),
175 [](QTableWidgetItem* first, QTableWidgetItem* second)
176 { return _nameOf(first) < _nameOf(second); });
177 QTableWidgetItem* first = items[0];
178 QTableWidgetItem* second = items[1];
180 connect(menu.addAction(
"Add edge '" + _nameOf(first) +
"' " +
utils::arrowRight +
" '" +
181 _nameOf(second) +
"'"),
183 [
this, first, second]() {
186 connect(menu.addAction(
"Add edge '" + _nameOf(first) +
"' " +
utils::arrowLeft +
" '" +
187 _nameOf(second) +
"'"),
189 [
this, first, second]() {
192 connect(menu.addAction(
"Add edges '" + _nameOf(first) +
"' " +
utils::arrowBoth +
" '" +
193 _nameOf(second) +
"'"),
195 [
this, first, second]() {
201 if (items.size() > 0)
203 QString edges = items.size() == 1 ?
"edge" :
"edges";
204 QString desc = items.size() == 1 ?
"'" + _nameOf(items[0]) +
"'"
205 : QString::number(items.size()) +
" locations";
207 if (items.size() == 1)
210 menu.addSection(
"Selected single location " + desc);
214 menu.addSection(
"Selected bulk of " + desc);
217 using Item = QTableWidgetItem;
218 using ListOfEdges = QList<QPair<Item*, Item*>>;
220 std::function<void(ListOfEdges & edges, Item * selected, Item * action)>;
222 auto addBulkAddEdgeActions = [
this, &items](QMenu* submenu, AppendFunc appendFunc)
224 if (items.size() == rowCount())
226 QAction*
a = submenu->addAction(
"No other locations");
227 a->setDisabled(
true);
229 for (
int row = 0; row < rowCount(); ++row)
231 QTableWidgetItem* action = this->item(row, 0);
232 if (items.count(action) == 0)
234 QAction*
a = submenu->addAction(_nameOf(action));
238 [
this, items, action, appendFunc]()
240 QList<QPair<QTableWidgetItem*, QTableWidgetItem*>> edges;
241 for (
auto* selected : items)
243 appendFunc(edges, selected, action);
251 addBulkAddEdgeActions(
253 [](ListOfEdges& edges, Item* selected, Item* action) {
254 edges.append(QPair{selected, action});
256 addBulkAddEdgeActions(
257 menu.addMenu(
"Add " + edges +
" " + desc +
" " +
utils::arrowLeft +
" ..."),
258 [](ListOfEdges& edges, Item* selected, Item* action) {
259 edges.append(QPair{action, selected});
261 addBulkAddEdgeActions(
262 menu.addMenu(
"Add " + edges +
" " + desc +
" " +
utils::arrowBoth +
" ..."),
263 [](ListOfEdges& edges, Item* selected, Item* action)
265 edges.append(QPair{selected, action});
266 edges.append(QPair{action, selected});
270 auto connectBulkRemoveEdgeAction =
276 [
this, items, edgeDirection]()
277 { emit edgeRemovalRequested(items, edgeDirection); });
280 connectBulkRemoveEdgeAction(
282 utils::EdgeDirection::To);
283 connectBulkRemoveEdgeAction(
285 utils::EdgeDirection::From);
286 connectBulkRemoveEdgeAction(
288 utils::EdgeDirection::Bidirectional);
292 menu.addSection(
"Manage Locations");
293 connect(menu.addAction(
"Create new location ..."),
296 [
this]() { emit newVertexRequested(); });
298 menu.exec(mapToGlobal(pos));