Fcitx
element.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2017-2017 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 #ifndef _FCITX_UTILS_ELEMENT_H_
8 #define _FCITX_UTILS_ELEMENT_H_
9 
10 #include <list>
11 #include <memory>
13 #include <fcitx-utils/fcitxutils_export.h>
14 #include <fcitx-utils/macros.h>
15 
16 /// \addtogroup FcitxUtils
17 /// \{
18 /// \file
19 /// \brief Utility class that provides a hierarchy between multiple objects.
20 
21 namespace fcitx {
22 
23 class ElementPrivate;
24 
25 /// \brief Base class that can be used for UI composition or graph.
26 class FCITXUTILS_EXPORT Element : public ConnectableObject {
27 public:
28  Element();
29  ~Element() override;
30 
31  /// \brief Enable query between different elements.
32  bool isChild(const Element *element) const;
33 
34  /// \brief Enable query between different elements.
35  bool isParent(const Element *element) const;
36 
37 protected:
38  /// \brief List all parents.
39  ///
40  /// For the sake of type safety, list parents are protected by default.
41  const std::list<Element *> &parents() const;
42 
43  /// \brief List all childs
44  ///
45  /// \see parents
46  const std::list<Element *> &childs() const;
47 
48  // Sub class may use these functions carefully if they intends
49  // to have single type of childs.
50  void addChild(Element *child);
51  void addParent(Element *parent);
52 
53  void insertChild(Element *before, Element *child);
54  void insertParent(Element *before, Element *parent);
55 
56  void removeParent(Element *parent);
57  void removeChild(Element *child);
58 
59  void removeAllChild();
60  void removeAllParent();
61 
62  static void addEdge(Element *parent, Element *child, Element *beforeChild,
63  Element *beforeParent);
64  static void removeEdge(Element *parent, Element *child);
65 
66 private:
67  std::unique_ptr<ElementPrivate> d_ptr;
68  FCITX_DECLARE_PRIVATE(Element);
69 };
70 } // namespace fcitx
71 
72 #endif // _FCITX_UTILS_ELEMENT_H_
Base class for all object supports connection.
Definition: action.cpp:17
Utilities to enable use object with signal.
Base class that can be used for UI composition or graph.
Definition: element.h:26