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