ConfigWidget.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2016 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 _GAZEBO_GUI_CONFIGWIDGET_HH_
19 #define _GAZEBO_GUI_CONFIGWIDGET_HH_
20 
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include <ignition/math/Pose3.hh>
27 #include <ignition/math/Vector3.hh>
28 
29 #include "gazebo/common/Color.hh"
30 #include "gazebo/math/Pose.hh"
31 #include "gazebo/gui/qt.h"
32 
33 namespace google
34 {
35  namespace protobuf
36  {
37  class Message;
38  class Reflection;
39  class FieldDescriptor;
40  }
41 }
42 
43 namespace gazebo
44 {
45  namespace gui
46  {
47  class ConfigWidgetPrivate;
48  class GroupWidget;
49 
52 
56  class GZ_GUI_VISIBLE ConfigChildWidget : public QFrame
57  {
58  Q_OBJECT
59 
61  public: ConfigChildWidget() : groupWidget(NULL) {}
62 
64  public: std::string key;
65 
67  public: std::string scopedName;
68 
70  public: std::vector<QWidget *> widgets;
71 
73  public: std::map<QWidget *, QLabel *> mapWidgetToUnit;
74 
78  };
79 
82  class GZ_GUI_VISIBLE GeometryConfigWidget : public ConfigChildWidget
83  {
84  Q_OBJECT
85 
88  public: QStackedWidget *geomDimensionWidget;
89 
91  public: QWidget *geomLengthSpinBox;
92 
94  public: QWidget *geomLengthLabel;
95 
97  public: QWidget *geomLengthUnitLabel;
98 
100  public: QWidget *geomFilenameLineEdit;
101 
103  public: QWidget *geomFilenameLabel;
104 
106  public: QWidget *geomFilenameButton;
107 
110  private slots: void GeometryChanged(const QString _text);
111 
113  private slots: void OnSelectFile();
114  };
115 
118  class GZ_GUI_VISIBLE EnumConfigWidget : public ConfigChildWidget
119  {
120  Q_OBJECT
121 
124  Q_SIGNALS: void EnumValueChanged(const QString &_value);
125 
128  private slots: void EnumChanged(const QString &_value);
129  };
130 
133  class GZ_GUI_VISIBLE GroupWidget : public QWidget
134  {
135  Q_OBJECT
136 
138  public: QWidget *childWidget;
139 
142  private slots: void Toggle(bool _checked);
143  };
144 
147  class GZ_GUI_VISIBLE ConfigWidget : public QWidget
148  {
149  Q_OBJECT
150 
152  public: ConfigWidget();
153 
155  public: ~ConfigWidget();
156 
159  public: void Load(const google::protobuf::Message *_msg);
160 
164  public: google::protobuf::Message *GetMsg() GAZEBO_DEPRECATED(7.0);
165 
168  public: google::protobuf::Message *Msg();
169 
175  public: std::string GetHumanReadableKey(const std::string &_key)
176  GAZEBO_DEPRECATED(7.0);
177 
182  public: std::string HumanReadableKey(const std::string &_key) const;
183 
192  public: std::string GetUnitFromKey(const std::string &_key,
193  const std::string &_jointType = "") GAZEBO_DEPRECATED(7.0);
194 
201  public: std::string UnitFromKey(const std::string &_key,
202  const std::string &_jointType = "") const;
203 
212  public: void GetRangeFromKey(const std::string &_key,
213  double &_min, double &_max) GAZEBO_DEPRECATED(7.0);
214 
220  public: void RangeFromKey(const std::string &_key,
221  double &_min, double &_max) const;
222 
226  public: void SetWidgetVisible(const std::string &_name, bool _visible);
227 
232  public: bool GetWidgetVisible(const std::string &_name) const
233  GAZEBO_DEPRECATED(7.0);
234 
238  public: bool WidgetVisible(const std::string &_name) const;
239 
243  public: void SetWidgetReadOnly(const std::string &_name, bool _readOnly);
244 
249  public: bool GetWidgetReadOnly(const std::string &_name) const
250  GAZEBO_DEPRECATED(7.0);
251 
255  public: bool WidgetReadOnly(const std::string &_name) const;
256 
259  public: void UpdateFromMsg(const google::protobuf::Message *_msg);
260 
265  public: bool SetIntWidgetValue(const std::string &_name, int _value);
266 
271  public: bool SetUIntWidgetValue(const std::string &_name, unsigned int
272  _value);
273 
278  public: bool SetDoubleWidgetValue(const std::string &_name,
279  double _value);
280 
285  public: bool SetBoolWidgetValue(const std::string &_name, bool _value);
286 
290  public: bool SetStringWidgetValue(const std::string &_name,
291  const std::string &_value);
292 
299  public: bool SetVector3WidgetValue(const std::string &_name,
300  const math::Vector3 &_value) GAZEBO_DEPRECATED(7.0);
301 
306  public: bool SetVector3dWidgetValue(const std::string &_name,
307  const ignition::math::Vector3d &_value);
308 
313  public: bool SetColorWidgetValue(const std::string &_name,
314  const common::Color &_value);
315 
322  public: bool SetPoseWidgetValue(const std::string &_name,
323  const math::Pose &_value) GAZEBO_DEPRECATED(7.0);
324 
329  public: bool SetPoseWidgetValue(const std::string &_name,
330  const ignition::math::Pose3d &_value);
331 
341  public: bool SetGeometryWidgetValue(const std::string &_name,
342  const std::string &_value, const math::Vector3 &_dimensions,
343  const std::string &_uri = "") GAZEBO_DEPRECATED(7.0);
344 
350  public: bool SetGeometryWidgetValue(const std::string &_name,
351  const std::string &_value,
352  const ignition::math::Vector3d &_dimensions,
353  const std::string &_uri = "");
354 
359  public: bool SetEnumWidgetValue(const std::string &_name,
360  const std::string &_value);
361 
366  public: bool AddItemEnumWidget(const std::string &_name,
367  const std::string &_itemText);
368 
373  public: bool RemoveItemEnumWidget(const std::string &_name,
374  const std::string &_itemText);
375 
379  public: bool ClearEnumWidget(const std::string &_name);
380 
385  public: int GetIntWidgetValue(const std::string &_name) const
386  GAZEBO_DEPRECATED(7.0);
387 
391  public: int IntWidgetValue(const std::string &_name) const;
392 
397  public: unsigned int GetUIntWidgetValue(const std::string &_name) const
398  GAZEBO_DEPRECATED(7.0);
399 
403  public: unsigned int UIntWidgetValue(const std::string &_name) const;
404 
409  public: double GetDoubleWidgetValue(const std::string &_name) const
410  GAZEBO_DEPRECATED(7.0);
411 
415  public: double DoubleWidgetValue(const std::string &_name) const;
416 
421  public: bool GetBoolWidgetValue(const std::string &_name) const
422  GAZEBO_DEPRECATED(7.0);
423 
427  public: bool BoolWidgetValue(const std::string &_name) const;
428 
433  public: std::string GetStringWidgetValue(const std::string &_name) const
434  GAZEBO_DEPRECATED(7.0);
435 
439  public: std::string StringWidgetValue(const std::string &_name) const;
440 
445  public: math::Vector3 GetVector3WidgetValue(const std::string &_name)
446  const GAZEBO_DEPRECATED(7.0);
447 
451  public: ignition::math::Vector3d Vector3dWidgetValue(
452  const std::string &_name) const;
453 
458  public: common::Color GetColorWidgetValue(const std::string &_name) const
459  GAZEBO_DEPRECATED(7.0);
460 
464  public: common::Color ColorWidgetValue(const std::string &_name) const;
465 
470  public: math::Pose GetPoseWidgetValue(const std::string &_name) const
471  GAZEBO_DEPRECATED(7.0);
472 
476  public: ignition::math::Pose3d PoseWidgetValue(
477  const std::string &_name) const;
478 
486  public: std::string GetGeometryWidgetValue(const std::string &_name,
487  math::Vector3 &_dimensions, std::string &_uri) const
488  GAZEBO_DEPRECATED(7.0);
489 
495  public: std::string GeometryWidgetValue(const std::string &_name,
496  ignition::math::Vector3d &_dimensions, std::string &_uri) const;
497 
502  public: std::string GetEnumWidgetValue(const std::string &_name) const
503  GAZEBO_DEPRECATED(7.0);
504 
508  public: std::string EnumWidgetValue(const std::string &_name) const;
509 
516  public: GroupWidget *CreateGroupWidget(const std::string &_name,
517  ConfigChildWidget *_childWidget, const int _level = 0);
518 
523  public: ConfigChildWidget *CreateUIntWidget(const std::string &_key,
524  const int _level = 0);
525 
530  public: ConfigChildWidget *CreateIntWidget(const std::string &_key,
531  const int _level = 0);
532 
537  public: ConfigChildWidget *CreateDoubleWidget(const std::string &_key,
538  const int _level = 0);
539 
545  public: ConfigChildWidget *CreateStringWidget(const std::string &_key,
546  const int _level = 0, const std::string &_type = "line");
547 
552  public: ConfigChildWidget *CreateBoolWidget(const std::string &_key,
553  const int _level = 0);
554 
559  public: ConfigChildWidget *CreateVector3dWidget(const std::string &_key,
560  const int _level = 0);
561 
566  public: ConfigChildWidget *CreateColorWidget(const std::string &_key,
567  const int _level = 0);
568 
573  public: ConfigChildWidget *CreatePoseWidget(const std::string &_key,
574  const int _level = 0);
575 
580  public: ConfigChildWidget *CreateGeometryWidget(const std::string &_key,
581  const int _level = 0);
582 
588  public: ConfigChildWidget *CreateEnumWidget(const std::string &_key,
589  const std::vector<std::string> &_values, const int _level = 0);
590 
598  public: bool AddConfigChildWidget(const std::string &_name,
599  ConfigChildWidget *_child);
600 
605  public: void InsertLayout(QLayout *_layout, int _pos);
606 
611  public: ConfigChildWidget *ConfigChildWidgetByName(
612  const std::string &_name) const;
613 
616  public: unsigned int ConfigChildWidgetCount() const;
617 
625  public: static QString StyleSheet(const std::string &_type,
626  const int _level = 0);
627 
630  public: static const std::vector<QString> bgColors;
631 
633  public: static const std::vector<QString> widgetColors;
634 
636  public: static const QString redColor;
637 
639  public: static const QString greenColor;
640 
642  public: static const QString blueColor;
643 
653  private: QWidget *Parse(google::protobuf::Message *_msg,
654  bool _update = false, const std::string &_name = "",
655  const int _level = 0);
656 
660  private: ignition::math::Vector3d ParseVector3d(
661  const google::protobuf::Message *_msg) const;
662 
666  private: void UpdateMsg(google::protobuf::Message *_msg,
667  const std::string &_name = "");
668 
672  private: void UpdateVector3dMsg(google::protobuf::Message *_msg,
673  const ignition::math::Vector3d &_value);
674 
679  private: bool UpdateUIntWidget(ConfigChildWidget *_widget,
680  const unsigned int _value);
681 
686  private: bool UpdateIntWidget(ConfigChildWidget *_widget,
687  const int _value);
688 
693  private: bool UpdateDoubleWidget(ConfigChildWidget *_widget,
694  const double _value);
695 
700  private: bool UpdateStringWidget(ConfigChildWidget *_widget,
701  const std::string &_value);
702 
707  private: bool UpdateBoolWidget(ConfigChildWidget *_widget,
708  const bool _value);
709 
714  private: bool UpdateVector3dWidget(ConfigChildWidget *_widget,
715  const ignition::math::Vector3d &_value);
716 
721  private: bool UpdateColorWidget(ConfigChildWidget *_widget,
722  const common::Color &_value);
723 
728  private: bool UpdatePoseWidget(ConfigChildWidget *_widget,
729  const ignition::math::Pose3d &_value);
730 
737  private: bool UpdateGeometryWidget(ConfigChildWidget *_widget,
738  const std::string &_value,
739  const ignition::math::Vector3d &_dimensions,
740  const std::string &_uri = "");
741 
746  private: bool UpdateEnumWidget(ConfigChildWidget *_widget,
747  const std::string &_value);
748 
752  private: int IntWidgetValue(ConfigChildWidget *_widget) const;
753 
757  private: unsigned int UIntWidgetValue(ConfigChildWidget *_widget) const;
758 
762  private: double DoubleWidgetValue(ConfigChildWidget *_widget) const;
763 
767  private: bool BoolWidgetValue(ConfigChildWidget *_widget) const;
768 
772  private: std::string StringWidgetValue(ConfigChildWidget *_widget) const;
773 
777  private: ignition::math::Vector3d Vector3dWidgetValue(
778  ConfigChildWidget *_widget) const;
779 
783  private: common::Color ColorWidgetValue(ConfigChildWidget *_widget) const;
784 
788  private: ignition::math::Pose3d PoseWidgetValue(
789  ConfigChildWidget *_widget) const;
790 
796  private: std::string GeometryWidgetValue(ConfigChildWidget *_widget,
797  ignition::math::Vector3d &_dimensions, std::string &_uri) const;
798 
802  private: std::string EnumWidgetValue(ConfigChildWidget *_widget) const;
803 
807  private slots: void OnItemSelection(QTreeWidgetItem *_item,
808  const int _column);
809 
811  private slots: void OnUIntValueChanged();
812 
814  private slots: void OnIntValueChanged();
815 
817  private slots: void OnDoubleValueChanged();
818 
820  private slots: void OnBoolValueChanged();
821 
823  private slots: void OnStringValueChanged();
824 
826  private slots: void OnVector3dValueChanged();
827 
830  private slots: void OnVector3dPresetChanged(const int _index);
831 
833  private slots: void OnColorValueChanged();
834 
836  private slots: void OnPoseValueChanged();
837 
839  private slots: void OnGeometryValueChanged();
840 
843  private slots: void OnGeometryValueChanged(const int _value);
844 
847  private slots: void OnEnumValueChanged(const QString &_value);
848 
852  Q_SIGNALS: void UIntValueChanged(const QString &_name,
853  const unsigned int _value);
854 
858  Q_SIGNALS: void IntValueChanged(const QString &_name, const int _value);
859 
863  Q_SIGNALS: void DoubleValueChanged(const QString &_name,
864  const double _value);
865 
869  Q_SIGNALS: void BoolValueChanged(const QString &_name,
870  const bool _value);
871 
877  Q_SIGNALS: void StringValueChanged(const QString &_name,
878  const std::string &_value);
879 
883  Q_SIGNALS: void Vector3dValueChanged(const QString &_name,
884  const ignition::math::Vector3d &_value);
885 
889  Q_SIGNALS: void ColorValueChanged(const QString &_name,
890  const gazebo::common::Color &_value);
891 
895  Q_SIGNALS: void PoseValueChanged(const QString &_name,
896  const ignition::math::Pose3d &_pose);
897 
903  Q_SIGNALS: void GeometryValueChanged(const std::string &_name,
904  const std::string &_value,
905  const ignition::math::Vector3d &_dimensions,
906  const std::string &_uri);
907 
911  Q_SIGNALS: void EnumValueChanged(const QString &_name,
912  const QString &_value);
913 
918  private: bool eventFilter(QObject *_obj, QEvent *_event);
919 
922  private: std::unique_ptr<ConfigWidgetPrivate> dataPtr;
923  };
924  }
925 }
926 #endif
A collapsible widget that holds child widgets.
Definition: ConfigWidget.hh:133
GroupWidget * groupWidget
Pointer to group widget.
Definition: ConfigWidget.hh:77
Forward declarations for the common classes.
Definition: Animation.hh:33
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
static const std::vector< QString > widgetColors
List of colors used for widget areas according to their level.
Definition: ConfigWidget.hh:633
A widget generated from a google protobuf message.
Definition: ConfigWidget.hh:147
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:48
static const QString greenColor
Green color used for "green" or "y" fields.
Definition: ConfigWidget.hh:639
QWidget * geomFilenameLineEdit
A line edit for editing the mesh filename.
Definition: ConfigWidget.hh:100
static const QString blueColor
Blue color used for "blue" or "z" fields.
Definition: ConfigWidget.hh:642
QWidget * geomLengthSpinBox
A spin box for configuring the length of the geometry.
Definition: ConfigWidget.hh:91
QWidget * geomFilenameButton
A button for selecting the mesh filename.
Definition: ConfigWidget.hh:106
static const std::vector< QString > bgColors
List of colors used for the background of widgets according to their level.
Definition: ConfigWidget.hh:630
A convenience widget that also holds pointers to a list of its child widgets.
Definition: ConfigWidget.hh:56
QWidget * childWidget
Child widget that can be collapsed or expanded.
Definition: ConfigWidget.hh:138
static const QString redColor
Red color used for "red" or "x" fields.
Definition: ConfigWidget.hh:636
A widget for configuring enum values.
Definition: ConfigWidget.hh:118
std::string scopedName
Widget&#39;s scoped name within parent config widget.
Definition: ConfigWidget.hh:67
A widget for configuring geometry properties.
Definition: ConfigWidget.hh:82
#define NULL
Definition: CommonTypes.hh:31
QStackedWidget * geomDimensionWidget
A stacked widget containing widgets for configuring geometry dimensions.
Definition: ConfigWidget.hh:88
Defines a color.
Definition: Color.hh:36
QWidget * geomLengthUnitLabel
A label for the unit of the length widget.
Definition: ConfigWidget.hh:97
Definition: ConfigWidget.hh:33
std::map< QWidget *, QLabel * > mapWidgetToUnit
Map a widget to the label holding its unit value.
Definition: ConfigWidget.hh:73
QWidget * geomLengthLabel
A label for the length widget.
Definition: ConfigWidget.hh:94
ConfigChildWidget()
Constructor;.
Definition: ConfigWidget.hh:61
QWidget * geomFilenameLabel
A label for the mesh filename widget.
Definition: ConfigWidget.hh:103
std::string key
Widget&#39;s key value.
Definition: ConfigWidget.hh:64
std::vector< QWidget * > widgets
List of widgets holding values, such as Spins and LineEdits.
Definition: ConfigWidget.hh:70