SnapshotForm.cpp
Go to the documentation of this file.
1 #include "SnapshotForm.h"
2 
3 #include <QCheckBox>
4 #include <QComboBox>
5 #include <QDateTimeEdit>
6 #include <QFormLayout>
7 #include <QGridLayout>
8 #include <QHBoxLayout>
9 #include <QLabel>
10 #include <QSpinBox>
11 #include <QVBoxLayout>
12 
14 
19 
20 namespace armarx::armem::gui
21 {
22 
23  client::query::SnapshotSelector
25  {
28  return s;
29  }
30 
31  void
33  {
34  dt->setDisplayFormat("yyyy-MM-dd HH:mm:ss");
35  }
36 
38  {
39  }
40 
41  void
43  {
44  selector.all();
45  }
46 
48  {
49  const QDateTime now = QDateTime::currentDateTime();
50 
51  label = new QLabel("Timestamp:");
52 
53  dateTime = new QDateTimeEdit(now);
54  dateTime->setDisabled(true);
55  setDateTimeDisplayFormat(dateTime);
56 
57  microseconds = new armarx::gui::LeadingZeroSpinBox(6, 10);
58  microseconds->setDisabled(true);
59  microseconds->setMinimum(0);
60  microseconds->setMaximum(1000 * 1000 - 1);
61  microseconds->setSingleStep(1);
62  microseconds->setValue(static_cast<int>(now.toMSecsSinceEpoch() % 1000) * 1000);
63 
64  QHBoxLayout* timestampLayout = new QHBoxLayout();
65  timestampLayout->addWidget(dateTime);
66  timestampLayout->addWidget(microseconds);
67 
68  latest = new QCheckBox("Latest");
69  latest->setChecked(true);
70 
71  QGridLayout* layout = new QGridLayout(this);
72  layout->addWidget(label, 0, 0);
73  layout->addLayout(timestampLayout, 0, 1);
74  layout->addWidget(latest, 0, 2);
75 
76  connect(latest, &QCheckBox::toggled, dateTime, &QDateTimeEdit::setDisabled);
77  connect(latest, &QCheckBox::toggled, microseconds, &QSpinBox::setDisabled);
78 
79  connect(dateTime, &QDateTimeEdit::dateTimeChanged, this, &SnapshotForm::queryChanged);
80  connect(microseconds,
81  QOverload<int>::of(&QSpinBox::valueChanged),
82  this,
84  connect(latest, &QCheckBox::toggled, this, &SnapshotForm::queryChanged);
85  }
86 
87  void
89  {
90  const Time time = latest->isChecked()
91  ? Time::Invalid()
92  : (Time(Duration::Seconds(dateTime->dateTime().toSecsSinceEpoch())) +
93  Duration::MicroSeconds(microseconds->value()));
94  selector.atTime(time);
95  }
96 
98  {
99  const QDateTime now = QDateTime::currentDateTime();
100 
101  fromLabel = new QLabel("From:");
102 
103  fromDateTime = new QDateTimeEdit(now.addSecs(-60));
104  fromDateTime->setDisabled(true);
106 
107  fromBegin = new QCheckBox("Begin");
108  fromBegin->setChecked(true);
109 
110  toLabel = new QLabel("To:");
111 
112  toDateTime = new QDateTimeEdit(now.addSecs(60));
113  toDateTime->setDisabled(true);
115 
116  toEnd = new QCheckBox("End");
117  toEnd->setChecked(true);
118 
119  QGridLayout* layout = new QGridLayout(this);
120  int row = 0;
121 
122  layout->addWidget(fromLabel, row, 0);
123  layout->addWidget(fromDateTime, row, 1);
124  layout->addWidget(fromBegin, row, 2);
125  ++row;
126 
127  layout->addWidget(toLabel, row, 0);
128  layout->addWidget(toDateTime, row, 1);
129  layout->addWidget(toEnd, row, 2);
130  ++row;
131 
132  connect(fromBegin, &QCheckBox::toggled, fromDateTime, &QDateTimeEdit::setDisabled);
133  connect(toEnd, &QCheckBox::toggled, toDateTime, &QDateTimeEdit::setDisabled);
134 
135  connect(fromBegin, &QCheckBox::toggled, this, &SnapshotForm::queryChanged);
136  connect(fromDateTime, &QDateTimeEdit::dateTimeChanged, this, &SnapshotForm::queryChanged);
137  connect(toEnd, &QCheckBox::toggled, this, &SnapshotForm::queryChanged);
138  connect(toDateTime, &QDateTimeEdit::dateTimeChanged, this, &SnapshotForm::queryChanged);
139  }
140 
141  void
143  {
144  Time defaults = Time::Invalid();
145  Time min = defaults, max = defaults;
146 
147  if (!fromBegin->isChecked())
148  {
149  min = Time(Duration::MilliSeconds(fromDateTime->dateTime().toMSecsSinceEpoch()));
150  }
151  if (!toEnd->isChecked())
152  {
153  max = Time(Duration::MilliSeconds(toDateTime->dateTime().toMSecsSinceEpoch())) +
154  Duration::MicroSeconds(int(1e6) - 1);
155  }
156 
157  selector.timeRange(min, max);
158  }
159 
161  {
162  firstLabel = new QLabel("First:");
163  firstSpinBox = new QSpinBox();
164  firstBegin = new QCheckBox("Begin");
165 
166  firstBegin->setChecked(false);
167  firstSpinBox->setDisabled(firstBegin->isChecked());
168 
169  lastLabel = new QLabel("To:");
170  lastSpinBox = new QSpinBox();
171  lastEnd = new QCheckBox("End");
172 
173  lastEnd->setChecked(true);
174  lastSpinBox->setDisabled(lastEnd->isChecked());
175 
176  std::initializer_list<QSpinBox*> sbs{firstSpinBox, lastSpinBox};
177  for (QSpinBox* sb : sbs)
178  {
179  sb->setMinimum(-1000);
180  sb->setMaximum(1000);
181  }
182  firstSpinBox->setValue(-2);
183  lastSpinBox->setValue(-1);
184 
185  QString tooltip =
186  "Python index semantics: Negative indices count from the end (-1 is the last entry).";
187  firstSpinBox->setToolTip(tooltip);
188  lastSpinBox->setToolTip(tooltip);
189 
190 
191  QGridLayout* layout = new QGridLayout(this);
192  int row = 0;
193 
194  layout->addWidget(firstLabel, row, 0);
195  layout->addWidget(firstSpinBox, row, 1);
196  layout->addWidget(firstBegin, row, 2);
197  ++row;
198 
199  layout->addWidget(lastLabel, row, 0);
200  layout->addWidget(lastSpinBox, row, 1);
201  layout->addWidget(lastEnd, row, 2);
202  ++row;
203 
204  connect(firstBegin, &QCheckBox::toggled, firstSpinBox, &QSpinBox::setDisabled);
205  connect(lastEnd, &QCheckBox::toggled, lastSpinBox, &QSpinBox::setDisabled);
206 
207  connect(firstBegin, &QCheckBox::toggled, this, &SnapshotForm::queryChanged);
208  connect(firstSpinBox,
209  QOverload<int>::of(&QSpinBox::valueChanged),
210  this,
212  connect(lastEnd, &QCheckBox::toggled, this, &SnapshotForm::queryChanged);
213  connect(lastSpinBox,
214  QOverload<int>::of(&QSpinBox::valueChanged),
215  this,
217  }
218 
219  void
221  {
222  long first = 0, last = -1;
223 
224  if (!firstBegin->isChecked())
225  {
226  first = firstSpinBox->value();
227  }
228  if (!lastEnd->isChecked())
229  {
230  last = lastSpinBox->value();
231  }
232 
233  selector.indexRange(first, last);
234  }
235 
236 } // namespace armarx::armem::gui
armarx::armem::gui::SnapshotFormTimeRange::toLabel
QLabel * toLabel
Definition: SnapshotForm.h:69
armarx::armem::gui::SnapshotFormSingle::SnapshotFormSingle
SnapshotFormSingle()
Definition: SnapshotForm.cpp:47
armarx::armem::client::query::SnapshotSelector::timeRange
SnapshotSelector & timeRange(Time min, Time max)
Definition: selectors.cpp:46
armarx::armem::gui::SnapshotForm::queryChanged
void queryChanged()
armarx::armem::gui::SnapshotFormAll::SnapshotFormAll
SnapshotFormAll()
Definition: SnapshotForm.cpp:37
armarx::armem::gui::SnapshotFormSingle::fillEntitySelector
void fillEntitySelector(client::query::SnapshotSelector &selector) override
Definition: SnapshotForm.cpp:88
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:297
armarx::armem::client::query::SnapshotSelector::all
SnapshotSelector & all() override
Definition: selectors.cpp:22
armarx::armem::gui::SnapshotFormIndexRange::firstSpinBox
QSpinBox * firstSpinBox
Definition: SnapshotForm.h:83
armarx::armem::gui::SnapshotFormIndexRange::lastLabel
QLabel * lastLabel
Definition: SnapshotForm.h:86
armarx::armem::client::query::SnapshotSelector
Definition: selectors.h:11
SnapshotForm.h
currentDateTime
std::string currentDateTime()
Definition: XMLScenarioParser.cpp:59
armarx::armem::gui::SnapshotFormIndexRange::lastEnd
QCheckBox * lastEnd
Definition: SnapshotForm.h:88
armarx::core::time::Duration::Seconds
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
Definition: Duration.cpp:72
armarx::armem::gui::SnapshotFormTimeRange::SnapshotFormTimeRange
SnapshotFormTimeRange()
Definition: SnapshotForm.cpp:97
armarx::armem::gui::SnapshotFormTimeRange::fillEntitySelector
void fillEntitySelector(client::query::SnapshotSelector &selector) override
Definition: SnapshotForm.cpp:142
armarx::armem::gui::SnapshotFormIndexRange::lastSpinBox
QSpinBox * lastSpinBox
Definition: SnapshotForm.h:87
armarx::armem::gui::SnapshotFormIndexRange::fillEntitySelector
void fillEntitySelector(client::query::SnapshotSelector &selector) override
Definition: SnapshotForm.cpp:220
ice_conversions.h
armarx::armem::gui::SnapshotFormTimeRange::fromDateTime
QDateTimeEdit * fromDateTime
Definition: SnapshotForm.h:66
armarx::armem::gui::SnapshotFormTimeRange::toEnd
QCheckBox * toEnd
Definition: SnapshotForm.h:71
armarx::armem::gui::SnapshotFormTimeRange::fromBegin
QCheckBox * fromBegin
Definition: SnapshotForm.h:67
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::armem::gui::SnapshotFormAll::fillEntitySelector
void fillEntitySelector(client::query::SnapshotSelector &selector) override
Definition: SnapshotForm.cpp:42
ExpressionException.h
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::gui::LeadingZeroSpinBox
Definition: gui_utils.h:59
armarx::armem::client::query::SnapshotSelector::atTime
SnapshotSelector & atTime(Time timestamp)
Definition: selectors.cpp:38
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:327
armarx::armem::gui
Definition: ActionsMenuBuilder.cpp:5
armarx::armem::gui::SnapshotFormTimeRange::fromLabel
QLabel * fromLabel
Definition: SnapshotForm.h:65
Time.h
Builder.h
armarx::armem::gui::SnapshotForm::makeEntitySelector
virtual client::query::SnapshotSelector makeEntitySelector()
Definition: SnapshotForm.cpp:24
armarx::armem::gui::SnapshotForm::fillEntitySelector
virtual void fillEntitySelector(client::query::SnapshotSelector &selector)=0
armarx::armem::gui::SnapshotFormIndexRange::SnapshotFormIndexRange
SnapshotFormIndexRange()
Definition: SnapshotForm.cpp:160
armarx::armem::gui::SnapshotForm::setDateTimeDisplayFormat
void setDateTimeDisplayFormat(QDateTimeEdit *dt)
Definition: SnapshotForm.cpp:32
armarx::armem::gui::SnapshotFormIndexRange::firstLabel
QLabel * firstLabel
Definition: SnapshotForm.h:82
armarx::core::time::Duration::MicroSeconds
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition: Duration.cpp:24
armarx::armem::client::query::SnapshotSelector::indexRange
SnapshotSelector & indexRange(long first, long last)
Definition: selectors.cpp:64
armarx::armem::gui::SnapshotFormIndexRange::firstBegin
QCheckBox * firstBegin
Definition: SnapshotForm.h:84
armarx::armem::gui::SnapshotFormTimeRange::toDateTime
QDateTimeEdit * toDateTime
Definition: SnapshotForm.h:70
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::core::time::DateTime::Invalid
static DateTime Invalid()
Definition: DateTime.cpp:57
gui_utils.h
dt
constexpr T dt
Definition: UnscentedKalmanFilterTest.cpp:45
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:48