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 #include <ArmarXGui/interface/WidgetDescription.h>
33 
35 {
36  class ValueChangedListenerInterface: public QFrame
37  {
38  Q_OBJECT
39  public:
41  public slots:
42  virtual void valueChangedSlot(std::string name, VariantBasePtr value) {}
43  };
44 
46  {
47  Q_OBJECT
48  public:
50 
51  virtual std::map<std::string, VariantBasePtr> getVariants()
52  {
53  return {};
54  }
55  virtual std::string getName() const
56  {
57  return objectName().toStdString();
58  }
59  virtual void setName(const std::string& name)
60  {
61  setObjectName(QString::fromStdString(name));
62  }
63  signals:
64  void valueChangedSignal(std::string name, VariantBasePtr value);
65  void variantWidgetUpdatedSignal(std::string name, VariantWidgetContent::VariantWidgetContentBasePtr data);
66  public slots:
67  virtual void variantWidgetUpdatedSlot(std::string name, VariantWidgetContent::VariantWidgetContentBasePtr data) {}
68  protected slots:
69  virtual void contentUpdated() {}
70  };
71 
72  //has to be here since it has the Q_OBJECT macro
74  {
75  Q_OBJECT
76  public:
78  std::map<std::string, VariantBasePtr> getVariants() override;
79  void valueChangedSlot(std::string name, VariantBasePtr value) override
80  {
81  emit valueChangedSignal(name, value);
82  }
83  void variantWidgetUpdatedSlot(std::string name, VariantWidgetContent::VariantWidgetContentBasePtr data) override
84  {
85  emit variantWidgetUpdatedSignal(name, data);
86  }
87  virtual DescribedWidgetBase* addChild(const WidgetPtr& childPtr);
88 
89  protected:
90  std::vector<DescribedWidgetBase*> children;
92  };
93 
95 
96  template<class T>
98  {
99  DescribedWidgetFactoryRegistration(const std::string& type)
100  {
102  type,
103  [type](const WidgetPtr & p, ValueChangedListenerInterface * listener)
104  {
105  ARMARX_CHECK_EXPRESSION(p) << "Passed WidgetPtr is null";
106  ARMARX_CHECK_EXPRESSION(p->ice_id() == type) << p->ice_id() << " == " << type;
107  // ARMARX_DEBUG << "Making DescribedWidget for type '" << type << "'";
108  return new T(p, listener);
109  }
110  );
111  }
112  };
113  DescribedWidgetBase* makeDescribedWidget(const WidgetPtr& p, ValueChangedListenerInterface* listener = nullptr);
114 }
armarx::WidgetDescription::DescribedWidgetLayoutBase::addChild
virtual DescribedWidgetBase * addChild(const WidgetPtr &childPtr)
Definition: WidgetDescription.cpp:730
armarx::WidgetDescription::DescribedWidgetBase::setName
virtual void setName(const std::string &name)
Definition: WidgetDescription.h:59
armarx::WidgetDescription::DescribedWidgetLayoutBase::valueChangedSlot
void valueChangedSlot(std::string name, VariantBasePtr value) override
Definition: WidgetDescription.h:79
armarx::WidgetDescription::DescribedWidgetLayoutBase::listener
ValueChangedListenerInterface * listener
Definition: WidgetDescription.h:91
armarx::WidgetDescription::DescribedWidgetLayoutBase::children
std::vector< DescribedWidgetBase * > children
Definition: WidgetDescription.h:90
armarx::Registrar::registerElement
static void registerElement(const KeyType &key, RegisteredType element)
Registers an element.
Definition: Registrar.h:105
armarx::WidgetDescription::DescribedWidgetBase::variantWidgetUpdatedSignal
void variantWidgetUpdatedSignal(std::string name, VariantWidgetContent::VariantWidgetContentBasePtr data)
armarx::WidgetDescription::ValueChangedListenerInterface
Definition: WidgetDescription.h:36
IceInternal::Handle<::armarx::VariantBase >
armarx::WidgetDescription
Definition: DefaultWidgetDescriptions.cpp:27
armarx::WidgetDescription::DescribedWidgetLayoutBase::getVariants
std::map< std::string, VariantBasePtr > getVariants() override
Definition: WidgetDescription.cpp:720
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::WidgetDescription::DescribedWidgetBase::variantWidgetUpdatedSlot
virtual void variantWidgetUpdatedSlot(std::string name, VariantWidgetContent::VariantWidgetContentBasePtr data)
Definition: WidgetDescription.h:67
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::WidgetDescription::DescribedWidgetBase
Definition: WidgetDescription.h:45
armarx::WidgetDescription::DescribedWidgetBase::getName
virtual std::string getName() const
Definition: WidgetDescription.h:55
armarx::WidgetDescription::DescribedWidgetBase::DescribedWidgetBase
DescribedWidgetBase(WidgetPtr ptr)
Definition: WidgetDescription.cpp:790
armarx::WidgetDescription::DescribedWidgetBase::valueChangedSignal
void valueChangedSignal(std::string name, VariantBasePtr value)
armarx::WidgetDescription::DescribedWidgetLayoutBase::variantWidgetUpdatedSlot
void variantWidgetUpdatedSlot(std::string name, VariantWidgetContent::VariantWidgetContentBasePtr data) override
Definition: WidgetDescription.h:83
Registrar.h
armarx::WidgetDescription::DescribedWidgetFactoryRegistration::DescribedWidgetFactoryRegistration
DescribedWidgetFactoryRegistration(const std::string &type)
Definition: WidgetDescription.h:99
armarx::WidgetDescription::ValueChangedListenerInterface::valueChangedSlot
virtual void valueChangedSlot(std::string name, VariantBasePtr value)
Definition: WidgetDescription.h:42
armarx::WidgetDescription::makeDescribedWidget
DescribedWidgetBase * makeDescribedWidget(const WidgetPtr &p, ValueChangedListenerInterface *listener)
Definition: WidgetDescription.cpp:742
armarx::WidgetDescription::ValueChangedListenerInterface::ValueChangedListenerInterface
ValueChangedListenerInterface()
Definition: WidgetDescription.cpp:798
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:66
ExpressionException.h
armarx::WidgetDescription::DescribedWidgetFactoryRegistration
Definition: WidgetDescription.h:97
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::Registrar
Stores key object pairs.
Definition: Registrar.h:62
armarx::WidgetDescription::DescribedWidgetLayoutBase::DescribedWidgetLayoutBase
DescribedWidgetLayoutBase(WidgetPtr ptr, ValueChangedListenerInterface *listener)
Definition: WidgetDescription.cpp:718
armarx::WidgetDescription::DescribedWidgetBase::getVariants
virtual std::map< std::string, VariantBasePtr > getVariants()
Definition: WidgetDescription.h:51
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::WidgetDescription::DescribedWidgetLayoutBase
Definition: WidgetDescription.h:73
armarx::WidgetDescription::DescribedWidgetBase::contentUpdated
virtual void contentUpdated()
Definition: WidgetDescription.h:69