TimestampInput.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package RobotAPI::armem::gui
17 * @author phesch ( ulila at student dot kit dot edu )
18 * @date 2022
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#include "TimestampInput.h"
24
25#include <QDateTimeEdit>
26#include <QHBoxLayout>
27#include <QLabel>
28
30
31namespace armarx::armem::gui
32{
34 dateTime(new QDateTimeEdit(QDateTime::currentDateTime())),
35 microseconds(new armarx::gui::LeadingZeroSpinBox(6, 10))
36 {
37 dateTime->setDisplayFormat("yyyy-MM-dd HH:mm:ss");
38 microseconds->setRange(0, 1000 * 1000 - 1);
39 microseconds->setSingleStep(1);
40 // This cast is safe because 999 * 1000 < MAX_INT.
41 microseconds->setValue(
42 static_cast<int>((QDateTime::currentMSecsSinceEpoch() % 1000) * 1000));
43 microseconds->setSuffix(" µs");
44
45 auto* hlayout = new QHBoxLayout();
46 // hlayout->addWidget(new QLabel("Time"));
47 hlayout->addWidget(dateTime);
48 hlayout->addWidget(new QLabel("."));
49 hlayout->addWidget(microseconds);
50 setLayout(hlayout);
51 }
52
55 {
56 return {Duration::MilliSeconds(dateTime->dateTime().toMSecsSinceEpoch()) +
57 Duration::MicroSeconds(microseconds->value())};
58 }
59
60 RelativeTimestampInput::RelativeTimestampInput() : seconds(new QDoubleSpinBox())
61 {
62 seconds->setDecimals(6);
63 seconds->setSingleStep(0.1);
64 seconds->setRange(-1e6, 1e6);
65 seconds->setSuffix(" s");
66 seconds->setValue(0);
67
68 auto* hlayout = new QHBoxLayout();
69 // hlayout->addWidget(new QLabel("Seconds"));
70 hlayout->addWidget(seconds);
71 setLayout(hlayout);
72 }
73
79} // namespace armarx::armem::gui
std::string currentDateTime()
static DateTime Now()
Definition DateTime.cpp:51
armarx::DateTime retrieveTimeStamp() override
armarx::DateTime retrieveTimeStamp() override
Represents a point in time.
Definition DateTime.h:25
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition Duration.cpp:24
static Duration SecondsDouble(double seconds)
Constructs a duration in seconds.
Definition Duration.cpp:78
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition Duration.cpp:48
This file offers overloads of toIce() and fromIce() functions for STL container types.