RemoteGuiWidgetController.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package ArmarXGui::gui-plugins::RemoteGuiWidgetController
17  * @author Fabian Paus ( fabian dot paus at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 #pragma once
23 
24 #include <ArmarXGui/gui-plugins/RemoteGuiPlugin/ui_RemoteGuiWidget.h>
25 
29 #include <ArmarXGui/interface/RemoteGuiInterface.h>
30 
32 
33 #include <string>
34 #include <mutex>
35 #include <map>
36 #include <set>
37 
38 namespace armarx
39 {
40 
41  /**
42  \page ArmarXGui-GuiPlugins-RemoteGui RemoteGui
43  \brief The RemoteGui allows visualizing remotely defined widgets for configuration.
44 
45  \image html RemoteGui.png
46  The user can create customized GUIs using the RemoteGuiProvider.
47  This plugin will display the created GUIs.
48 
49  API Documentation \ref RemoteGuiWidgetController
50 
51  \see RemoteGuiPlugin
52  \see RemoteGuiProvider
53  \see RemoteGuiExample
54  */
55 
56  /**
57  * \class RemoteGuiWidgetController
58  * \brief RemoteGuiWidgetController brief one line description
59  *
60  * Detailed description
61  */
64  : public armarx::ArmarXComponentWidgetControllerTemplate < RemoteGuiWidgetController >
65  , public armarx::RemoteGuiListenerInterface
66  {
67  Q_OBJECT
68 
69  public:
70  /**
71  * Controller Constructor
72  */
73  explicit RemoteGuiWidgetController();
74 
75  /**
76  * Controller destructor
77  */
78  virtual ~RemoteGuiWidgetController();
79 
80  QPointer<QDialog> getConfigDialog(QWidget* parent = 0) override;
81  void configured() override;
82 
83  /**
84  * @see ArmarXWidgetController::loadSettings()
85  */
86  void loadSettings(QSettings* settings) override;
87 
88  /**
89  * @see ArmarXWidgetController::saveSettings()
90  */
91  void saveSettings(QSettings* settings) override;
92 
93  /**
94  * Returns the Widget name displayed in the ArmarXGui to create an
95  * instance of this class.
96  */
97  static QString GetWidgetName()
98  {
99  return "Util.RemoteGui";
100  }
101 
102  // ManagedIceObject interface
103  void onInitComponent() override;
104  void onConnectComponent() override;
105 
106  // RemoteGuiListenerInterface interface
107  void reportTabChanged(const std::string& tab, const Ice::Current&) override;
108  void reportTabsRemoved(const Ice::Current&) override;
109  void reportWidgetChanged(const std::string& tab, const RemoteGui::WidgetStateMap& widgetState, const Ice::Current&) override;
110  void reportStateChanged(const std::string& tab, const RemoteGui::ValueMap& delta, const Ice::Current&) override;
111 
112  void onLockWidget() override;
113  void onUnlockWidget() override;
114 
115  public slots:
116  /* QT slot declarations */
117  void onTabChanged(QString id);
118  void onTabsChanged();
119  void onWidgetChanged(QString id);
120  void onStateChanged(QString id);
121 
122  void onGuiStateChanged();
123  void onSendButtonClicked();
124 
125  void onCheckBoxGroupTabsClicked(bool checked);
126  void onComboBoxTabGroupsCurrentIndexChanged(const QString& group);
127 
128  signals:
129  /* QT signal declarations */
130  void tabChanged(QString id);
131  void tabsChanged();
132  void widgetChanged(QString id);
133  void stateChanged(QString id);
134 
135  private:
136  void createTab(std::string const& tabId);
137  void removeObsoleteTabs();
138  void updateWidgets(std::string const& tabId);
139  void updateState(std::string const& tabId);
140 
141 
142  void createWidgets(std::string const& id);
143  void updateValuesInWidget(std::string const& id);
144 
145  void updateValuesInState();
146 
147  void doAutoUpdate(std::string const& id);
148 
149  QWidget* createWidgetFromDescription(std::string const& tabId, RemoteGui::WidgetPtr const& desc);
150 
151  private:
152  struct TabData
153  {
154  std::string fullName() const;
155  std::string name(const std::string& pre) const;
156  int findTabIndex(QTabWidget* tab) const;
157  QWidget* w = nullptr;
158  std::set<std::string> groups;
159  };
160  /**
161  * Widget Form
162  */
163  Ui::RemoteGuiWidget widget;
164 
165  QPointer<SimpleConfigDialog> dialog;
166  std::string remoteGuiProviderName;
167  RemoteGuiInterfacePrx remoteGuiProvider;
168 
169  std::mutex stateMutex;
170  RemoteGui::WidgetMap tabs;
171  std::map<std::string, TabData> qtTabs;
172  std::map<std::string, RemoteGui::WidgetMap> guiDescriptions;
173  RemoteGui::TabValueMap tabValueMap;
174  RemoteGui::TabValueMap tabDirtyMap;
175 
176  RemoteGui::TabWidgetStateMap tabWidgetStates;
177 
178  std::map<std::string, std::map<std::string, QWidget*>> guiWidgets;
179 
180  std::atomic<bool> internalUpdate {false};
181 
182  static constexpr auto groupAll = "<ALL>";
183  static constexpr auto groupUngrouped = "<UNGROUPED>";
184  std::string activeGroup = groupAll;
185 
186  std::map<std::string, std::size_t> tabsPerGroup;
187  };
188 }
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
SimpleConfigDialog.h
armarx::RemoteGui::ValueMap
std::map< std::string, ValueVariant > ValueMap
Definition: RemoteGuiVisitors.h:41
ArmarXGuiPlugin.h
ArmarXComponentWidgetController.h
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
armarx::RemoteGuiWidgetController
RemoteGuiWidgetController brief one line description.
Definition: RemoteGuiWidgetController.h:62
armarx::RemoteGuiWidgetController::GetWidgetName
static QString GetWidgetName()
Returns the Widget name displayed in the ArmarXGui to create an instance of this class.
Definition: RemoteGuiWidgetController.h:97
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:66
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RemoteGui::Client::createTab
void createTab(Ice::ObjectPrx const &remoteGuiObject, std::string const &tabName, Widget const &rootWidget)
ImportExportComponent.h