StringWidgets.h
Go to the documentation of this file.
1#pragma once
2
3#include <QComboBox>
4#include <QLineEdit>
5
6#include "Basic.h"
7
8namespace armarx::RemoteGui
9{
10 struct LineEditHandler : TypedWidget<LineEdit, QLineEdit, VALUE_VARIANT_STRING>
11 {
12 static QWidgetT*
14 CreateWidgetCallback const& createChild,
15 const QObject* stateChangeReceiver,
16 const char* stateChangeSlot)
17 {
19 QWidgetT* widget = new QWidgetT();
20 widget->setToolTip(QString::fromStdString(desc.toolTip));
21
22 QObject::connect(
23 widget, SIGNAL(editingFinished()), stateChangeReceiver, stateChangeSlot);
24
25 return widget;
26 }
27
28 static void
29 updateGui(RemoteWidgetT const& desc, QWidgetT* widget, ValueT const& value)
30 {
31 widget->setText(toQString(value));
32 }
33
34 static ValueT
36 {
37 return toUtf8(widget->text());
38 }
39 };
40
41 struct ComboBoxHandler : TypedWidget<ComboBox, QComboBox, VALUE_VARIANT_STRING>
42 {
43 static QWidgetT*
45 CreateWidgetCallback const& createChild,
46 const QObject* stateChangeReceiver,
47 const char* stateChangeSlot)
48 {
50 QWidgetT* widget = new QWidgetT();
51 widget->setToolTip(QString::fromStdString(desc.toolTip));
52
53 for (std::string const& option : desc.options)
54 {
56 widget->addItem(toQString(option));
57 }
59 QObject::connect(
60 widget, SIGNAL(currentIndexChanged(int)), stateChangeReceiver, stateChangeSlot);
61
62 return widget;
63 }
64
65 static void
66 updateGui(RemoteWidgetT const& desc, QWidgetT* widget, ValueT const& value)
67 {
69 int index = widget->findText(toQString(value));
70 if (index >= 0)
71 {
72 widget->setCurrentIndex(index);
73 }
74 else
75 {
76 throw LocalException()
77 << "Invalid value set for ComboBox '" << desc.name << "': " << value;
78 }
79 }
80
81 static ValueT
83 {
84 return toUtf8(widget->currentText());
85 }
86 };
87
88} // namespace armarx::RemoteGui
uint8_t index
#define option(type, fn)
std::function< QWidgetPtr(WidgetPtr const &)> CreateWidgetCallback
QString toQString(std::string const &string)
std::string toUtf8(QString const &qstring)
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
static void updateGui(RemoteWidgetT const &desc, QWidgetT *widget, ValueT const &value)
static ValueT handleGuiChange(RemoteWidgetT const &desc, QWidgetT *widget)
static QWidgetT * createWidget(RemoteWidgetT const &desc, CreateWidgetCallback const &createChild, const QObject *stateChangeReceiver, const char *stateChangeSlot)
static void updateGui(RemoteWidgetT const &desc, QWidgetT *widget, ValueT const &value)
static ValueT handleGuiChange(RemoteWidgetT const &desc, QWidgetT *widget)
#define ARMARX_TRACE
Definition trace.h:77