33 ui->treeWidget->setColumnCount(8);
34 QTreeWidgetItem* head =
ui->treeWidget->headerItem();
39 head->setText(
idxAct,
"Act");
40 head->setText(
idxReq,
"Req");
41 head->setText(
idxType,
"Target Type");
42 head->setText(
idxVal,
"Target Value");
44 head->setToolTip(
idxName,
"The control device's name (green: ok, red: missmatch between requested and active mode, orange: active/requested device not found in the displayed list)");
45 head->setToolTip(
idxTags,
"The control device's tags");
46 head->setToolTip(
idxMode,
"The control device's control mode");
47 head->setToolTip(
idxHWMode,
"The control device's hardware control mode");
48 head->setToolTip(
idxAct,
"Whether the control mode is active (green: ok, red: missmatch between requested and active mode)");
49 head->setToolTip(
idxReq,
"Whether the control mode is requested (green: ok, red: missmatch between requested and active mode)");
50 head->setToolTip(
idxType,
"The control mode's target type");
51 head->setToolTip(
idxVal,
"The control mode's target value");
53 ui->treeWidget->setColumnWidth(
idxName, 150);
54 ui->treeWidget->setColumnWidth(
idxTags, 100);
55 ui->treeWidget->setColumnWidth(
idxMode, 225);
57 ui->treeWidget->setColumnWidth(
idxAct, 40);
58 ui->treeWidget->setColumnWidth(
idxReq, 40);
59 ui->treeWidget->setColumnWidth(
idxType, 350);
60 ui->treeWidget->header()->setResizeMode(
idxAct, QHeaderView::Fixed);
61 ui->treeWidget->header()->setResizeMode(
idxReq, QHeaderView::Fixed);
71 std::unique_lock<std::recursive_timed_mutex> guard {
mutex, std::defer_lock};
72 if (!guard.try_lock_for(std::chrono::microseconds(100)))
76 for (
const auto&
status : allStatus)
78 if (statusUpdates[
status.deviceName].timestampUSec <
status.timestampUSec)
83 QMetaObject::invokeMethod(
this,
"updateContent", Qt::QueuedConnection);
92 statusUpdates.clear();
98 for (
const auto& pair : statusUpdates)
102 statusUpdates.clear();
107 auto temp =
robotUnit->getControlDeviceDescriptions();
109 std::unique_lock<std::recursive_timed_mutex> guard {
mutex};
110 resetData = std::move(temp);
116 if (resetData.empty())
120 add(resetData.back());
121 resetData.pop_back();
125 void ControlDevicesWidget::add(
const ControlDeviceDescription& desc)
127 std::unique_lock<std::recursive_timed_mutex> guard {
mutex};
128 if (entries.count(desc.deviceName))
132 entries[desc.deviceName] =
new ControlDevicesWidgetEntry(*
this, *(
ui->treeWidget), desc);
135 void ControlDevicesWidget::update(
const ControlDeviceStatus&
status)
137 std::unique_lock<std::recursive_timed_mutex> guard {
mutex};
142 if (!entries.count(
status.deviceName))
152 header =
new QTreeWidgetItem;
153 treeWidget.addTopLevelItem(header);
157 QCheckBox* boxTags =
new QCheckBox{QString::number(desc.tags.size()) +
" Tags"};
160 boxTags->setChecked(
false);
161 connect(boxTags, SIGNAL(clicked(
bool)),
this, SLOT(hideTagList(
bool)));
162 for (
const auto& tag : desc.tags)
164 QTreeWidgetItem* child =
new QTreeWidgetItem {{QString::fromStdString(tag)}};
165 treeWidget.addTopLevelItem(child);
166 tags.emplace_back(child);
169 for (
const auto& nameToType : desc.contolModeToTargetType)
171 ControllerEntry& subEntry = subEntries[nameToType.first];
172 subEntry.child =
new QTreeWidgetItem;
173 header->addChild(subEntry.child);
179 subEntry.value =
new VariantWidget;
187 bool newDevsNotFound =
false;
188 if (activeMode !=
status.activeControlMode)
190 if (subEntries.count(activeMode))
195 activeMode =
status.activeControlMode;
196 if (subEntries.count(activeMode))
198 newDevsNotFound =
true;
202 if (requestedMode !=
status.requestedControlMode)
204 if (subEntries.count(requestedMode))
209 requestedMode =
status.requestedControlMode;
210 if (subEntries.count(requestedMode))
212 newDevsNotFound =
true;
219 if (subEntries.count(requestedMode))
223 if (subEntries.count(activeMode))
229 for (
const auto& pair :
status.controlTargetValues)
231 if (subEntries.count(pair.first))
233 subEntries.at(pair.first).value->update(pair.second);
234 subEntries.at(pair.first).value->layout()->setContentsMargins(0, 0, 0, 0);
246 for (
const auto& tagit : tags)
258 std::set<QTreeWidgetItem*> hits;
259 for (
const auto& pair : subEntries)
263 hits.emplace(pair.second.child);
271 std::set<QTreeWidgetItem*> hits;
272 for (
const auto& pair : subEntries)
276 hits.emplace(pair.second.child);
284 std::set<QTreeWidgetItem*> hits;
285 for (
const auto& pair : subEntries)
289 hits.emplace(pair.second.child);
297 std::set<QTreeWidgetItem*> hits;
298 for (
const auto& pair : subEntries)
302 hits.emplace(pair.second.child);
314 header->setHidden(!vis);
319 for (
const auto& pair : subEntries)
321 if (children.count(pair.second.child))
323 pair.second.child->setHidden(!vis);
327 pair.second.child->setHidden(vis);
332 void ControlDevicesWidgetEntry::hideTagList(
bool hide)
334 for (QTreeWidgetItem* tag : tags)
336 tag->setHidden(hide);