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 
31 namespace 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 
76  {
77  return DateTime::Now() + Duration::SecondsDouble(seconds->value());
78  }
79 } // namespace armarx::armem::gui
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::armem::gui::AbsoluteTimestampInput::retrieveTimeStamp
armarx::DateTime retrieveTimeStamp() override
Definition: TimestampInput.cpp:54
currentDateTime
std::string currentDateTime()
Definition: XMLScenarioParser.cpp:60
armarx::armem::gui::AbsoluteTimestampInput::AbsoluteTimestampInput
AbsoluteTimestampInput()
Definition: TimestampInput.cpp:33
armarx::armem::gui::RelativeTimestampInput::retrieveTimeStamp
armarx::DateTime retrieveTimeStamp() override
Definition: TimestampInput.cpp:75
armarx::core::time::Duration::SecondsDouble
static Duration SecondsDouble(double seconds)
Constructs a duration in seconds.
Definition: Duration.cpp:90
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::gui
Definition: ActionsMenuBuilder.cpp:6
armarx::armem::gui::RelativeTimestampInput::RelativeTimestampInput
RelativeTimestampInput()
Definition: TimestampInput.cpp:60
armarx::core::time::Duration::MicroSeconds
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition: Duration.cpp:27
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
gui_utils.h
TimestampInput.h
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55