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 
582  private: void UpdateVector3dMsg(google::protobuf::Message *_msg,
583  const ignition::math::Vector3d &_value);
584 
589  private: bool UpdateUIntWidget(ConfigChildWidget *_widget,
590  const unsigned int _value);
591 
596  private: bool UpdateIntWidget(ConfigChildWidget *_widget,
597  const int _value);
598 
603  private: bool UpdateDoubleWidget(ConfigChildWidget *_widget,
604  const double _value);
605 
610  private: bool UpdateStringWidget(ConfigChildWidget *_widget,
611  const std::string &_value);
612 
617  private: bool UpdateBoolWidget(ConfigChildWidget *_widget,
618  const bool _value);
619 
624  private: bool UpdateVector3dWidget(ConfigChildWidget *_widget,
625  const ignition::math::Vector3d &_value);
626 
631  private: bool UpdateColorWidget(ConfigChildWidget *_widget,
632  const common::Color &_value);
633 
638  private: bool UpdatePoseWidget(ConfigChildWidget *_widget,
639  const ignition::math::Pose3d &_value);
640 
647  private: bool UpdateGeometryWidget(ConfigChildWidget *_widget,
648  const std::string &_value,
649  const ignition::math::Vector3d &_dimensions,
650  const std::string &_uri = "");
651 
656  private: bool UpdateEnumWidget(ConfigChildWidget *_widget,
657  const std::string &_value);
658 
663  private: bool UpdateDensityWidget(ConfigChildWidget *_widget,
664  const double _value);
665 
669  private: int IntWidgetValue(ConfigChildWidget *_widget) const;
670 
674  private: unsigned int UIntWidgetValue(ConfigChildWidget *_widget) const;
675 
679  private: double DoubleWidgetValue(ConfigChildWidget *_widget) const;
680 
684  private: bool BoolWidgetValue(ConfigChildWidget *_widget) const;
685 
689  private: std::string StringWidgetValue(ConfigChildWidget *_widget) const;
690 
694  private: ignition::math::Vector3d Vector3dWidgetValue(
695  ConfigChildWidget *_widget) const;
696 
700  private: common::Color ColorWidgetValue(ConfigChildWidget *_widget) const;
701 
705  private: ignition::math::Pose3d PoseWidgetValue(
706  ConfigChildWidget *_widget) const;
707 
713  private: std::string GeometryWidgetValue(ConfigChildWidget *_widget,
714  ignition::math::Vector3d &_dimensions, std::string &_uri) const;
715 
719  private: std::string EnumWidgetValue(ConfigChildWidget *_widget) const;
720 
724  private slots: void OnItemSelection(QTreeWidgetItem *_item,
725  const int _column);
726 
728  private slots: void OnUIntValueChanged();
729 
731  private slots: void OnIntValueChanged();
732 
734  private slots: void OnDoubleValueChanged();
735 
737  private slots: void OnBoolValueChanged();
738 
740  private slots: void OnStringValueChanged();
741 
743  private slots: void OnVector3dValueChanged();
744 
747  private slots: void OnVector3dPresetChanged(const int _index);
748 
750  private slots: void OnColorValueChanged();
751 
755  private slots: void OnColorValueChanged(const QColor _value);
756 
758  private slots: void OnPoseValueChanged();
759 
761  private slots: void OnGeometryValueChanged();
762 
765  private slots: void OnGeometryValueChanged(const int _value);
766 
769  private slots: void OnEnumValueChanged(const QString &_value);
770 
773  private slots: void OnCustomColorDialog();
774 
778  Q_SIGNALS: void UIntValueChanged(const QString &_name,
779  const unsigned int _value);
780 
784  Q_SIGNALS: void IntValueChanged(const QString &_name, const int _value);
785 
789  Q_SIGNALS: void DoubleValueChanged(const QString &_name,
790  const double _value);
791 
795  Q_SIGNALS: void BoolValueChanged(const QString &_name,
796  const bool _value);
797 
803  Q_SIGNALS: void StringValueChanged(const QString &_name,
804  const std::string &_value);
805 
809  Q_SIGNALS: void Vector3dValueChanged(const QString &_name,
810  const ignition::math::Vector3d &_value);
811 
815  Q_SIGNALS: void ColorValueChanged(const QString &_name,
816  const gazebo::common::Color &_value);
817 
821  Q_SIGNALS: void PoseValueChanged(const QString &_name,
822  const ignition::math::Pose3d &_pose);
823 
829  Q_SIGNALS: void GeometryValueChanged(const std::string &_name,
830  const std::string &_value,
831  const ignition::math::Vector3d &_dimensions,
832  const std::string &_uri);
833 
837  Q_SIGNALS: void EnumValueChanged(const QString &_name,
838  const QString &_value);
839 
842  Q_SIGNALS: void DensityValueChanged(const double &_value);
843 
846  Q_SIGNALS: void MassValueChanged(const double &_value);
847 
850  private slots: void OnDensityValueChanged(const double _value);
851 
854  private slots: void OnMassValueChanged(const double _value);
855 
857  private slots: void OnGeometryChanged();
858 
860  Q_SIGNALS: void GeometryChanged();
861 
866  private: bool eventFilter(QObject *_obj, QEvent *_event);
867 
870  private: std::unique_ptr<ConfigWidgetPrivate> dataPtr;
871  };
872  }
873 }
874 #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:36
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