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
9namespace 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
#define cmp_or_log(l, c, r)
Eigen::Vector3f fromIce(Vector3f v)
Definition Storage.cpp:100
std::function< QWidgetPtr(WidgetPtr const &)> CreateWidgetCallback
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
static ValueT handleGuiChange(RemoteWidgetT const &, QWidgetT *widget)
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
static void updateGui(RemoteWidgetT const &, QWidgetT *widget, ValueT const &value)
static bool isValid(RemoteWidgetT const &desc, std::ostream &out)
#define ARMARX_TRACE
Definition trace.h:77