ConfigWidget.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef _CONFIG_WIDGET_HH_
19 #define _CONFIG_WIDGET_HH_
20 
21 #include <string>
22 #include <vector>
23 #include <map>
24 
25 #include "gazebo/math/Pose.hh"
26 #include "gazebo/common/Color.hh"
27 #include "gazebo/gui/qt.h"
28 
29 namespace google
30 {
31  namespace protobuf
32  {
33  class Message;
34  class Reflection;
35  class FieldDescriptor;
36  }
37 }
38 
39 namespace gazebo
40 {
41  namespace gui
42  {
43  class GroupWidget;
44 
47 
51  class GAZEBO_VISIBLE ConfigChildWidget : public QWidget
52  {
53  Q_OBJECT
54 
56  public: ConfigChildWidget() : groupWidget(NULL) {}
57 
59  public: std::vector<QWidget *> widgets;
60 
64  };
65 
69  {
70  Q_OBJECT
71 
74  public: QStackedWidget *geomDimensionWidget;
75 
77  public: QWidget *geomLengthSpinBox;
78 
80  public: QWidget *geomLengthLabel;
81 
84  private slots: void GeometryChanged(const QString _text);
85  };
86 
89  class GAZEBO_VISIBLE GroupWidget : public QWidget
90  {
91  Q_OBJECT
92 
94  public: QWidget *childWidget;
95 
97  private slots: void Toggle();
98  };
99 
102  class GAZEBO_VISIBLE ConfigWidget : public QWidget
103  {
104  Q_OBJECT
105 
107  public: ConfigWidget();
108 
110  public: ~ConfigWidget();
111 
114  public: void Load(const google::protobuf::Message *_msg);
115 
118  public: google::protobuf::Message *GetMsg();
119 
123  public: void SetWidgetVisible(const std::string &_name, bool _visible);
124 
128  public: bool GetWidgetVisible(const std::string &_name) const;
129 
133  public: void SetWidgetReadOnly(const std::string &_name, bool _readOnly);
134 
138  public: bool GetWidgetReadOnly(const std::string &_name) const;
139 
142  public: void UpdateFromMsg(const google::protobuf::Message *_msg);
143 
147  public: void SetIntWidgetValue(const std::string &_name, int _value);
148 
152  public: void SetUIntWidgetValue(const std::string &_name, unsigned int
153  _value);
154 
158  public: void SetDoubleWidgetValue(const std::string &_name,
159  double _value);
160 
164  public: void SetBoolWidgetValue(const std::string &_name, bool _value);
165 
169  public: void SetStringWidgetValue(const std::string &_name,
170  const std::string &_value);
171 
175  public: void SetVector3WidgetValue(const std::string &_name,
176  const math::Vector3 &_value);
177 
181  public: void SetColorWidgetValue(const std::string &_name,
182  const common::Color &_value);
183 
187  public: void SetPoseWidgetValue(const std::string &_name,
188  const math::Pose &_value);
189 
194  public: void SetGeometryWidgetValue(const std::string &_name,
195  const std::string &_value, const math::Vector3 &_dimensions);
196 
200  public: int GetIntWidgetValue(const std::string &_name) const;
201 
205  public: unsigned int GetUIntWidgetValue(const std::string &_name) const;
206 
210  public: double GetDoubleWidgetValue(const std::string &_name) const;
211 
215  public: bool GetBoolWidgetValue(const std::string &_name) const;
216 
220  public: std::string GetStringWidgetValue(const std::string &_name) const;
221 
225  public: math::Vector3 GetVector3WidgetValue(const std::string &_name)
226  const;
227 
231  public: common::Color GetColorWidgetValue(const std::string &_name) const;
232 
236  public: math::Pose GetPoseWidgetValue(const std::string &_name) const;
237 
242  public: std::string GetGeometryWidgetValue(const std::string &_name,
243  math::Vector3 &_dimensions) const;
244 
251  private: QWidget *Parse(google::protobuf::Message *_msg,
252  const std::string &_name = "");
253 
257  private: math::Vector3 ParseVector3(
258  const google::protobuf::Message *_msg);
259 
263  private: void UpdateMsg(google::protobuf::Message *_msg,
264  const std::string &_name = "");
265 
269  private: void UpdateVector3Msg(google::protobuf::Message *_msg,
270  const math::Vector3 &_value);
271 
275  private: ConfigChildWidget *CreateUIntWidget(const std::string &_key);
276 
280  private: ConfigChildWidget *CreateIntWidget(const std::string &_key);
281 
285  private: ConfigChildWidget *CreateDoubleWidget(const std::string &_key);
286 
290  private: ConfigChildWidget *CreateStringWidget(const std::string &_key);
291 
295  private: ConfigChildWidget *CreateBoolWidget(const std::string &_key);
296 
300  private: ConfigChildWidget *CreateVector3dWidget(const std::string &_key);
301 
305  private: ConfigChildWidget *CreateColorWidget(const std::string &_key);
306 
310  private: ConfigChildWidget *CreatePoseWidget(const std::string &_key);
311 
315  private: ConfigChildWidget *CreateGeometryWidget(const std::string &_key);
316 
320  private: void UpdateUIntWidget(ConfigChildWidget *_widget,
321  unsigned int _value);
322 
326  private: void UpdateIntWidget(ConfigChildWidget *_widget, int _value);
327 
331  private: void UpdateDoubleWidget(ConfigChildWidget *_widget,
332  double _value);
333 
337  private: void UpdateStringWidget(ConfigChildWidget *_widget,
338  const std::string &_value);
339 
343  private: void UpdateBoolWidget(ConfigChildWidget *_widget, bool _value);
344 
348  private: void UpdateVector3Widget(ConfigChildWidget *_widget,
349  const math::Vector3 &_value);
350 
354  private: void UpdateColorWidget(ConfigChildWidget *_widget,
355  const common::Color &_value);
356 
360  private: void UpdatePoseWidget(ConfigChildWidget *_widget,
361  const math::Pose &_value);
362 
367  private: void UpdateGeometryWidget(ConfigChildWidget *_widget,
368  const std::string &_value, const math::Vector3 &_dimensions);
369 
373  private: int GetIntWidgetValue(ConfigChildWidget *_widget) const;
374 
378  private: unsigned int GetUIntWidgetValue(ConfigChildWidget *_widget)
379  const;
380 
384  private: double GetDoubleWidgetValue(ConfigChildWidget *_widget) const;
385 
389  private: bool GetBoolWidgetValue(ConfigChildWidget *_widget) const;
390 
394  private: std::string GetStringWidgetValue(ConfigChildWidget *_widget)
395  const;
396 
400  private: math::Vector3 GetVector3WidgetValue(ConfigChildWidget *_widget)
401  const;
402 
406  private: common::Color GetColorWidgetValue(ConfigChildWidget *_widget)
407  const;
408 
412  private: math::Pose GetPoseWidgetValue(ConfigChildWidget *_widget) const;
413 
418  private: std::string GetGeometryWidgetValue(ConfigChildWidget *_widget,
419  math::Vector3 &_dimensions) const;
420 
424  private slots: void OnItemSelection(QTreeWidgetItem *_item, int _column);
425 
427  private: std::map <std::string, ConfigChildWidget *> configWidgets;
428 
430  private: google::protobuf::Message *configMsg;
431  };
432  }
433 }
434 #endif
QWidget * geomLengthLabel
A label for the length widget.
Definition: ConfigWidget.hh:80
A collapsible widget that holds child widgets.
Definition: ConfigWidget.hh:89
GroupWidget * groupWidget
Pointer to group widget.
Definition: ConfigWidget.hh:63
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
QWidget * childWidget
Child widget that can be collapsed or expanded.
Definition: ConfigWidget.hh:94
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
A widget generated from a google protobuf message.
Definition: ConfigWidget.hh:102
ConfigChildWidget()
Constructor;.
Definition: ConfigWidget.hh:56
A convenience widget that also holds pointers to a list of its child widgets.
Definition: ConfigWidget.hh:51
QWidget * geomLengthSpinBox
A spin box for configuring the length of the geometry.
Definition: ConfigWidget.hh:77
std::vector< QWidget * > widgets
List of child widgets.
Definition: ConfigWidget.hh:59
A widget for configuring geometry properties.
Definition: ConfigWidget.hh:68
#define NULL
Definition: CommonTypes.hh:30
Defines a color.
Definition: Color.hh:39
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
QStackedWidget * geomDimensionWidget
A stacked widget containing widgets for configuring geometry dimensions.
Definition: ConfigWidget.hh:74