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 
12 namespace armarx::RemoteGui
13 {
14  struct FloatSpinBoxHandler : TypedWidget<FloatSpinBox, QDoubleSpinBox, VALUE_VARIANT_FLOAT>
15  {
16  static bool isValid(RemoteWidgetT const& desc, std::ostream& out)
17  {
18 #define cmp_or_log(l,c,r) \
19  (l c r ? true : \
20  ( \
21  out << " FAILED: " #l " " #c " " #r " " \
22  << VAROUT(l) << ", " << VAROUT(r) << '\n',\
23  false \
24  ))
25  return cmp_or_log(desc.min, <=, desc.max)
26  && cmp_or_log(desc.steps, >, 0)
27  && cmp_or_log(desc.decimals, >=, 0);
28 #undef cmp_or_log
29  }
30 
31  static QWidgetT* createWidget(RemoteWidgetT const& desc, CreateWidgetCallback const& createChild,
32  const QObject* stateChangeReceiver, 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(widget, SIGNAL(valueChanged(double)), stateChangeReceiver, stateChangeSlot);
44 
45  return widget;
46  }
47 
48  static void updateGui(RemoteWidgetT const& desc, QWidgetT* widget, ValueT const& value)
49  {
50  widget->setValue(value);
51  }
52 
53  static ValueT handleGuiChange(RemoteWidgetT const& desc, QWidgetT* widget)
54  {
55  return widget->value();
56  }
57  };
58 
59  struct FloatSliderHandler : TypedWidget<FloatSlider, QwtSlider, VALUE_VARIANT_FLOAT>
60  {
61  static bool isValid(RemoteWidgetT const& desc, std::ostream& out)
62  {
63 #define cmp_or_log(l,c,r) \
64  (l c r ? true : \
65  ( \
66  out << " FAILED: " #l " " #c " " #r " " \
67  << VAROUT(l) << ", " << VAROUT(r) << '\n',\
68  false \
69  ))
70  return cmp_or_log(desc.min, <=, desc.max)
71  && cmp_or_log(desc.steps, >, 0);
72 #undef cmp_or_log
73  }
74 
75  static QWidgetT* createWidget(RemoteWidgetT const& desc, CreateWidgetCallback const& createChild,
76  const QObject* stateChangeReceiver, const char* stateChangeSlot)
77  {
79  QWidgetT* widget = new QWidgetT(nullptr);
80 
81  widget->setToolTip(QString::fromStdString(desc.toolTip));
82  widget->setLowerBound(desc.min);
83  widget->setUpperBound(desc.max);
84  widget->setTotalSteps(desc.steps);
85  widget->setOrientation(Qt::Horizontal);
86 
87  QObject::connect(widget, SIGNAL(valueChanged(double)), stateChangeReceiver, stateChangeSlot);
88 
89  return widget;
90  }
91 
92  static void updateGui(RemoteWidgetT const& desc, QWidgetT* widget, ValueT const& value)
93  {
94  widget->setValue(value);
95  }
96 
97  static ValueT handleGuiChange(RemoteWidgetT const& desc, QWidgetT* widget)
98  {
99  return widget->value();
100  }
101  };
102 
103 }
cmp_or_log
#define cmp_or_log(l, c, r)
armarx::RemoteGui
Definition: LightweightRemoteGuiComponentPlugin.h:30
armarx::RemoteGui::FloatSliderHandler::isValid
static bool isValid(RemoteWidgetT const &desc, std::ostream &out)
Definition: FloatWidgets.h:61
armarx::RemoteGui::TypedWidget
Definition: TypedWidget.h:115
armarx::RemoteGui::FloatSliderHandler
Definition: FloatWidgets.h:59
armarx::RemoteGui::FloatSliderHandler::updateGui
static void updateGui(RemoteWidgetT const &desc, QWidgetT *widget, ValueT const &value)
Definition: FloatWidgets.h:92
armarx::RemoteGui::FloatSpinBoxHandler::handleGuiChange
static ValueT handleGuiChange(RemoteWidgetT const &desc, QWidgetT *widget)
Definition: FloatWidgets.h:53
armarx::RemoteGui::FloatSliderHandler::handleGuiChange
static ValueT handleGuiChange(RemoteWidgetT const &desc, QWidgetT *widget)
Definition: FloatWidgets.h:97
armarx::RemoteGui::TypedWidget< FloatSpinBox, QDoubleSpinBox, VALUE_VARIANT_FLOAT >::ValueT
typename Storage< ValueType >::Type ValueT
Definition: TypedWidget.h:120
armarx::RemoteGui::FloatSpinBoxHandler::isValid
static bool isValid(RemoteWidgetT const &desc, std::ostream &out)
Definition: FloatWidgets.h:16
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::RemoteGui::FloatSpinBoxHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: FloatWidgets.h:31
armarx::RemoteGui::FloatSpinBoxHandler::updateGui
static void updateGui(RemoteWidgetT const &desc, QWidgetT *widget, ValueT const &value)
Definition: FloatWidgets.h:48
armarx::RemoteGui::Client::FloatSlider
Definition: Widgets.h:107
Basic.h
armarx::RemoteGui::TypedWidget< FloatSpinBox, QDoubleSpinBox, VALUE_VARIANT_FLOAT >::QWidgetT
QDoubleSpinBox QWidgetT
Definition: TypedWidget.h:118
armarx::RemoteGui::FloatSliderHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: FloatWidgets.h:75
armarx::RemoteGui::CreateWidgetCallback
std::function< QWidgetPtr(WidgetPtr const &)> CreateWidgetCallback
Definition: WidgetHandler.h:20
armarx::RemoteGui::FloatSpinBoxHandler
Definition: FloatWidgets.h:14
armarx::RemoteGui::Client::FloatSpinBox
Definition: Widgets.h:93