Kross

childreninterface.h
1 /***************************************************************************
2  * childreninterface.h
3  * This file is part of the KDE project
4  * copyright (C)2004-2006 by Sebastian Sauer ([email protected])
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program; see the file COPYING. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  ***************************************************************************/
19 
20 #ifndef KROSS_CHILDRENINTERFACE_H
21 #define KROSS_CHILDRENINTERFACE_H
22 
23 #include <QHash>
24 #include <QObject>
25 
26 #include "krossconfig.h"
27 
28 namespace Kross
29 {
30 
31 /**
32  * Interface for managing \a Object collections.
33  *
34  * The \a Manager as well as the \a Action class inherit this interface
35  * to allow to attach QObject to a global or a local context related
36  * instances that should be published to the scripting code.
37  */
38 class KROSSCORE_EXPORT ChildrenInterface
39 {
40 public:
41 
42  /**
43  * Additional options that could be defined for a QObject instance.
44  */
45  enum Options {
46  NoOption = 0x00, ///< No additional options. This is the default.
47  AutoConnectSignals = 0x01, ///< auto connect signals with scripting functions.
48 
49  //TODO probably add more options like;
50  //ScriptableSlots = 0x01, ///< Publish slots that have Q_SCRIPTABLE defined.
51  //NonScriptableSlots = 0x02, ///< Publish slots that don't have Q_SCRIPTABLE defined.
52  //PrivateSlots = 0x04, ///< Publish private slots.
53  //ProtectedSlots = 0x08, ///< Publish protected slots.
54  //PublicSlots = 0x10, ///< Publish public slots.
55  //AllSlots = ScriptableSlots|NonScriptableSlots|PrivateSlots|ProtectedSlots|PublicSlots,
56  //ScriptableSignals = 0x100, ///< Publish signals that have Q_SCRIPTABLE defined.
57  //NonScriptableSignals = 0x200, ///< Publish signals that don't have Q_SCRIPTABLE defined.
58  //PrivateSignals = 0x400, ///< Publish private signals.
59  //ProtectedSignals = 0x800, ///< Publish protected signals.
60  //PublicSignals = 0x1000, ///< Publish public signals.
61  //AllSignals = ScriptableSignals|NonScriptableSignals|PrivateSignals|ProtectedSignals|PublicSignals,
62  //ScriptableProperties = 0x10000, ///< Publish properties that have Q_SCRIPTABLE defined.
63  //NonScriptableProperties = 0x20000, ///< Publish properties that don't have Q_SCRIPTABLE defined.
64  //AllProperties = ScriptableProperties|NonScriptableProperties,
65  //GetParentObject = 0x100000, ///< Provide access to the parent QObject the QObject has.
66  //SetParentObject = 0x200000, ///< Be able to set the parent QObject the QObject has.
67  //ChildObjects = 0x400000, ///< Provide access to the child QObject's the QObject has.
68  //AllObjects = GetParentObject|SetParentObject|ChildObjects
69 
70  LastOption = 0x1000000
71  };
72 
73  /**
74  * Add a QObject to the list of children.
75  * \param object The QObject instance that should be added to the list of children.
76  * \param name The name the QObject should be known under. If not defined, the
77  * QObject's objectName is used.
78  * \param options Additional optional options for the QObject.
79  */
80  void addObject(QObject *object, const QString &name = QString(), Options options = NoOption)
81  {
82  QString n = name.isNull() ? object->objectName() : name;
83  m_objects.insert(n, object);
84  if (options != NoOption) {
85  m_options.insert(n, options);
86  }
87  }
88 
89  /**
90  * \return true if there exist a QObject with the \p name else false is returned.
91  */
92  bool hasObject(const QString &name) const
93  {
94  return m_objects.contains(name);
95  }
96 
97  /**
98  * \return the QObject with \p name or NULL if there exist no such object.
99  */
100  QObject *object(const QString &name) const
101  {
102  return m_objects.contains(name) ? m_objects.value(name) : nullptr;
103  }
104 
105  /**
106  * \return the map of QObject instances.
107  */
109  {
110  return m_objects;
111  }
112 
113  /**
114  * \return true if the QObject with \p name was added with autoConnect enabled.
115  */
116  Options objectOption(const QString &name) const
117  {
118  return m_options.contains(name) ? m_options.value(name) : NoOption;
119  }
120 
121  /**
122  * \return the map of options.
123  */
125  {
126  return m_options;
127  }
128 
129 private:
130  QHash< QString, QObject * > m_objects;
131  QHash< QString, Options > m_options;
132 };
133 
134 }
135 
136 #endif
137 
void addObject(QObject *object, const QString &name=QString(), Options options=NoOption)
Add a QObject to the list of children.
Definition: action.cpp:36
QHash< QString, Options > objectOptions() const
bool isNull() const const
const QLatin1String name
QHash< QString, QObject * > objects() const
bool hasObject(const QString &name) const
Interface for managing Object collections.
Options
Additional options that could be defined for a QObject instance.
QObject * object(const QString &name) const
Options objectOption(const QString &name) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Dec 6 2021 22:51:19 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.