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/Color.hh>
27#include <ignition/math/Pose3.hh>
28#include <ignition/math/Vector3.hh>
29
30#include "gazebo/gui/qt.h"
31#include "gazebo/util/system.hh"
32
33namespace google
34{
35 namespace protobuf
36 {
37 class Message;
38 class Reflection;
39 class FieldDescriptor;
40 }
41}
42
43namespace 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 OnGeometryTypeChanged(const QString &_text);
111
114 private slots: void OnGeometrySizeChanged(const double _value);
115
117 private slots: void OnSelectFile();
118
120 Q_SIGNALS: void GeometryChanged();
121 };
122
125 class GZ_GUI_VISIBLE DensityConfigWidget : public ConfigChildWidget
126 {
127 Q_OBJECT
128
131
134 public: void SetDensity(const double _density);
135
138 public: double Density() const;
139
142 private slots: void OnComboBoxChanged(const QString &_text);
143
146 private slots: void OnSpinBoxChanged(const QString &_text);
147
150 Q_SIGNALS: void DensityValueChanged(const double &_value);
151
153 public: QComboBox *comboBox;
154
156 public: QDoubleSpinBox *spinBox;
157
159 private: double density;
160 };
161
164 class GZ_GUI_VISIBLE EnumConfigWidget : public ConfigChildWidget
165 {
166 Q_OBJECT
167
170 Q_SIGNALS: void EnumValueChanged(const QString &_value);
171
174 private slots: void EnumChanged(const QString &_value);
175 };
176
179 class GZ_GUI_VISIBLE GroupWidget : public QWidget
180 {
181 Q_OBJECT
182
184 public: QWidget *childWidget;
185
188 private slots: void Toggle(bool _checked);
189 };
190
193 class GZ_GUI_VISIBLE ConfigWidget : public QWidget
194 {
195 Q_OBJECT
196
198 public: ConfigWidget();
199
201 public: ~ConfigWidget();
202
205 public: void Load(const google::protobuf::Message *_msg);
206
209 public: google::protobuf::Message *Msg();
210
215 public: static std::string HumanReadableKey(const std::string &_key);
216
223 public: std::string UnitFromKey(const std::string &_key,
224 const std::string &_jointType = "") const;
225
231 public: void RangeFromKey(const std::string &_key,
232 double &_min, double &_max) const;
233
237 public: void SetWidgetVisible(const std::string &_name, bool _visible);
238
242 public: bool WidgetVisible(const std::string &_name) const;
243
247 public: void SetWidgetReadOnly(const std::string &_name, bool _readOnly);
248
252 public: bool WidgetReadOnly(const std::string &_name) const;
253
256 public: void UpdateFromMsg(const google::protobuf::Message *_msg);
257
262 public: bool SetIntWidgetValue(const std::string &_name, int _value);
263
268 public: bool SetUIntWidgetValue(const std::string &_name, unsigned int
269 _value);
270
275 public: bool SetDoubleWidgetValue(const std::string &_name,
276 double _value);
277
282 public: bool SetBoolWidgetValue(const std::string &_name, bool _value);
283
287 public: bool SetStringWidgetValue(const std::string &_name,
288 const std::string &_value);
289
294 public: bool SetVector3dWidgetValue(const std::string &_name,
295 const ignition::math::Vector3d &_value);
296
301 public: bool SetColorWidgetValue(const std::string &_name,
302 const ignition::math::Color &_value);
303
308 public: bool SetPoseWidgetValue(const std::string &_name,
309 const ignition::math::Pose3d &_value);
310
316 public: bool SetGeometryWidgetValue(const std::string &_name,
317 const std::string &_value,
318 const ignition::math::Vector3d &_dimensions,
319 const std::string &_uri = "");
320
325 public: bool SetDensityWidgetValue(const std::string &_name,
326 const double _value);
327
332 public: bool SetEnumWidgetValue(const std::string &_name,
333 const std::string &_value);
334
339 public: bool AddItemEnumWidget(const std::string &_name,
340 const std::string &_itemText);
341
346 public: bool RemoveItemEnumWidget(const std::string &_name,
347 const std::string &_itemText);
348
352 public: bool ClearEnumWidget(const std::string &_name);
353
357 public: int IntWidgetValue(const std::string &_name) const;
358
362 public: unsigned int UIntWidgetValue(const std::string &_name) const;
363
367 public: double DoubleWidgetValue(const std::string &_name) const;
368
372 public: bool BoolWidgetValue(const std::string &_name) const;
373
377 public: std::string StringWidgetValue(const std::string &_name) const;
378
382 public: ignition::math::Vector3d Vector3dWidgetValue(
383 const std::string &_name) const;
384
388 public: ignition::math::Color ColorWidgetValue(
389 const std::string &_name) const;
390
394 public: ignition::math::Pose3d PoseWidgetValue(
395 const std::string &_name) const;
396
402 public: std::string GeometryWidgetValue(const std::string &_name,
403 ignition::math::Vector3d &_dimensions, std::string &_uri) const;
404
408 public: double DensityWidgetValue(const std::string &_name) const;
409
413 public: std::string EnumWidgetValue(const std::string &_name) const;
414
421 public: GroupWidget *CreateGroupWidget(const std::string &_name,
422 ConfigChildWidget *_childWidget, const int _level = 0);
423
428 public: ConfigChildWidget *CreateUIntWidget(const std::string &_key,
429 const int _level = 0);
430
435 public: ConfigChildWidget *CreateIntWidget(const std::string &_key,
436 const int _level = 0);
437
442 public: ConfigChildWidget *CreateDoubleWidget(const std::string &_key,
443 const int _level = 0);
444
450 public: ConfigChildWidget *CreateStringWidget(const std::string &_key,
451 const int _level = 0, const std::string &_type = "line");
452
457 public: ConfigChildWidget *CreateBoolWidget(const std::string &_key,
458 const int _level = 0);
459
464 public: ConfigChildWidget *CreateVector3dWidget(const std::string &_key,
465 const int _level = 0);
466
471 public: ConfigChildWidget *CreateColorWidget(const std::string &_key,
472 const int _level = 0);
473
478 public: ConfigChildWidget *CreatePoseWidget(const std::string &_key,
479 const int _level = 0);
480
485 public: ConfigChildWidget *CreateGeometryWidget(const std::string &_key,
486 const int _level = 0);
487
493 public: ConfigChildWidget *CreateEnumWidget(const std::string &_key,
494 const std::vector<std::string> &_values, const int _level = 0);
495
500 public: ConfigChildWidget *CreateDensityWidget(const std::string &_key,
501 const int _level = 0);
502
510 public: bool AddConfigChildWidget(const std::string &_name,
511 ConfigChildWidget *_child);
512
517 public: void InsertLayout(QLayout *_layout, int _pos);
518
524 const std::string &_name) const;
525
528 public: unsigned int ConfigChildWidgetCount() const;
529
537 public: static QString StyleSheet(const std::string &_type,
538 const int _level = 0);
539
542 public: static const std::vector<QString> bgColors;
543
545 public: static const std::vector<QString> widgetColors;
546
548 public: static const QString redColor;
549
551 public: static const QString greenColor;
552
554 public: static const QString blueColor;
555
565 private: QWidget *Parse(google::protobuf::Message *_msg,
566 bool _update = false, const std::string &_name = "",
567 const int _level = 0);
568
572 private: ignition::math::Vector3d ParseVector3d(
573 const google::protobuf::Message *_msg) const;
574
578 private: void UpdateMsg(google::protobuf::Message *_msg,
579 const std::string &_name = "");
580
585 private: void UpdateVector3dMsg(google::protobuf::Message *_msg,
586 const ignition::math::Vector3d &_value);
587
592 private: bool UpdateUIntWidget(ConfigChildWidget *_widget,
593 const unsigned int _value);
594
599 private: bool UpdateIntWidget(ConfigChildWidget *_widget,
600 const int _value);
601
606 private: bool UpdateDoubleWidget(ConfigChildWidget *_widget,
607 const double _value);
608
613 private: bool UpdateStringWidget(ConfigChildWidget *_widget,
614 const std::string &_value);
615
620 private: bool UpdateBoolWidget(ConfigChildWidget *_widget,
621 const bool _value);
622
627 private: bool UpdateVector3dWidget(ConfigChildWidget *_widget,
628 const ignition::math::Vector3d &_value);
629
634 private: bool UpdateColorWidget(ConfigChildWidget *_widget,
635 const ignition::math::Color &_value);
636
641 private: bool UpdatePoseWidget(ConfigChildWidget *_widget,
642 const ignition::math::Pose3d &_value);
643
650 private: bool UpdateGeometryWidget(ConfigChildWidget *_widget,
651 const std::string &_value,
652 const ignition::math::Vector3d &_dimensions,
653 const std::string &_uri = "");
654
659 private: bool UpdateEnumWidget(ConfigChildWidget *_widget,
660 const std::string &_value);
661
666 private: bool UpdateDensityWidget(ConfigChildWidget *_widget,
667 const double _value);
668
672 private: int IntWidgetValue(ConfigChildWidget *_widget) const;
673
677 private: unsigned int UIntWidgetValue(ConfigChildWidget *_widget) const;
678
682 private: double DoubleWidgetValue(ConfigChildWidget *_widget) const;
683
687 private: bool BoolWidgetValue(ConfigChildWidget *_widget) const;
688
692 private: std::string StringWidgetValue(ConfigChildWidget *_widget) const;
693
697 private: ignition::math::Vector3d Vector3dWidgetValue(
698 ConfigChildWidget *_widget) const;
699
703 private: ignition::math::Color ColorWidgetValue(
704 ConfigChildWidget *_widget) const;
705
709 private: ignition::math::Pose3d PoseWidgetValue(
710 ConfigChildWidget *_widget) const;
711
717 private: std::string GeometryWidgetValue(ConfigChildWidget *_widget,
718 ignition::math::Vector3d &_dimensions, std::string &_uri) const;
719
723 private: std::string EnumWidgetValue(ConfigChildWidget *_widget) const;
724
728 private slots: void OnItemSelection(QTreeWidgetItem *_item,
729 const int _column);
730
732 private slots: void OnUIntValueChanged();
733
735 private slots: void OnIntValueChanged();
736
738 private slots: void OnDoubleValueChanged();
739
741 private slots: void OnBoolValueChanged();
742
744 private slots: void OnStringValueChanged();
745
747 private slots: void OnVector3dValueChanged();
748
751 private slots: void OnVector3dPresetChanged(const int _index);
752
754 private slots: void OnColorValueChanged();
755
759 private slots: void OnColorValueChanged(const QColor _value);
760
762 private slots: void OnPoseValueChanged();
763
765 private slots: void OnGeometryValueChanged();
766
769 private slots: void OnGeometryValueChanged(const int _value);
770
773 private slots: void OnEnumValueChanged(const QString &_value);
774
777 private slots: void OnCustomColorDialog();
778
782 Q_SIGNALS: void UIntValueChanged(const QString &_name,
783 const unsigned int _value);
784
788 Q_SIGNALS: void IntValueChanged(const QString &_name, const int _value);
789
793 Q_SIGNALS: void DoubleValueChanged(const QString &_name,
794 const double _value);
795
799 Q_SIGNALS: void BoolValueChanged(const QString &_name,
800 const bool _value);
801
807 Q_SIGNALS: void StringValueChanged(const QString &_name,
808 const std::string &_value);
809
813 Q_SIGNALS: void Vector3dValueChanged(const QString &_name,
814 const ignition::math::Vector3d &_value);
815
819 Q_SIGNALS: void ColorValueChanged(const QString &_name,
820 const ignition::math::Color &_value);
821
825 Q_SIGNALS: void PoseValueChanged(const QString &_name,
826 const ignition::math::Pose3d &_pose);
827
833 Q_SIGNALS: void GeometryValueChanged(const std::string &_name,
834 const std::string &_value,
835 const ignition::math::Vector3d &_dimensions,
836 const std::string &_uri);
837
841 Q_SIGNALS: void EnumValueChanged(const QString &_name,
842 const QString &_value);
843
846 Q_SIGNALS: void DensityValueChanged(const double &_value);
847
850 Q_SIGNALS: void MassValueChanged(const double &_value);
851
854 private slots: void OnDensityValueChanged(const double _value);
855
858 private slots: void OnMassValueChanged(const double _value);
859
861 private slots: void OnGeometryChanged();
862
864 Q_SIGNALS: void GeometryChanged();
865
870 private: bool eventFilter(QObject *_obj, QEvent *_event);
871
874 private: std::unique_ptr<ConfigWidgetPrivate> dataPtr;
875 };
876 }
877}
878#endif
#define NULL
Definition CommonTypes.hh:31
gui
Definition KeyEventHandler.hh:29
A convenience widget that also holds pointers to a list of its child widgets.
Definition ConfigWidget.hh:57
A widget generated from a google protobuf message.
Definition ConfigWidget.hh:194
A widget for configuring density properties.
Definition ConfigWidget.hh:126
A widget for configuring enum values.
Definition ConfigWidget.hh:165
A widget for configuring geometry properties.
Definition ConfigWidget.hh:83
A collapsible widget that holds child widgets.
Definition ConfigWidget.hh:180
bool SetDoubleWidgetValue(const std::string &_name, double _value)
Set a double value to a child widget.
std::string UnitFromKey(const std::string &_key, const std::string &_jointType="") const
Returns the unit for a given key.
void EnumValueChanged(const QString &_name, const QString &_value)
Signal that an enum config widget's enum value has changed.
static const QString redColor
Red color used for "red" or "x" fields.
Definition ConfigWidget.hh:548
void StringValueChanged(const QString &_name, const std::string &_value)
Signal that a string config widget's value has changed.
ConfigChildWidget * CreateVector3dWidget(const std::string &_key, const int _level=0)
Create a widget for configuring a vector3 value.
QComboBox * comboBox
A combo box for selecting a material density.
Definition ConfigWidget.hh:153
bool SetVector3dWidgetValue(const std::string &_name, const ignition::math::Vector3d &_value)
Set a vector3 value to a child widget.
std::vector< QWidget * > widgets
List of widgets holding values, such as Spins and LineEdits.
Definition ConfigWidget.hh:70
void EnumValueChanged(const QString &_value)
brief Signal an enum value change event.
ConfigWidget()
Constructor.
std::string StringWidgetValue(const std::string &_name) const
Get a string value from a child widget.
static const QString blueColor
Blue color used for "blue" or "z" fields.
Definition ConfigWidget.hh:554
static const std::vector< QString > bgColors
List of colors used for the background of widgets according to their level.
Definition ConfigWidget.hh:542
void UIntValueChanged(const QString &_name, const unsigned int _value)
Signal that a uint config widget's value has changed.
ConfigChildWidget * CreateEnumWidget(const std::string &_key, const std::vector< std::string > &_values, const int _level=0)
Create a widget for configuring an enum value.
void SetDensity(const double _density)
Updates the widget's density value.
void PoseValueChanged(const QString &_name, const ignition::math::Pose3d &_pose)
Signal that a pose config widget's value has changed.
static QString StyleSheet(const std::string &_type, const int _level=0)
Get a style sheet in string format, to be applied to a child config widget with setStyleSheet.
ConfigChildWidget * CreateGeometryWidget(const std::string &_key, const int _level=0)
Create a widget for configuring a geometry value.
double DoubleWidgetValue(const std::string &_name) const
Get a double value from a child widget.
bool WidgetVisible(const std::string &_name) const
Get whether a child widget is visible.
bool SetEnumWidgetValue(const std::string &_name, const std::string &_value)
Set an enum value to a child widget.
ConfigChildWidget * CreateUIntWidget(const std::string &_key, const int _level=0)
Create a widget for configuring an unsigned integer value.
ignition::math::Color ColorWidgetValue(const std::string &_name) const
Get a color value from a child widget.
QWidget * geomFilenameLineEdit
A line edit for editing the mesh filename.
Definition ConfigWidget.hh:100
ConfigChildWidget * ConfigChildWidgetByName(const std::string &_name) const
Get a config child widget by its name.
void DoubleValueChanged(const QString &_name, const double _value)
Signal that a double config widget's value has changed.
int IntWidgetValue(const std::string &_name) const
Get an integer value from a child widget.
QWidget * geomLengthLabel
A label for the length widget.
Definition ConfigWidget.hh:94
bool ClearEnumWidget(const std::string &_name)
Remove all items from a child enum widget.
std::map< QWidget *, QLabel * > mapWidgetToUnit
Map a widget to the label holding its unit value.
Definition ConfigWidget.hh:73
ConfigChildWidget * CreateIntWidget(const std::string &_key, const int _level=0)
Create a widget for configuring an integer value.
static std::string HumanReadableKey(const std::string &_key)
Create a human readable key, capitalizing the first letter and removing characters like "_".
void ColorValueChanged(const QString &_name, const ignition::math::Color &_value)
Signal that a color config widget's value has changed.
QWidget * geomFilenameButton
A button for selecting the mesh filename.
Definition ConfigWidget.hh:106
void BoolValueChanged(const QString &_name, const bool _value)
Signal that a bool config widget's value has changed.
double Density() const
Accessor for the widget's density value.
void SetWidgetReadOnly(const std::string &_name, bool _readOnly)
Set whether a child widget should be read-only.
void Load(const google::protobuf::Message *_msg)
Load from a google protobuf message.
static const std::vector< QString > widgetColors
List of colors used for widget areas according to their level.
Definition ConfigWidget.hh:545
bool AddItemEnumWidget(const std::string &_name, const std::string &_itemText)
Add an item to a child enum widget.
ConfigChildWidget()
Constructor;.
Definition ConfigWidget.hh:61
ConfigChildWidget * CreateColorWidget(const std::string &_key, const int _level=0)
Create a widget for configuring a color value.
google::protobuf::Message * Msg()
Get the updated message.
void InsertLayout(QLayout *_layout, int _pos)
Insert a layout into the config widget's layout at a specific position.
bool AddConfigChildWidget(const std::string &_name, ConfigChildWidget *_child)
Register a child widget as a child of this widget, so it can be updated.
ConfigChildWidget * CreatePoseWidget(const std::string &_key, const int _level=0)
Create a widget for configuring a pose value.
ConfigChildWidget * CreateDoubleWidget(const std::string &_key, const int _level=0)
Create a widget for configuring a double value.
ignition::math::Vector3d Vector3dWidgetValue(const std::string &_name) const
Get a vector3 value from a child widget.
QWidget * geomLengthUnitLabel
A label for the unit of the length widget.
Definition ConfigWidget.hh:97
void UpdateFromMsg(const google::protobuf::Message *_msg)
Update the widgets from a message.
bool SetGeometryWidgetValue(const std::string &_name, const std::string &_value, const ignition::math::Vector3d &_dimensions, const std::string &_uri="")
Set a geometry value to a child widget.
QDoubleSpinBox * spinBox
A spin box for entering a density value.
Definition ConfigWidget.hh:156
QWidget * geomLengthSpinBox
A spin box for configuring the length of the geometry.
Definition ConfigWidget.hh:91
bool BoolWidgetValue(const std::string &_name) const
Get a bool value from a child widget.
bool RemoveItemEnumWidget(const std::string &_name, const std::string &_itemText)
Remove an item from a child enum widget.
QWidget * geomFilenameLabel
A label for the mesh filename widget.
Definition ConfigWidget.hh:103
std::string key
Widget's key value.
Definition ConfigWidget.hh:64
QStackedWidget * geomDimensionWidget
A stacked widget containing widgets for configuring geometry dimensions.
Definition ConfigWidget.hh:88
ConfigChildWidget * CreateBoolWidget(const std::string &_key, const int _level=0)
Create a widget for configuring a bool value.
void RangeFromKey(const std::string &_key, double &_min, double &_max) const
Returns the range for a given key.
void DensityValueChanged(const double &_value)
Signal emitted when density has changed.
ConfigChildWidget * CreateStringWidget(const std::string &_key, const int _level=0, const std::string &_type="line")
Create a widget for configuring a string value.
bool SetPoseWidgetValue(const std::string &_name, const ignition::math::Pose3d &_value)
Set a pose value to a child widget.
unsigned int ConfigChildWidgetCount() const
Get the number of child widgets.
bool SetColorWidgetValue(const std::string &_name, const ignition::math::Color &_value)
Set a color value to a child widget.
bool SetStringWidgetValue(const std::string &_name, const std::string &_value)
Set a string value to a child widget.
void SetWidgetVisible(const std::string &_name, bool _visible)
Set whether a child widget should be visible.
static const QString greenColor
Green color used for "green" or "y" fields.
Definition ConfigWidget.hh:551
GroupWidget * CreateGroupWidget(const std::string &_name, ConfigChildWidget *_childWidget, const int _level=0)
Create a widget which has a button header which collapses the field widget.
QWidget * childWidget
Child widget that can be collapsed or expanded.
Definition ConfigWidget.hh:184
ignition::math::Pose3d PoseWidgetValue(const std::string &_name) const
Get a pose value from a child widget.
std::string GeometryWidgetValue(const std::string &_name, ignition::math::Vector3d &_dimensions, std::string &_uri) const
Get a geometry value from a child widget.
void MassValueChanged(const double &_value)
Signal emitted when mass value changes.
bool SetDensityWidgetValue(const std::string &_name, const double _value)
Set a density value to a child widget.
void GeometryChanged()
Signal emitted when geometry changes.
bool SetIntWidgetValue(const std::string &_name, int _value)
Set an integer value to a child widget.
void IntValueChanged(const QString &_name, const int _value)
Signal that an int config widget's value has changed.
bool SetBoolWidgetValue(const std::string &_name, bool _value)
Set a bool value to a child widget.
std::string scopedName
Widget's scoped name within parent config widget.
Definition ConfigWidget.hh:67
unsigned int UIntWidgetValue(const std::string &_name) const
Get an unsigned integer value from a child widget.
ConfigChildWidget * CreateDensityWidget(const std::string &_key, const int _level=0)
Create a widget for setting a density value.
void Vector3dValueChanged(const QString &_name, const ignition::math::Vector3d &_value)
Signal that a vector3 config widget's value has changed.
bool SetUIntWidgetValue(const std::string &_name, unsigned int _value)
Set an unsigned integer value to a child widget.
bool WidgetReadOnly(const std::string &_name) const
Get whether a child widget is read-only.
double DensityWidgetValue(const std::string &_name) const
Get a density value from a child widget.
void GeometryValueChanged(const std::string &_name, const std::string &_value, const ignition::math::Vector3d &_dimensions, const std::string &_uri)
Signal that a geometry config widget's value has changed.
std::string EnumWidgetValue(const std::string &_name) const
Get an enum value from a child widget.
GroupWidget * groupWidget
Pointer to group widget.
Definition ConfigWidget.hh:77
Forward declarations for the common classes.
Definition Animation.hh:27
Definition ConfigWidget.hh:34