ConfigWidget.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 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/gui/qt.h"
31 
32 namespace google
33 {
34  namespace protobuf
35  {
36  class Message;
37  class Reflection;
38  class FieldDescriptor;
39  }
40 }
41 
42 namespace gazebo
43 {
44  namespace gui
45  {
46  class ConfigWidgetPrivate;
47  class GroupWidget;
48 
51 
55  class GZ_GUI_VISIBLE ConfigChildWidget : public QFrame
56  {
57  Q_OBJECT
58 
60  public: ConfigChildWidget() : groupWidget(NULL) {}
61 
63  public: std::string key;
64 
66  public: std::string scopedName;
67 
69  public: std::vector<QWidget *> widgets;
70 
72  public: std::map<QWidget *, QLabel *> mapWidgetToUnit;
73 
77  };
78 
81  class GZ_GUI_VISIBLE GeometryConfigWidget : public ConfigChildWidget
82  {
83  Q_OBJECT
84 
87  public: QStackedWidget *geomDimensionWidget;
88 
90  public: QWidget *geomLengthSpinBox;
91 
93  public: QWidget *geomLengthLabel;
94 
96  public: QWidget *geomLengthUnitLabel;
97 
99  public: QWidget *geomFilenameLineEdit;
100 
102  public: QWidget *geomFilenameLabel;
103 
105  public: QWidget *geomFilenameButton;
106 
109  private slots: void OnGeometryTypeChanged(const QString &_text);
110 
113  private slots: void OnGeometrySizeChanged(const double _value);
114 
116  private slots: void OnSelectFile();
117 
119  Q_SIGNALS: void GeometryChanged();
120  };
121 
124  class GZ_GUI_VISIBLE DensityConfigWidget : public ConfigChildWidget
125  {
126  Q_OBJECT
127 
129  public: DensityConfigWidget();
130 
133  public: void SetDensity(const double _density);
134 
137  public: double Density() const;
138 
141  private slots: void OnComboBoxChanged(const QString &_text);
142 
145  private slots: void OnSpinBoxChanged(const QString &_text);
146 
149  Q_SIGNALS: void DensityValueChanged(const double &_value);
150 
152  public: QComboBox *comboBox;
153 
155  public: QDoubleSpinBox *spinBox;
156 
158  private: double density;
159  };
160 
163  class GZ_GUI_VISIBLE EnumConfigWidget : public ConfigChildWidget
164  {
165  Q_OBJECT
166 
169  Q_SIGNALS: void EnumValueChanged(const QString &_value);
170 
173  private slots: void EnumChanged(const QString &_value);
174  };
175 
178  class GZ_GUI_VISIBLE GroupWidget : public QWidget
179  {
180  Q_OBJECT
181 
183  public: QWidget *childWidget;
184 
187  private slots: void Toggle(bool _checked);
188  };
189 
192  class GZ_GUI_VISIBLE ConfigWidget : public QWidget
193  {
194  Q_OBJECT
195 
197  public: ConfigWidget();
198 
200  public: ~ConfigWidget();
201 
204  public: void Load(const google::protobuf::Message *_msg);
205 
208  public: google::protobuf::Message *Msg();
209 
214  public: static std::string HumanReadableKey(const std::string &_key);
215 
222  public: std::string UnitFromKey(const std::string &_key,
223  const std::string &_jointType = "") const;
224 
230  public: void RangeFromKey(const std::string &_key,
231  double &_min, double &_max) const;
232 
236  public: void SetWidgetVisible(const std::string &_name, bool _visible);
237 
241  public: bool WidgetVisible(const std::string &_name) const;
242 
246  public: void SetWidgetReadOnly(const std::string &_name, bool _readOnly);
247 
251  public: bool WidgetReadOnly(const std::string &_name) const;
252 
255  public: void UpdateFromMsg(const google::protobuf::Message *_msg);
256 
261  public: bool SetIntWidgetValue(const std::string &_name, int _value);
262 
267  public: bool SetUIntWidgetValue(const std::string &_name, unsigned int
268  _value);
269 
274  public: bool SetDoubleWidgetValue(const std::string &_name,
275  double _value);
276 
281  public: bool SetBoolWidgetValue(const std::string &_name, bool _value);
282 
286  public: bool SetStringWidgetValue(const std::string &_name,
287  const std::string &_value);
288 
293  public: bool SetVector3dWidgetValue(const std::string &_name,
294  const ignition::math::Vector3d &_value);
295 
300  public: bool SetColorWidgetValue(const std::string &_name,
301  const common::Color &_value);
302 
307  public: bool SetPoseWidgetValue(const std::string &_name,
308  const ignition::math::Pose3d &_value);
309 
315  public: bool SetGeometryWidgetValue(const std::string &_name,
316  const std::string &_value,
317  const ignition::math::Vector3d &_dimensions,
318  const std::string &_uri = "");
319 
324  public: bool SetDensityWidgetValue(const std::string &_name,
325  const double _value);
326 
331  public: bool SetEnumWidgetValue(const std::string &_name,
332  const std::string &_value);
333 
338  public: bool AddItemEnumWidget(const std::string &_name,
339  const std::string &_itemText);
340 
345  public: bool RemoveItemEnumWidget(const std::string &_name,
346  const std::string &_itemText);
347 
351  public: bool ClearEnumWidget(const std::string &_name);
352 
356  public: int IntWidgetValue(const std::string &_name) const;
357 
361  public: unsigned int UIntWidgetValue(const std::string &_name) const;
362 
366  public: double DoubleWidgetValue(const std::string &_name) const;
367 
371  public: bool BoolWidgetValue(const std::string &_name) const;
372 
376  public: std::string StringWidgetValue(const std::string &_name) const;
377 
381  public: ignition::math::Vector3d Vector3dWidgetValue(
382  const std::string &_name) const;
383 
387  public: common::Color ColorWidgetValue(const std::string &_name) const;
388 
392  public: ignition::math::Pose3d PoseWidgetValue(
393  const std::string &_name) const;
394 
400  public: std::string GeometryWidgetValue(const std::string &_name,
401  ignition::math::Vector3d &_dimensions, std::string &_uri) const;
402 
406  public: double DensityWidgetValue(const std::string &_name) const;
407 
411  public: std::string EnumWidgetValue(const std::string &_name) const;
412 
419  public: GroupWidget *CreateGroupWidget(const std::string &_name,
420  ConfigChildWidget *_childWidget, const int _level = 0);
421 
426  public: ConfigChildWidget *CreateUIntWidget(const std::string &_key,
427  const int _level = 0);
428 
433  public: ConfigChildWidget *CreateIntWidget(const std::string &_key,
434  const int _level = 0);
435 
440  public: ConfigChildWidget *CreateDoubleWidget(const std::string &_key,
441  const int _level = 0);
442 
448  public: ConfigChildWidget *CreateStringWidget(const std::string &_key,
449  const int _level = 0, const std::string &_type = "line");
450 
455  public: ConfigChildWidget *CreateBoolWidget(const std::string &_key,
456  const int _level = 0);
457 
462  public: ConfigChildWidget *CreateVector3dWidget(const std::string &_key,
463  const int _level = 0);
464 
469  public: ConfigChildWidget *CreateColorWidget(const std::string &_key,
470  const int _level = 0);
471 
476  public: ConfigChildWidget *CreatePoseWidget(const std::string &_key,
477  const int _level = 0);
478 
483  public: ConfigChildWidget *CreateGeometryWidget(const std::string &_key,
484  const int _level = 0);
485 
491  public: ConfigChildWidget *CreateEnumWidget(const std::string &_key,
492  const std::vector<std::string> &_values, const int _level = 0);
493 
498  public: ConfigChildWidget *CreateDensityWidget(const std::string &_key,
499  const int _level = 0);
500 
508  public: bool AddConfigChildWidget(const std::string &_name,
509  ConfigChildWidget *_child);
510 
515  public: void InsertLayout(QLayout *_layout, int _pos);
516 
521  public: ConfigChildWidget *ConfigChildWidgetByName(
522  const std::string &_name) const;
523 
526  public: unsigned int ConfigChildWidgetCount() const;
527 
535  public: static QString StyleSheet(const std::string &_type,
536  const int _level = 0);
537 
540  public: static const std::vector<QString> bgColors;
541 
543  public: static const std::vector<QString> widgetColors;
544 
546  public: static const QString redColor;
547 
549  public: static const QString greenColor;
550 
552  public: static const QString blueColor;
553 
563  private: QWidget *Parse(google::protobuf::Message *_msg,
564  bool _update = false, const std::string &_name = "",
565  const int _level = 0);
566 
570  private: ignition::math::Vector3d ParseVector3d(
571  const google::protobuf::Message *_msg) const;
572 
576  private: void UpdateMsg(google::protobuf::Message *_msg,
577  const std::string &_name = "");
578 
583  private: void UpdateVector3dMsg(google::protobuf::Message *_msg,
584  const ignition::math::Vector3d &_value);
585 
590  private: bool UpdateUIntWidget(ConfigChildWidget *_widget,
591  const unsigned int _value);
592 
597  private: bool UpdateIntWidget(ConfigChildWidget *_widget,
598  const int _value);
599 
604  private: bool UpdateDoubleWidget(ConfigChildWidget *_widget,
605  const double _value);
606 
611  private: bool UpdateStringWidget(ConfigChildWidget *_widget,
612  const std::string &_value);
613 
618  private: bool UpdateBoolWidget(ConfigChildWidget *_widget,
619  const bool _value);
620 
625  private: bool UpdateVector3dWidget(ConfigChildWidget *_widget,
626  const ignition::math::Vector3d &_value);
627 
632  private: bool UpdateColorWidget(ConfigChildWidget *_widget,
633  const common::Color &_value);
634 
639  private: bool UpdatePoseWidget(ConfigChildWidget *_widget,
640  const ignition::math::Pose3d &_value);
641 
648  private: bool UpdateGeometryWidget(ConfigChildWidget *_widget,
649  const std::string &_value,
650  const ignition::math::Vector3d &_dimensions,
651  const std::string &_uri = "");
652 
657  private: bool UpdateEnumWidget(ConfigChildWidget *_widget,
658  const std::string &_value);
659 
664  private: bool UpdateDensityWidget(ConfigChildWidget *_widget,
665  const double _value);
666 
670  private: int IntWidgetValue(ConfigChildWidget *_widget) const;
671 
675  private: unsigned int UIntWidgetValue(ConfigChildWidget *_widget) const;
676 
680  private: double DoubleWidgetValue(ConfigChildWidget *_widget) const;
681 
685  private: bool BoolWidgetValue(ConfigChildWidget *_widget) const;
686 
690  private: std::string StringWidgetValue(ConfigChildWidget *_widget) const;
691 
695  private: ignition::math::Vector3d Vector3dWidgetValue(
696  ConfigChildWidget *_widget) const;
697 
701  private: common::Color ColorWidgetValue(ConfigChildWidget *_widget) const;
702 
706  private: ignition::math::Pose3d PoseWidgetValue(
707  ConfigChildWidget *_widget) const;
708 
714  private: std::string GeometryWidgetValue(ConfigChildWidget *_widget,
715  ignition::math::Vector3d &_dimensions, std::string &_uri) const;
716 
720  private: std::string EnumWidgetValue(ConfigChildWidget *_widget) const;
721 
725  private slots: void OnItemSelection(QTreeWidgetItem *_item,
726  const int _column);
727 
729  private slots: void OnUIntValueChanged();
730 
732  private slots: void OnIntValueChanged();
733 
735  private slots: void OnDoubleValueChanged();
736 
738  private slots: void OnBoolValueChanged();
739 
741  private slots: void OnStringValueChanged();
742 
744  private slots: void OnVector3dValueChanged();
745 
748  private slots: void OnVector3dPresetChanged(const int _index);
749 
751  private slots: void OnColorValueChanged();
752 
756  private slots: void OnColorValueChanged(const QColor _value);
757 
759  private slots: void OnPoseValueChanged();
760 
762  private slots: void OnGeometryValueChanged();
763 
766  private slots: void OnGeometryValueChanged(const int _value);
767 
770  private slots: void OnEnumValueChanged(const QString &_value);
771 
774  private slots: void OnCustomColorDialog();
775 
779  Q_SIGNALS: void UIntValueChanged(const QString &_name,
780  const unsigned int _value);
781 
785  Q_SIGNALS: void IntValueChanged(const QString &_name, const int _value);
786 
790  Q_SIGNALS: void DoubleValueChanged(const QString &_name,
791  const double _value);
792 
796  Q_SIGNALS: void BoolValueChanged(const QString &_name,
797  const bool _value);
798 
804  Q_SIGNALS: void StringValueChanged(const QString &_name,
805  const std::string &_value);
806 
810  Q_SIGNALS: void Vector3dValueChanged(const QString &_name,
811  const ignition::math::Vector3d &_value);
812 
816  Q_SIGNALS: void ColorValueChanged(const QString &_name,
817  const gazebo::common::Color &_value);
818 
822  Q_SIGNALS: void PoseValueChanged(const QString &_name,
823  const ignition::math::Pose3d &_pose);
824 
830  Q_SIGNALS: void GeometryValueChanged(const std::string &_name,
831  const std::string &_value,
832  const ignition::math::Vector3d &_dimensions,
833  const std::string &_uri);
834 
838  Q_SIGNALS: void EnumValueChanged(const QString &_name,
839  const QString &_value);
840 
843  Q_SIGNALS: void DensityValueChanged(const double &_value);
844 
847  Q_SIGNALS: void MassValueChanged(const double &_value);
848 
851  private slots: void OnDensityValueChanged(const double _value);
852 
855  private slots: void OnMassValueChanged(const double _value);
856 
858  private slots: void OnGeometryChanged();
859 
861  Q_SIGNALS: void GeometryChanged();
862 
867  private: bool eventFilter(QObject *_obj, QEvent *_event);
868 
871  private: std::unique_ptr<ConfigWidgetPrivate> dataPtr;
872  };
873  }
874 }
875 #endif
A collapsible widget that holds child widgets.
Definition: ConfigWidget.hh:178
T T _min
Definition: Helpers.hh:130
QComboBox * comboBox
A combo box for selecting a material density.
Definition: ConfigWidget.hh:152
T T T _max
Definition: Helpers.hh:131
GroupWidget * groupWidget
Pointer to group widget.
Definition: ConfigWidget.hh:76
Forward declarations for the common classes.
Definition: Animation.hh:33
static const std::vector< QString > widgetColors
List of colors used for widget areas according to their level.
Definition: ConfigWidget.hh:543
A widget generated from a google protobuf message.
Definition: ConfigWidget.hh:192
static const QString greenColor
Green color used for "green" or "y" fields.
Definition: ConfigWidget.hh:549
QWidget * geomFilenameLineEdit
A line edit for editing the mesh filename.
Definition: ConfigWidget.hh:99
static const QString blueColor
Blue color used for "blue" or "z" fields.
Definition: ConfigWidget.hh:552
QWidget * geomLengthSpinBox
A spin box for configuring the length of the geometry.
Definition: ConfigWidget.hh:90
QWidget * geomFilenameButton
A button for selecting the mesh filename.
Definition: ConfigWidget.hh:105
static const std::vector< QString > bgColors
List of colors used for the background of widgets according to their level.
Definition: ConfigWidget.hh:540
A convenience widget that also holds pointers to a list of its child widgets.
Definition: ConfigWidget.hh:55
QWidget * childWidget
Child widget that can be collapsed or expanded.
Definition: ConfigWidget.hh:183
static const QString redColor
Red color used for "red" or "x" fields.
Definition: ConfigWidget.hh:546
A widget for configuring enum values.
Definition: ConfigWidget.hh:163
std::string scopedName
Widget&#39;s scoped name within parent config widget.
Definition: ConfigWidget.hh:66
QDoubleSpinBox * spinBox
A spin box for entering a density value.
Definition: ConfigWidget.hh:155
A widget for configuring geometry properties.
Definition: ConfigWidget.hh:81
#define NULL
Definition: CommonTypes.hh:31
QStackedWidget * geomDimensionWidget
A stacked widget containing widgets for configuring geometry dimensions.
Definition: ConfigWidget.hh:87
Defines a color.
Definition: Color.hh:35
QWidget * geomLengthUnitLabel
A label for the unit of the length widget.
Definition: ConfigWidget.hh:96
Definition: ConfigWidget.hh:32
std::map< QWidget *, QLabel * > mapWidgetToUnit
Map a widget to the label holding its unit value.
Definition: ConfigWidget.hh:72
QWidget * geomLengthLabel
A label for the length widget.
Definition: ConfigWidget.hh:93
ConfigChildWidget()
Constructor;.
Definition: ConfigWidget.hh:60
A widget for configuring density properties.
Definition: ConfigWidget.hh:124
QWidget * geomFilenameLabel
A label for the mesh filename widget.
Definition: ConfigWidget.hh:102
std::string key
Widget&#39;s key value.
Definition: ConfigWidget.hh:63
std::vector< QWidget * > widgets
List of widgets holding values, such as Spins and LineEdits.
Definition: ConfigWidget.hh:69