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 <map>
25#include <mutex>
26#include <set>
27#include <string>
28
30
31#include <ArmarXGui/gui-plugins/RemoteGuiPlugin/ui_RemoteGuiWidget.h>
32#include <ArmarXGui/interface/RemoteGuiInterface.h>
36
37namespace armarx
38{
39
40 /**
41 \page ArmarXGui-GuiPlugins-RemoteGui RemoteGui
42 \brief The RemoteGui allows visualizing remotely defined widgets for configuration.
43
44 \image html RemoteGui.png
45 The user can create customized GUIs using the RemoteGuiProvider.
46 This plugin will display the created GUIs.
47
48 API Documentation \ref RemoteGuiWidgetController
49
50 \see RemoteGuiPlugin
51 \see RemoteGuiProvider
52 \see RemoteGuiExample
53 */
54
55 /**
56 * \class RemoteGuiWidgetController
57 * \brief RemoteGuiWidgetController brief one line description
58 *
59 * Detailed description
60 */
62 public armarx::ArmarXComponentWidgetControllerTemplate<RemoteGuiWidgetController>,
63 public armarx::RemoteGuiListenerInterface
64 {
65 Q_OBJECT
66
67 public:
68 /**
69 * Controller Constructor
70 */
72
73 /**
74 * Controller destructor
75 */
77
78 QPointer<QDialog> getConfigDialog(QWidget* parent = 0) override;
79 void configured() override;
80
81 /**
82 * @see ArmarXWidgetController::loadSettings()
83 */
84 void loadSettings(QSettings* settings) override;
85
86 /**
87 * @see ArmarXWidgetController::saveSettings()
88 */
89 void saveSettings(QSettings* settings) override;
90
91 /**
92 * Returns the Widget name displayed in the ArmarXGui to create an
93 * instance of this class.
94 */
95 static QString
97 {
98 return "Util.RemoteGui";
99 }
100
101 // ManagedIceObject interface
102 void onInitComponent() override;
103 void onConnectComponent() override;
104
105 // RemoteGuiListenerInterface interface
106 void reportTabChanged(const std::string& tab, const Ice::Current&) override;
107 void reportTabsRemoved(const Ice::Current&) override;
108 void reportWidgetChanged(const std::string& tab,
109 const RemoteGui::WidgetStateMap& widgetState,
110 const Ice::Current&) override;
111 void reportStateChanged(const std::string& tab,
112 const RemoteGui::ValueMap& delta,
113 const Ice::Current&) override;
114
115 void onLockWidget() override;
116 void onUnlockWidget() override;
117
118 public slots:
119 /* QT slot declarations */
120 void onTabChanged(QString id);
121 void onTabsChanged();
122 void onWidgetChanged(QString id);
123 void onStateChanged(QString id);
124
125 void onGuiStateChanged();
126 void onSendButtonClicked();
127
128 void onCheckBoxGroupTabsClicked(bool checked);
129 void onComboBoxTabGroupsCurrentIndexChanged(const QString& group);
130
131 signals:
132 /* QT signal declarations */
133 void tabChanged(QString id);
135 void widgetChanged(QString id);
136 void stateChanged(QString id);
137
138 private:
139 void createTab(std::string const& tabId);
140 void removeObsoleteTabs();
141 void updateWidgets(std::string const& tabId);
142 void updateState(std::string const& tabId);
143
144
145 void createWidgets(std::string const& id);
146 void updateValuesInWidget(std::string const& id);
147
148 void updateValuesInState();
149
150 void doAutoUpdate(std::string const& id);
151
152 QWidget* createWidgetFromDescription(std::string const& tabId,
153 RemoteGui::WidgetPtr const& desc);
154
155 private:
156 struct TabData
157 {
158 std::string fullName() const;
159 std::string name(const std::string& pre) const;
160 int findTabIndex(QTabWidget* tab) const;
161 QWidget* w = nullptr;
162 std::set<std::string> groups;
163 };
164
165 /**
166 * Widget Form
167 */
168 Ui::RemoteGuiWidget widget;
169
170 QPointer<SimpleConfigDialog> dialog;
171 std::string remoteGuiProviderName;
172 RemoteGuiInterfacePrx remoteGuiProvider;
173
174 std::mutex stateMutex;
175 RemoteGui::WidgetMap tabs;
176 std::map<std::string, TabData> qtTabs;
177 std::map<std::string, RemoteGui::WidgetMap> guiDescriptions;
178 RemoteGui::TabValueMap tabValueMap;
179 RemoteGui::TabValueMap tabDirtyMap;
180
181 RemoteGui::TabWidgetStateMap tabWidgetStates;
182
183 std::map<std::string, std::map<std::string, QWidget*>> guiWidgets;
184
185 std::atomic<bool> internalUpdate{false};
186
187 static constexpr auto groupAll = "<ALL>";
188 static constexpr auto groupUngrouped = "<UNGROUPED>";
189 std::string activeGroup = groupAll;
190
191 std::map<std::string, std::size_t> tabsPerGroup;
192 };
193} // namespace armarx
#define ARMARXCOMPONENT_IMPORT_EXPORT
void loadSettings(QSettings *settings) override
void saveSettings(QSettings *settings) override
QPointer< QDialog > getConfigDialog(QWidget *parent=0) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
static QString GetWidgetName()
Returns the Widget name displayed in the ArmarXGui to create an instance of this class.
std::map< std::string, ValueVariant > ValueMap
This file offers overloads of toIce() and fromIce() functions for STL container types.