WidgetDescription.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::WidgetDescription
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 <functional>
26
27#include <QFrame>
28
31#include <ArmarXCore/interface/observers/VariantBase.h>
32
33#include <ArmarXGui/interface/WidgetDescription.h>
34
36{
37 class ValueChangedListenerInterface : public QFrame
38 {
39 Q_OBJECT
40 public:
42 public slots:
43
44 virtual void
45 valueChangedSlot(std::string name, VariantBasePtr value)
46 {
47 }
48 };
49
51 {
52 Q_OBJECT
53 public:
55
56 virtual std::map<std::string, VariantBasePtr>
58 {
59 return {};
60 }
61
62 virtual std::string
63 getName() const
64 {
65 return objectName().toStdString();
66 }
67
68 virtual void
69 setName(const std::string& name)
70 {
71 setObjectName(QString::fromStdString(name));
72 }
73
74 signals:
75 void valueChangedSignal(std::string name, VariantBasePtr value);
76 void variantWidgetUpdatedSignal(std::string name,
77 VariantWidgetContent::VariantWidgetContentBasePtr data);
78 public slots:
79
80 virtual void
81 variantWidgetUpdatedSlot(std::string name,
82 VariantWidgetContent::VariantWidgetContentBasePtr data)
83 {
84 }
85
86 protected slots:
87
88 virtual void
90 {
91 }
92 };
93
94 //has to be here since it has the Q_OBJECT macro
96 {
97 Q_OBJECT
98 public:
100 std::map<std::string, VariantBasePtr> getVariants() override;
101
102 void
103 valueChangedSlot(std::string name, VariantBasePtr value) override
104 {
105 emit valueChangedSignal(name, value);
106 }
107
108 void
109 variantWidgetUpdatedSlot(std::string name,
110 VariantWidgetContent::VariantWidgetContentBasePtr data) override
111 {
113 }
114
115 virtual DescribedWidgetBase* addChild(const WidgetPtr& childPtr);
116
117 protected:
118 std::vector<DescribedWidgetBase*> children;
120 };
121
124
125 template <class T>
127 {
128 DescribedWidgetFactoryRegistration(const std::string& type)
129 {
131 type,
132 [type](const WidgetPtr& p, ValueChangedListenerInterface* listener)
133 {
134 ARMARX_CHECK_EXPRESSION(p) << "Passed WidgetPtr is null";
135 ARMARX_CHECK_EXPRESSION(p->ice_id() == type) << p->ice_id() << " == " << type;
136 // ARMARX_DEBUG << "Making DescribedWidget for type '" << type << "'";
137 return new T(p, listener);
138 });
139 }
140 };
141
142 DescribedWidgetBase* makeDescribedWidget(const WidgetPtr& p,
143 ValueChangedListenerInterface* listener = nullptr);
144} // namespace armarx::WidgetDescription
Stores key object pairs.
Definition Registrar.h:63
static void registerElement(const std::string &key, std::function< DescribedWidgetBase *(const WidgetPtr &, ValueChangedListenerInterface *)> element)
Definition Registrar.h:108
virtual void setName(const std::string &name)
void variantWidgetUpdatedSignal(std::string name, VariantWidgetContent::VariantWidgetContentBasePtr data)
virtual void variantWidgetUpdatedSlot(std::string name, VariantWidgetContent::VariantWidgetContentBasePtr data)
void valueChangedSignal(std::string name, VariantBasePtr value)
virtual std::map< std::string, VariantBasePtr > getVariants()
DescribedWidgetLayoutBase(WidgetPtr ptr, ValueChangedListenerInterface *listener)
virtual DescribedWidgetBase * addChild(const WidgetPtr &childPtr)
std::map< std::string, VariantBasePtr > getVariants() override
void valueChangedSlot(std::string name, VariantBasePtr value) override
void variantWidgetUpdatedSlot(std::string name, VariantWidgetContent::VariantWidgetContentBasePtr data) override
virtual void valueChangedSlot(std::string name, VariantBasePtr value)
#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< DescribedWidgetBase *(const WidgetPtr &, ValueChangedListenerInterface *)> > DescribedWidgetFactory
DescribedWidgetBase * makeDescribedWidget(const WidgetPtr &p, ValueChangedListenerInterface *listener)
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr