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
20namespace armarx::armem::gui
21{
22
23 client::query::SnapshotSelector
30
31 void
33 {
34 dt->setDisplayFormat("yyyy-MM-dd HH:mm:ss");
35 }
36
40
41 void
46
48 {
49 const QDateTime now = QDateTime::currentDateTime();
50
51 label = new QLabel("Timestamp:");
52
53 dateTime = new QDateTimeEdit(now);
54 dateTime->setDisabled(true);
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()
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
constexpr T dt
SnapshotSelector & indexRange(long first, long last)
Definition selectors.cpp:64
SnapshotSelector & atTime(Time timestamp)
Definition selectors.cpp:38
SnapshotSelector & timeRange(Time min, Time max)
Definition selectors.cpp:46
void fillEntitySelector(client::query::SnapshotSelector &selector) override
void fillEntitySelector(client::query::SnapshotSelector &selector) override
void fillEntitySelector(client::query::SnapshotSelector &selector) override
void fillEntitySelector(client::query::SnapshotSelector &selector) override
virtual client::query::SnapshotSelector makeEntitySelector()
virtual void fillEntitySelector(client::query::SnapshotSelector &selector)=0
void setDateTimeDisplayFormat(QDateTimeEdit *dt)
static DateTime Invalid()
Definition DateTime.cpp:57
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition Duration.cpp:24
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
Definition Duration.cpp:72
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition Duration.cpp:48
armarx::core::time::DateTime Time
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)