File indexing completed on 2024-04-14 14:27:09
0001 /*************************************************************************** 0002 * childreninterface.h 0003 * This file is part of the KDE project 0004 * copyright (C)2004-2006 by Sebastian Sauer (mail@dipe.org) 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this program; see the file COPYING. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 ***************************************************************************/ 0019 0020 #ifndef KROSS_CHILDRENINTERFACE_H 0021 #define KROSS_CHILDRENINTERFACE_H 0022 0023 #include <QHash> 0024 #include <QObject> 0025 0026 #include "krossconfig.h" 0027 0028 namespace Kross 0029 { 0030 0031 /** 0032 * Interface for managing \a Object collections. 0033 * 0034 * The \a Manager as well as the \a Action class inherit this interface 0035 * to allow to attach QObject to a global or a local context related 0036 * instances that should be published to the scripting code. 0037 */ 0038 class KROSSCORE_EXPORT ChildrenInterface 0039 { 0040 public: 0041 0042 /** 0043 * Additional options that could be defined for a QObject instance. 0044 */ 0045 enum Options { 0046 NoOption = 0x00, ///< No additional options. This is the default. 0047 AutoConnectSignals = 0x01, ///< auto connect signals with scripting functions. 0048 0049 //TODO probably add more options like; 0050 //ScriptableSlots = 0x01, ///< Publish slots that have Q_SCRIPTABLE defined. 0051 //NonScriptableSlots = 0x02, ///< Publish slots that don't have Q_SCRIPTABLE defined. 0052 //PrivateSlots = 0x04, ///< Publish private slots. 0053 //ProtectedSlots = 0x08, ///< Publish protected slots. 0054 //PublicSlots = 0x10, ///< Publish public slots. 0055 //AllSlots = ScriptableSlots|NonScriptableSlots|PrivateSlots|ProtectedSlots|PublicSlots, 0056 //ScriptableSignals = 0x100, ///< Publish signals that have Q_SCRIPTABLE defined. 0057 //NonScriptableSignals = 0x200, ///< Publish signals that don't have Q_SCRIPTABLE defined. 0058 //PrivateSignals = 0x400, ///< Publish private signals. 0059 //ProtectedSignals = 0x800, ///< Publish protected signals. 0060 //PublicSignals = 0x1000, ///< Publish public signals. 0061 //AllSignals = ScriptableSignals|NonScriptableSignals|PrivateSignals|ProtectedSignals|PublicSignals, 0062 //ScriptableProperties = 0x10000, ///< Publish properties that have Q_SCRIPTABLE defined. 0063 //NonScriptableProperties = 0x20000, ///< Publish properties that don't have Q_SCRIPTABLE defined. 0064 //AllProperties = ScriptableProperties|NonScriptableProperties, 0065 //GetParentObject = 0x100000, ///< Provide access to the parent QObject the QObject has. 0066 //SetParentObject = 0x200000, ///< Be able to set the parent QObject the QObject has. 0067 //ChildObjects = 0x400000, ///< Provide access to the child QObject's the QObject has. 0068 //AllObjects = GetParentObject|SetParentObject|ChildObjects 0069 0070 LastOption = 0x1000000 0071 }; 0072 0073 /** 0074 * Add a QObject to the list of children. 0075 * \param object The QObject instance that should be added to the list of children. 0076 * \param name The name the QObject should be known under. If not defined, the 0077 * QObject's objectName is used. 0078 * \param options Additional optional options for the QObject. 0079 */ 0080 void addObject(QObject *object, const QString &name = QString(), Options options = NoOption) 0081 { 0082 QString n = name.isNull() ? object->objectName() : name; 0083 m_objects.insert(n, object); 0084 if (options != NoOption) { 0085 m_options.insert(n, options); 0086 } 0087 } 0088 0089 /** 0090 * \return true if there exist a QObject with the \p name else false is returned. 0091 */ 0092 bool hasObject(const QString &name) const 0093 { 0094 return m_objects.contains(name); 0095 } 0096 0097 /** 0098 * \return the QObject with \p name or NULL if there exist no such object. 0099 */ 0100 QObject *object(const QString &name) const 0101 { 0102 return m_objects.contains(name) ? m_objects.value(name) : nullptr; 0103 } 0104 0105 /** 0106 * \return the map of QObject instances. 0107 */ 0108 QHash< QString, QObject * > objects() const 0109 { 0110 return m_objects; 0111 } 0112 0113 /** 0114 * \return true if the QObject with \p name was added with autoConnect enabled. 0115 */ 0116 Options objectOption(const QString &name) const 0117 { 0118 return m_options.contains(name) ? m_options.value(name) : NoOption; 0119 } 0120 0121 /** 0122 * \return the map of options. 0123 */ 0124 QHash< QString, Options > objectOptions() const 0125 { 0126 return m_options; 0127 } 0128 0129 private: 0130 QHash< QString, QObject * > m_objects; 0131 QHash< QString, Options > m_options; 0132 }; 0133 0134 } 0135 0136 #endif 0137