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
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
56  handleGuiChange(RemoteWidgetT const& desc, QWidgetT* widget)
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
103  handleGuiChange(RemoteWidgetT const& desc, QWidgetT* widget)
104  {
105  return widget->value();
106  }
107  };
108 
109 } // namespace armarx::RemoteGui
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:65
armarx::RemoteGui::TypedWidget
Definition: TypedWidget.h:113
armarx::RemoteGui::FloatSliderHandler
Definition: FloatWidgets.h:62
armarx::RemoteGui::FloatSliderHandler::updateGui
static void updateGui(RemoteWidgetT const &desc, QWidgetT *widget, ValueT const &value)
Definition: FloatWidgets.h:97
armarx::RemoteGui::FloatSpinBoxHandler::handleGuiChange
static ValueT handleGuiChange(RemoteWidgetT const &desc, QWidgetT *widget)
Definition: FloatWidgets.h:56
armarx::RemoteGui::FloatSliderHandler::handleGuiChange
static ValueT handleGuiChange(RemoteWidgetT const &desc, QWidgetT *widget)
Definition: FloatWidgets.h:103
armarx::RemoteGui::TypedWidget< FloatSpinBox, QDoubleSpinBox, VALUE_VARIANT_FLOAT >::ValueT
typename Storage< ValueType >::Type ValueT
Definition: TypedWidget.h:118
armarx::RemoteGui::FloatSpinBoxHandler::isValid
static bool isValid(RemoteWidgetT const &desc, std::ostream &out)
Definition: FloatWidgets.h:17
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::RemoteGui::FloatSpinBoxHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: FloatWidgets.h:29
armarx::RemoteGui::FloatSpinBoxHandler::updateGui
static void updateGui(RemoteWidgetT const &desc, QWidgetT *widget, ValueT const &value)
Definition: FloatWidgets.h:50
armarx::RemoteGui::Client::FloatSlider
Definition: Widgets.h:107
Basic.h
armarx::RemoteGui::TypedWidget< FloatSpinBox, QDoubleSpinBox, VALUE_VARIANT_FLOAT >::QWidgetT
QDoubleSpinBox QWidgetT
Definition: TypedWidget.h:116
armarx::RemoteGui::FloatSliderHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: FloatWidgets.h:76
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