parameter_widget.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement
4  *
5  * Copyright (c) 2020,
6  * TU Dortmund - Institute of Control Theory and Systems Engineering.
7  * All rights reserved.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  *
22  * Authors: Christoph Rösmann
23  *********************************************************************/
24 
25 #ifndef SRC_GUI_INCLUDE_CORBO_GUI_PARAMETER_WIDGET_H_
26 #define SRC_GUI_INCLUDE_CORBO_GUI_PARAMETER_WIDGET_H_
27 
28 #include <QHash>
29 #include <QPair>
30 #include <QStack>
31 #include <QVBoxLayout>
32 #include <QWidget>
33 
38 #include <QGroupBox>
39 
40 #include <memory>
41 #include <string>
42 #include <tuple>
43 #include <vector>
44 
45 namespace corbo {
46 namespace gui {
47 
48 class ParameterWidget : public QWidget
49 {
50  Q_OBJECT
51 
52  public:
53  explicit ParameterWidget(ParameterCache* cache = nullptr, QWidget* parent = nullptr);
54  virtual ~ParameterWidget();
55 
56  QSize sizeHint() const override;
57 
58  public slots:
59 
60  void generateFromMessage(std::shared_ptr<google::protobuf::Message> message);
61 
62  void generateFromAllocatedField(google::protobuf::Message* message, const google::protobuf::FieldDescriptor* field);
63 
64  const google::protobuf::Message* getMessage() const { return _param_message.get(); }
65  google::protobuf::Message* getMessage() { return _param_message.get(); }
66 
67  void addParameterInt32(int value, const MessageParser::FieldInformation& info);
68  void addParameterInt32Array(const std::vector<int>& values, const MessageParser::FieldInformation& info);
69  void addParameterDouble(double value, const MessageParser::FieldInformation& info);
70  void addParameterDoubleArray(const std::vector<double>& values, const MessageParser::FieldInformation& info);
71  void addParameterBool(bool value, const MessageParser::FieldInformation& info);
72  void addParameterBoolArray(const std::vector<bool>& values, const MessageParser::FieldInformation& info);
73  void addParameterEnum(const std::string& value, const MessageParser::FieldInformation& info);
74  void addParameterString(std::string value, const MessageParser::FieldInformation& info);
75  void addInfoText(const std::string& text, const MessageParser::FieldInformation& info);
76 
77  void startGroup(const MessageParser::FieldInformation& info);
78  void endGroup();
79 
80  bool hasParameters() const;
81 
82  void clearElements();
83 
84  const std::list<std::string>& nestedParentFieldNames() const { return _nested_parent_fields; }
85  std::list<std::string>& nestedParentFieldNames() { return _nested_parent_fields; }
86  QString parentFieldNames() const { return QString::fromStdString(MessageParser::nestedNamesToString(_nested_parent_fields)); }
87 
88  signals:
89  void updatedOneOfField(const QString& text);
90  void parameterInt32Updated(const QString& parameter, int value);
91  void signalUpdateRequested();
92 
93  protected:
94  void generateElements();
95  void parse(google::protobuf::Message* message, const google::protobuf::FieldDescriptor* field = nullptr);
96 
97  private:
98  void addSubWidget(QWidget* widget);
99  void addOneOfField(const MessageParser::FieldInformation& info);
100 
101  std::shared_ptr<google::protobuf::Message> _param_message;
102 
103  QVBoxLayout* _layout;
104  QStack<std::tuple<CollapsableGroupBox*, QLayout*, bool>> _groups;
105  QHash<QString, OneOfParamWidget*> _oneof_widgets;
106 
108 
109  std::list<std::string> _nested_parent_fields;
110 
111  bool _has_parameters = false;
112 };
113 
114 } // namespace gui
115 } // namespace corbo
116 
117 #endif // SRC_GUI_INCLUDE_CORBO_GUI_PARAMETER_WIDGET_H_
corbo::gui::ParameterWidget::nestedParentFieldNames
const std::list< std::string > & nestedParentFieldNames() const
Definition: parameter_widget.h:150
corbo::gui::ParameterWidget::sizeHint
QSize sizeHint() const override
Definition: parameter_widget.cpp:107
corbo::gui::ParameterWidget::_param_cache
ParameterCache * _param_cache
Definition: parameter_widget.h:173
corbo::gui::ParameterWidget::_groups
QStack< std::tuple< CollapsableGroupBox *, QLayout *, bool > > _groups
groupbox ptr, layout ptr, new msg flag (e.g. for loading default params)
Definition: parameter_widget.h:170
corbo::gui::ParameterWidget::addParameterInt32
void addParameterInt32(int value, const MessageParser::FieldInformation &info)
Definition: parameter_widget.cpp:165
corbo::gui::ParameterWidget::_oneof_widgets
QHash< QString, OneOfParamWidget * > _oneof_widgets
Definition: parameter_widget.h:171
corbo::gui::ParameterWidget::clearElements
void clearElements()
Definition: parameter_widget.cpp:998
corbo
Definition: communication/include/corbo-communication/utilities.h:37
corbo::gui::ParameterWidget::addParameterDouble
void addParameterDouble(double value, const MessageParser::FieldInformation &info)
Definition: parameter_widget.cpp:387
corbo::gui::ParameterWidget::_param_message
std::shared_ptr< google::protobuf::Message > _param_message
Definition: parameter_widget.h:167
corbo::gui::ParameterWidget::addParameterInt32Array
void addParameterInt32Array(const std::vector< int > &values, const MessageParser::FieldInformation &info)
Definition: parameter_widget.cpp:259
corbo::gui::ParameterWidget::getMessage
const google::protobuf::Message * getMessage() const
Definition: parameter_widget.h:130
corbo::gui::ParameterWidget::signalUpdateRequested
void signalUpdateRequested()
corbo::gui::ParameterWidget::_layout
QVBoxLayout * _layout
Definition: parameter_widget.h:169
corbo::gui::ParameterWidget::hasParameters
bool hasParameters() const
Definition: parameter_widget.cpp:986
corbo::gui::ParameterWidget::generateFromMessage
void generateFromMessage(std::shared_ptr< google::protobuf::Message > message)
Definition: parameter_widget.cpp:924
corbo::gui::ParameterWidget::addParameterBoolArray
void addParameterBoolArray(const std::vector< bool > &values, const MessageParser::FieldInformation &info)
Definition: parameter_widget.cpp:653
corbo::gui::ParameterWidget::parse
void parse(google::protobuf::Message *message, const google::protobuf::FieldDescriptor *field=nullptr)
Definition: parameter_widget.cpp:943
corbo::gui::ParameterWidget::~ParameterWidget
virtual ~ParameterWidget()
Definition: parameter_widget.cpp:105
corbo::gui::ParameterCache
Definition: parameter_cache.h:82
corbo::gui::ParameterWidget::generateFromAllocatedField
void generateFromAllocatedField(google::protobuf::Message *message, const google::protobuf::FieldDescriptor *field)
Definition: parameter_widget.cpp:931
info
else if n * info
Definition: cholesky.cpp:18
corbo::gui::ParameterWidget::addInfoText
void addInfoText(const std::string &text, const MessageParser::FieldInformation &info)
Definition: parameter_widget.cpp:863
corbo::gui::ParameterWidget::addSubWidget
void addSubWidget(QWidget *widget)
Definition: parameter_widget.cpp:903
corbo::gui::ParameterWidget::addParameterString
void addParameterString(std::string value, const MessageParser::FieldInformation &info)
Definition: parameter_widget.cpp:830
corbo::gui::ParameterWidget::parameterInt32Updated
void parameterInt32Updated(const QString &parameter, int value)
corbo::gui::ParameterWidget::addParameterBool
void addParameterBool(bool value, const MessageParser::FieldInformation &info)
Definition: parameter_widget.cpp:605
corbo::gui::ParameterWidget::updatedOneOfField
void updatedOneOfField(const QString &text)
parameter_cache.h
corbo::gui::ParameterWidget::addParameterDoubleArray
void addParameterDoubleArray(const std::vector< double > &values, const MessageParser::FieldInformation &info)
Definition: parameter_widget.cpp:477
corbo::gui::ParameterWidget::startGroup
void startGroup(const MessageParser::FieldInformation &info)
Definition: parameter_widget.cpp:874
one_of_param_widget.h
corbo::gui::ParameterWidget::endGroup
void endGroup()
Definition: parameter_widget.cpp:886
collapsable_groupbox.h
corbo::gui::ParameterWidget::ParameterWidget
ParameterWidget(ParameterCache *cache=nullptr, QWidget *parent=nullptr)
Definition: parameter_widget.cpp:96
corbo::gui::ParameterWidget::parentFieldNames
QString parentFieldNames() const
Definition: parameter_widget.h:152
corbo::gui::ParameterWidget::generateElements
void generateElements()
Definition: parameter_widget.cpp:937
corbo::gui::ParameterWidget::addParameterEnum
void addParameterEnum(const std::string &value, const MessageParser::FieldInformation &info)
Definition: parameter_widget.cpp:793
corbo::gui::ParameterWidget::_has_parameters
bool _has_parameters
Definition: parameter_widget.h:177
corbo::gui::ParameterWidget::addOneOfField
void addOneOfField(const MessageParser::FieldInformation &info)
Definition: parameter_widget.cpp:109
corbo::gui::ParameterWidget::_nested_parent_fields
std::list< std::string > _nested_parent_fields
Definition: parameter_widget.h:175
relicense.text
text
Definition: relicense.py:59
message_parser.h


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:05:59