VariantWidget.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarXGui::ArmarXObjects::VariantWidget
17 * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18 * @date 2017
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <QFormLayout>
26#include <QWidget>
27
30#include <ArmarXCore/interface/observers/VariantBase.h>
31
33{
35}
36
37namespace armarx
38{
39 class VariantWidget : public QWidget
40 {
41 using VariantDataWidgetBase = VariantDataWidgets::VariantDataWidgetBase;
42 Q_OBJECT
43 public:
44 VariantWidget(QWidget* parent = nullptr);
45 using QWidget::QWidget;
46 public slots:
47 void update(const VariantBasePtr& v);
48 void update(const std::vector<VariantBasePtr>& vec);
49 void update(const std::map<std::string, VariantBasePtr>& map);
50
51 private:
52 void updateEntry(const std::string& name, const VariantBasePtr& v);
53
54 enum class Mode
55 {
56 Empty,
57 SingleEntry,
58 Vector,
59 Map
60 };
61 void reset(Mode newMode = Mode::Empty);
62 Mode mode{Mode::Empty};
63
64 std::map<std::string, VariantDataWidgetBase*> entries;
65 QFormLayout* l;
66 int getEntryRow(VariantDataWidgetBase* entry) const;
67 };
68} // namespace armarx
69
71{
72 class VariantDataWidgetBase : public QWidget
73 {
74 Q_OBJECT
75 public:
76 virtual void
77 update(const VariantDataPtr&)
78 {
79 }
80
81 virtual std::string
83 {
84 return typeName;
85 }
86
87 virtual void
88 setTypeName(const std::string& name)
89 {
90 typeName = name;
91 }
92
93 private:
94 std::string typeName;
95 };
96
98 Registrar<std::function<VariantDataWidgetBase*(const VariantDataPtr&)>>;
99
100 template <class T>
102 {
104 {
106 type,
107 [type](const VariantDataPtr& p)
108 {
109 ARMARX_CHECK_EXPRESSION(p) << "Passed VariantDataPtr is null";
110 ARMARX_CHECK_EXPRESSION(p->ice_id() == type) << p->ice_id() << " == " << type;
111 return new T(p);
112 }
113
114 );
115 }
116 };
117
118 VariantDataWidgetBase* makeVariantDataWidget(const VariantBasePtr& p);
119} // namespace armarx::VariantDataWidgets
Stores key object pairs.
Definition Registrar.h:63
static void registerElement(const std::string &key, std::function< VariantDataWidgetBase *(const VariantDataPtr &)> element)
Definition Registrar.h:108
virtual void setTypeName(const std::string &name)
virtual void update(const VariantDataPtr &)
VariantWidget(VariantPtr variant, QWidget *parent=0, Qt::WindowFlags f=0)
void update(const VariantBasePtr &v)
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Registrar< std::function< VariantDataWidgetBase *(const VariantDataPtr &)> > VariantDataWidgetFactory
VariantDataWidgetBase * makeVariantDataWidget(const VariantBasePtr &p)
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr