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