QueryWidget.cpp
Go to the documentation of this file.
1 #include "QueryWidget.h"
2 
3 #include <limits>
4 #include <mutex>
5 
6 #include <QCheckBox>
7 #include <QGroupBox>
8 #include <QHBoxLayout>
9 #include <QLabel>
10 #include <QLineEdit>
11 #include <QPushButton>
12 #include <QScrollArea>
13 #include <QSpinBox>
14 #include <QTabWidget>
15 #include <QVBoxLayout>
16 #include <QWidget>
17 
19 
20 namespace armarx::armem::gui
21 {
22 
24  {
25  auto* vlayout = new QVBoxLayout();
26  auto* hlayout = new QHBoxLayout();
27 
28  {
29  _availableMemoriesGroupBox = new QGroupBox("Available memories");
30  auto vboxlayout = new QVBoxLayout();
31  vboxlayout->setMargin(1);
32  vboxlayout->setSizeConstraint(QLayout::SizeConstraint::SetMinAndMaxSize);
33  vboxlayout->setAlignment(Qt::AlignTop);
34  _availableMemoriesGroupBox->setLayout(vboxlayout);
35  hlayout->addWidget(_availableMemoriesGroupBox);
36  }
37 
38  QFrame* vFrame = new QFrame;
39  vFrame->setFrameShape(QFrame::VLine);
40  hlayout->addWidget(vFrame);
41 
42  {
43  _additionalSettingsGroupBox = new QGroupBox("Additional query settings");
44  auto vboxlayout = new QVBoxLayout();
45  vboxlayout->setMargin(1);
46  vboxlayout->setSizeConstraint(QLayout::SizeConstraint::SetMinAndMaxSize);
47  vboxlayout->setAlignment(Qt::AlignTop);
48  _additionalSettingsGroupBox->setLayout(vboxlayout);
49 
50  _dataCheckBox = new QCheckBox("Get Data");
51  _dataCheckBox->setChecked(true);
52  vboxlayout->addWidget(_dataCheckBox);
53 
54  _dropRemovedCheckBox = new QCheckBox("Drop disconnected memories");
55  _dropRemovedCheckBox->setChecked(true);
56  vboxlayout->addWidget(_dropRemovedCheckBox);
57 
58  _dropDisabledCheckBox = new QCheckBox("Drop disabled memories");
59  _dropDisabledCheckBox->setChecked(false);
60  vboxlayout->addWidget(_dropDisabledCheckBox);
61 
62  auto* recDepthHLayout = new QHBoxLayout();
63  _recursionDepthLabel = new QLabel("Link resolution depth:");
64  recDepthHLayout->addWidget(_recursionDepthLabel);
65  _recursionDepthLabel->setFixedWidth(200);
66 
67  _recursionDepthSpinner = new QSpinBox(); // NOLINT
68  _recursionDepthSpinner->setRange(-1, std::numeric_limits<int>::max());
69  _recursionDepthSpinner->setValue(0);
70  _recursionDepthSpinner->setEnabled(_dataCheckBox->isChecked());
71  _recursionDepthSpinner->setSpecialValueText(QString("Unlimited"));
72  recDepthHLayout->addWidget(_recursionDepthSpinner);
73  recDepthHLayout->addStretch();
74  vboxlayout->addLayout(recDepthHLayout);
75 
76  /*
77  auto* exportPathHLayout = new QHBoxLayout();
78  _exportPathLabel = new QLabel("Export path:");
79  exportPathHLayout->addWidget(_exportPathLabel);
80  _exportPathLabel->setFixedWidth(200);
81 
82  _exportPathLineEdit = new QLineEdit();
83  exportPathHLayout->addWidget(_exportPathLineEdit);
84  exportPathHLayout->setStretchFactor(_exportPathLineEdit, 4);
85 
86  _exportPathConfirmButton = new QPushButton("Confirm Path");
87  exportPathHLayout->addWidget(_exportPathConfirmButton);
88  _exportPathConfirmButton->setFixedWidth(100);
89  vboxlayout->addLayout(exportPathHLayout);
90 
91  auto* exportNameHLayout = new QHBoxLayout();
92  _exportNameLabel = new QLabel("Export name:");
93  exportNameHLayout->addWidget(_exportNameLabel);
94  _exportNameLabel->setFixedWidth(200);
95 
96  _exportNameLineEdit = new QLineEdit();
97  exportNameHLayout->addWidget(_exportNameLineEdit);
98  exportNameHLayout->setStretchFactor(_exportNameLineEdit, 4);
99 
100  _exportNameConfirmButton = new QPushButton("Confirm Name");
101  exportNameHLayout->addWidget(_exportNameConfirmButton);
102  _exportNameConfirmButton->setFixedWidth(100);
103  vboxlayout->addLayout(exportNameHLayout);
104 */
105 
106  auto ltmButtonsLayout = new QVBoxLayout();
107  _storeInLTMButton = new QPushButton("Query and store in LTM");
108  ltmButtonsLayout->addWidget(_storeInLTMButton);
109 
110  auto* ltmRecHLayout = new QHBoxLayout();
111  _startLTMRecordingButton = new QPushButton("Start LTM Recording");
112  _stopLTMRecordingButton = new QPushButton("Stop LTM Recording");
113 
114  ltmRecHLayout->addWidget(_startLTMRecordingButton);
115  ltmRecHLayout->addWidget(_stopLTMRecordingButton);
116  ltmButtonsLayout->addLayout(ltmRecHLayout);
117 
118  vboxlayout->addLayout(ltmButtonsLayout);
119 
120  hlayout->addWidget(_additionalSettingsGroupBox);
121  }
122  vlayout->addLayout(hlayout);
123 
124  // Public connections.
125  /*
126  connect(_exportPathConfirmButton, &QPushButton::pressed, this, [=]() {
127  confirmExportPath(_exportPathLineEdit->text().toStdString());
128  });
129  connect(_exportNameConfirmButton, &QPushButton::pressed, this, [=]() {
130  confirmExportPath(_exportNameLineEdit->text().toStdString());
131  });
132 */
133  connect(_storeInLTMButton, &QPushButton::pressed, this, &This::storeInLTM);
134  connect(_startLTMRecordingButton, &QPushButton::pressed, this, &This::startRecording);
135  connect(_stopLTMRecordingButton, &QPushButton::pressed, this, &This::stopRecording);
136 
137  // Private connections.
138  connect(
139  _dataCheckBox, &QCheckBox::stateChanged, this, &This::setRecursionDepthSpinnerEnabled);
140 
141  setLayout(vlayout);
142  }
143 
144  void
145  QueryWidget::update(const std::vector<std::string>& activeMemoryNames)
146  {
147  std::scoped_lock l(enabledMemoriesMutex);
148  std::vector<std::string> alreadyPresentMemoryCheckboxes;
149 
150  // get information about memories already present and activate inactive ones if necessary
151  int maxIndex = _availableMemoriesGroupBox->layout()->count();
152  for (int i = 0; i < maxIndex; ++i)
153  {
154  auto w = _availableMemoriesGroupBox->layout()->itemAt(i)->widget();
155  QCheckBox* box = static_cast<QCheckBox*>(w);
156  std::string memoryName = box->text().toStdString();
157  if (box->isEnabled() &&
158  std::find(activeMemoryNames.begin(), activeMemoryNames.end(), memoryName) ==
159  activeMemoryNames.end())
160  {
161  // checkbox is enabled but memory is not available anymore
162  box->setVisible(false);
163  box->setChecked(false);
164  box->setEnabled(false);
165  }
166  if (not(box->isEnabled()) &&
167  std::find(activeMemoryNames.begin(), activeMemoryNames.end(), memoryName) !=
168  activeMemoryNames.end())
169  {
170  // checkbox is disabled but memory is available again
171  box->setVisible(true);
172  box->setChecked(true);
173  box->setEnabled(true);
174  }
175  alreadyPresentMemoryCheckboxes.push_back(memoryName);
176  }
177 
178  // Add checkboxes for new memories
179  for (const auto& memoryName : activeMemoryNames)
180  {
181  if (std::find(alreadyPresentMemoryCheckboxes.begin(),
182  alreadyPresentMemoryCheckboxes.end(),
183  memoryName) == alreadyPresentMemoryCheckboxes.end())
184  {
185  // new memory available
186  auto box = new QCheckBox(QString::fromStdString(memoryName));
187  box->setChecked(true);
188  box->setVisible(true);
189  box->setEnabled(true);
190  _availableMemoriesGroupBox->layout()->addWidget(box);
191  }
192  }
193  }
194 
197  {
198  return _dataCheckBox->isChecked() ? armem::query::DataMode::WithData
200  }
201 
202  bool
204  {
205  return _dropRemovedCheckBox->isChecked();
206  }
207 
208  bool
210  {
211  return _dropDisabledCheckBox->isChecked();
212  }
213 
214  std::map<std::string, QueryWidget::ActiveMemoryState>
216  {
217  std::scoped_lock l(enabledMemoriesMutex);
218 
219  std::map<std::string, QueryWidget::ActiveMemoryState> states;
220  int maxIndex = _availableMemoriesGroupBox->layout()->count();
221  for (int i = 0; i < maxIndex; ++i)
222  {
223  auto w = _availableMemoriesGroupBox->layout()->itemAt(i)->widget();
224  QCheckBox* box = static_cast<QCheckBox*>(w);
225  std::string memoryName = box->text().toStdString();
226  if (box->isEnabled() && box->isChecked())
227  {
229  }
230  else if (box->isEnabled() && !box->isChecked())
231  {
233  }
234  else
235  {
237  }
238  }
239  return states;
240  }
241 
242  std::vector<std::string>
244  {
245  std::scoped_lock l(enabledMemoriesMutex);
246 
247  std::vector<std::string> enabledMemoryCheckboxes;
248  int maxIndex = _availableMemoriesGroupBox->layout()->count();
249  for (int i = 0; i < maxIndex; ++i)
250  {
251  auto w = _availableMemoriesGroupBox->layout()->itemAt(i)->widget();
252  QCheckBox* box = static_cast<QCheckBox*>(w);
253  std::string memoryName = box->text().toStdString();
254  if (box->isEnabled() && box->isChecked())
255  {
256  // Invisible ones are always unchecked if set to invisible from update method
257  enabledMemoryCheckboxes.push_back(memoryName);
258  }
259  }
260  return enabledMemoryCheckboxes;
261  }
262 
263  int
265  {
266  return _recursionDepthSpinner->value();
267  }
268 
269  void
270  QueryWidget::setRecursionDepthSpinnerEnabled(int state)
271  {
272  switch (state)
273  {
274  case Qt::Checked:
275  _recursionDepthSpinner->setEnabled(true);
276  break;
277  case Qt::Unchecked:
278  default:
279  _recursionDepthSpinner->setEnabled(false);
280  break;
281  }
282  }
283 } // namespace armarx::armem::gui
armarx::armem::gui::QueryWidget::storeInLTM
void storeInLTM()
armarx::armem::query::DataMode::WithData
@ WithData
Get structure and ARON data.
armarx::armem::gui::QueryWidget::QueryWidget
QueryWidget()
Definition: QueryWidget.cpp:23
armarx::armem::gui::QueryWidget::stopRecording
void stopRecording()
armarx::armem::gui::QueryWidget::ActiveMemoryState::NotFound
@ NotFound
armarx::armem::gui::QueryWidget::ActiveMemoryState::FoundAndNotChecked
@ FoundAndNotChecked
armarx::armem::query::DataMode
DataMode
Definition: DataMode.h:7
max
T max(T t1, T t2)
Definition: gdiam.h:48
armarx::armem::gui::QueryWidget::update
void update(const std::vector< std::string > &memoryNames)
Definition: QueryWidget.cpp:145
QueryWidget.h
ExpressionException.h
armarx::armem::gui::QueryWidget::getAvailableMemoryStates
std::map< std::string, ActiveMemoryState > getAvailableMemoryStates() const
Definition: QueryWidget.cpp:215
armarx::armem::gui::QueryWidget::startRecording
void startRecording()
armarx::armem::gui::QueryWidget::dropRemovedMemories
bool dropRemovedMemories() const
Definition: QueryWidget.cpp:203
armarx::armem::gui::QueryWidget::getEnabledMemories
std::vector< std::string > getEnabledMemories() const
Definition: QueryWidget.cpp:243
armarx::armem::gui::QueryWidget::ActiveMemoryState::FoundAndChecked
@ FoundAndChecked
armarx::armem::laser_scans::constants::memoryName
const std::string memoryName
Definition: constants.h:28
armarx::armem::gui
Definition: ActionsMenuBuilder.cpp:6
armarx::armem::query::DataMode::NoData
@ NoData
Just get the structure, but no ARON data.
armarx::armem::gui::QueryWidget::queryLinkRecursionDepth
int queryLinkRecursionDepth() const
Definition: QueryWidget.cpp:264
armarx::armem::gui::QueryWidget::dropDisabledMemories
bool dropDisabledMemories() const
Definition: QueryWidget.cpp:209
armarx::armem::gui::QueryWidget::dataMode
armem::query::DataMode dataMode() const
Definition: QueryWidget.cpp:196