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