FloatWidgets.h
Go to the documentation of this file.
1#pragma once
2
3#include <QDoubleSpinBox>
4
5#pragma GCC diagnostic push
6#pragma GCC diagnostic ignored "-Wpedantic"
7#include <qwt_slider.h>
8#pragma GCC diagnostic pop
9
10#include "Basic.h"
11
12namespace armarx::RemoteGui
13{
14 struct FloatSpinBoxHandler : TypedWidget<FloatSpinBox, QDoubleSpinBox, VALUE_VARIANT_FLOAT>
15 {
16 static bool
17 isValid(RemoteWidgetT const& desc, std::ostream& out)
18 {
19#define cmp_or_log(l, c, r) \
20 (l c r ? true \
21 : (out << " FAILED: " #l " " #c " " #r " " << VAROUT(l) << ", " << VAROUT(r) << '\n', \
22 false))
23 return cmp_or_log(desc.min, <=, desc.max) && cmp_or_log(desc.steps, >, 0) &&
24 cmp_or_log(desc.decimals, >=, 0);
25#undef cmp_or_log
26 }
27
28 static QWidgetT*
30 CreateWidgetCallback const& createChild,
31 const QObject* stateChangeReceiver,
32 const char* stateChangeSlot)
33 {
35 QWidgetT* widget = new QWidgetT();
36
37 widget->setToolTip(QString::fromStdString(desc.toolTip));
38 widget->setMinimum(desc.min);
39 widget->setMaximum(desc.max);
40 widget->setDecimals(desc.decimals);
41 widget->setSingleStep((desc.max - desc.min) / desc.steps);
42
43 QObject::connect(
44 widget, SIGNAL(valueChanged(double)), stateChangeReceiver, stateChangeSlot);
45
46 return widget;
47 }
48
49 static void
50 updateGui(RemoteWidgetT const& desc, QWidgetT* widget, ValueT const& value)
51 {
52 widget->setValue(value);
53 }
54
55 static ValueT
57 {
58 return widget->value();
59 }
60 };
61
62 struct FloatSliderHandler : TypedWidget<FloatSlider, QwtSlider, VALUE_VARIANT_FLOAT>
63 {
64 static bool
65 isValid(RemoteWidgetT const& desc, std::ostream& out)
66 {
67#define cmp_or_log(l, c, r) \
68 (l c r ? true \
69 : (out << " FAILED: " #l " " #c " " #r " " << VAROUT(l) << ", " << VAROUT(r) << '\n', \
70 false))
71 return cmp_or_log(desc.min, <=, desc.max) && cmp_or_log(desc.steps, >, 0);
72#undef cmp_or_log
73 }
74
75 static QWidgetT*
77 CreateWidgetCallback const& createChild,
78 const QObject* stateChangeReceiver,
79 const char* stateChangeSlot)
80 {
82 QWidgetT* widget = new QWidgetT(nullptr);
83
84 widget->setToolTip(QString::fromStdString(desc.toolTip));
85 widget->setLowerBound(desc.min);
86 widget->setUpperBound(desc.max);
87 widget->setTotalSteps(desc.steps);
88 widget->setOrientation(Qt::Horizontal);
89
90 QObject::connect(
91 widget, SIGNAL(valueChanged(double)), stateChangeReceiver, stateChangeSlot);
92
93 return widget;
94 }
95
96 static void
97 updateGui(RemoteWidgetT const& desc, QWidgetT* widget, ValueT const& value)
98 {
99 widget->setValue(value);
100 }
101
102 static ValueT
104 {
105 return widget->value();
106 }
107 };
108
109} // namespace armarx::RemoteGui
#define cmp_or_log(l, c, r)
std::function< QWidgetPtr(WidgetPtr const &)> CreateWidgetCallback
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
static void updateGui(RemoteWidgetT const &desc, QWidgetT *widget, ValueT const &value)
static ValueT handleGuiChange(RemoteWidgetT const &desc, QWidgetT *widget)
static bool isValid(RemoteWidgetT const &desc, std::ostream &out)
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
static void updateGui(RemoteWidgetT const &desc, QWidgetT *widget, ValueT const &value)
static ValueT handleGuiChange(RemoteWidgetT const &desc, QWidgetT *widget)
static bool isValid(RemoteWidgetT const &desc, std::ostream &out)
#define ARMARX_TRACE
Definition trace.h:77