Kross

wrapperinterface.h
1 /***************************************************************************
2  * wrapperinterface.h
3  * This file is part of the KDE project
4  * copyright (C)2008 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_WRAPPERINTERFACE_H
21 #define KROSS_WRAPPERINTERFACE_H
22 
23 #include "krossconfig.h"
24 
25 namespace Kross
26 {
27 
28 /**
29  * Wrapper-class used to provide handlers for custom types.
30  *
31  * Custom types are types other than QObject*, QWidget* or one
32  * of the base types supported by QVariant. By using the
33  * Kross::registerMetaTypeHandler() method such custom handlers
34  * can be registered and used to either translate various
35  * types to a by QVariant supported type or by providing on
36  * the fly an own wrapper class that inherits from QObject
37  * and does provide access to the functionality of the
38  * wrapped custom type.
39  *
40  * Following sample demonstrates the usage by registering
41  * a handler for the type "TestObject*". Once such a type
42  * got returned by a C++ class, the handler got called. If
43  * we return a QObject that implements the WrapperInterface,
44  * what is not needed, then the wrappedObject() method will
45  * be used to translate the wrapper back to the wrapped
46  * object if a C++ function got called and the wrapper is
47  * passed as argument.
48  *
49  * \code
50  * // This is our wrapper class we are using to e.g. provide
51  * // additional functionality on the fly or to provide access
52  * // to a C++ type that does not inherit from QObject.
53  * class MyWrapper : public QObject, public Kross::WrapperInterface {
54  * public:
55  * MyWrapper(QObject* obj) : QObject(obj) {}
56  * void* wrappedObject() const { return parent(); }
57  * };
58  * // This function will be called by Kross if a type named
59  * // "TestObject*" got returned by a C++ method.
60  * QVariant TestObjectHandler(void* ptr)
61  * {
62  * TestObject* obj = static_cast<TestObject*>(ptr);
63  * MyWrapper* w = new MyWrapper(obj);
64  * QVariant r;
65  * r.setValue( (QObject*)w );
66  * return r;
67  * }
68  * // and somewhere else we finally register our function.
69  * Kross::Manager::self().registerMetaTypeHandler("TestObject*", TestObjectHandler);
70  * \endcode
71  *
72  * \since 4.2
73  */
74 class KROSSCORE_EXPORT WrapperInterface
75 {
76 public:
77 
78  /**
79  * Destructor.
80  */
81  virtual ~WrapperInterface();
82 
83  /**
84  * This method got called by Kross if the wrapper-instance
85  * got passed to a C++ slot. It is recommend to return here
86  * the wrapped instance, but you don't need to.
87  */
88  virtual void *wrappedObject() const = 0;
89 
90  //void wrapperConstructed() {}
91  //void wrapperDestroyed() {}
92 };
93 
94 }
95 
96 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Dec 5 2023 04:09:32 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.