Vector3fWidgets.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QWidget>
4 #include <QDoubleSpinBox>
5 #include <QHBoxLayout>
6 
7 #include "Basic.h"
8 
9 namespace armarx::RemoteGui
10 {
11  struct Vector3fSpinBoxesHandler : TypedWidget<Vector3fSpinBoxes, QWidget, VALUE_VARIANT_VECTOR3>
12  {
13  static bool isValid(RemoteWidgetT const& desc, std::ostream& out)
14  {
15 #define cmp_or_log(l,c,r) \
16  (l c r ? true : \
17  ( \
18  out << " FAILED: " #l " " #c " " #r " " \
19  << VAROUT(l) << ", " << VAROUT(r) << '\n',\
20  false \
21  ))
22 
23  return cmp_or_log(desc.min.x, <=, desc.max.x)
24  && cmp_or_log(desc.min.y, <=, desc.max.y)
25  && cmp_or_log(desc.min.z, <=, desc.max.z)
26  && cmp_or_log(desc.steps.x, >, 0)
27  && cmp_or_log(desc.steps.y, >, 0)
28  && cmp_or_log(desc.steps.z, >, 0)
29  && cmp_or_log(desc.decimals.x, >=, 0)
30  && cmp_or_log(desc.decimals.y, >=, 0)
31  && cmp_or_log(desc.decimals.z, >=, 0);
32 #undef cmp_or_log
33  }
34 
35  static QWidgetT* createWidget(RemoteWidgetT const& desc, CreateWidgetCallback const& createChild,
36  const QObject* stateChangeReceiver, const char* stateChangeSlot)
37  {
39  QWidget* widget = new QWidget;
40  widget->setToolTip(QString::fromStdString(desc.toolTip));
41  QHBoxLayout* l = new QHBoxLayout;
42  l->setContentsMargins(0, 0, 0, 0);
43  widget->setLayout(l);
44 
45  Eigen::Vector3f min = fromIce(desc.min);
46  Eigen::Vector3f max = fromIce(desc.max);
47  Eigen::Vector3i decimals = fromIce(desc.decimals);
48  Eigen::Vector3i steps = fromIce(desc.steps);
49  for (int i = 0; i < 3; ++i)
50  {
51  QDoubleSpinBox* e = new QDoubleSpinBox;
52  l->addWidget(e);
53  e->setMinimum(min(i));
54  e->setMaximum(max(i));
55  e->setDecimals(decimals(i));
56  e->setSingleStep((max(i) - min(i)) / steps(i));
57  QObject::connect(e, SIGNAL(valueChanged(double)), stateChangeReceiver, stateChangeSlot);
58  }
59  return widget;
60  }
61 
62  static void updateGui(RemoteWidgetT const&, QWidgetT* widget, ValueT const& value)
63  {
64  static_cast<QDoubleSpinBox*>(widget->layout()->itemAt(0)->widget())->setValue(value(0));
65  static_cast<QDoubleSpinBox*>(widget->layout()->itemAt(1)->widget())->setValue(value(1));
66  static_cast<QDoubleSpinBox*>(widget->layout()->itemAt(2)->widget())->setValue(value(2));
67  }
68 
69  static ValueT handleGuiChange(RemoteWidgetT const&, QWidgetT* widget)
70  {
71  QWidgetT* parent = static_cast<QWidget*>(widget->parent());
72  return
73  {
74  static_cast<float>(static_cast<QDoubleSpinBox*>(parent->layout()->itemAt(0)->widget())->value()),
75  static_cast<float>(static_cast<QDoubleSpinBox*>(parent->layout()->itemAt(1)->widget())->value()),
76  static_cast<float>(static_cast<QDoubleSpinBox*>(parent->layout()->itemAt(2)->widget())->value())
77  };
78  }
79  };
80 
81 }
armarx::RemoteGui::Vector3fSpinBoxesHandler::createWidget
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
Definition: Vector3fWidgets.h:35
cmp_or_log
#define cmp_or_log(l, c, r)
armarx::RemoteGui
Definition: LightweightRemoteGuiComponentPlugin.h:30
armarx::RemoteGui::Vector3fSpinBoxesHandler::updateGui
static void updateGui(RemoteWidgetT const &, QWidgetT *widget, ValueT const &value)
Definition: Vector3fWidgets.h:62
armarx::RemoteGui::TypedWidget
Definition: TypedWidget.h:115
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
armarx::RemoteGui::Vector3fSpinBoxesHandler::isValid
static bool isValid(RemoteWidgetT const &desc, std::ostream &out)
Definition: Vector3fWidgets.h:13
armarx::RemoteGui::TypedWidget< Vector3fSpinBoxes, QWidget, VALUE_VARIANT_VECTOR3 >::ValueT
typename Storage< ValueType >::Type ValueT
Definition: TypedWidget.h:120
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
Basic.h
armarx::RemoteGui::TypedWidget< Vector3fSpinBoxes, QWidget, VALUE_VARIANT_VECTOR3 >::QWidgetT
QWidget QWidgetT
Definition: TypedWidget.h:118
armarx::RemoteGui::fromIce
Eigen::Vector3f fromIce(Vector3f v)
Definition: Storage.cpp:91
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:294
armarx::RemoteGui::Vector3fSpinBoxesHandler::handleGuiChange
static ValueT handleGuiChange(RemoteWidgetT const &, QWidgetT *widget)
Definition: Vector3fWidgets.h:69
armarx::RemoteGui::Vector3fSpinBoxesHandler
Definition: Vector3fWidgets.h:11
armarx::RemoteGui::CreateWidgetCallback
std::function< QWidgetPtr(WidgetPtr const &)> CreateWidgetCallback
Definition: WidgetHandler.h:20
armarx::RemoteGui::TypedWidget< Vector3fSpinBoxes, QWidget, VALUE_VARIANT_VECTOR3 >::RemoteWidgetT
Vector3fSpinBoxes RemoteWidgetT
Definition: TypedWidget.h:117