• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

kjsembed

  • kjsembed
  • kjsembed
qobject_binding.h
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org>
3 Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com>
4 Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org>
5 Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us>
6 Copyright (C) 2007, 2008 Sebastian Sauer <mail@dipe.org>
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22*/
23
24
25#ifndef QOBJECT_BINDING_H
26#define QOBJECT_BINDING_H
27
28#include <QtCore/QObjectCleanupHandler>
29#include <QtCore/QDebug>
30#include <QtCore/QBool>
31
32#include <kjs/function.h>
33#include <kdemacros.h>
34
35#include "binding_support.h"
36#include "object_binding.h"
37
38
45#define START_QOBJECT_METHOD( METHODNAME, TYPE) \
46KJS::JSValue *METHODNAME( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args ) \
47{ \
48 Q_UNUSED( args ); \
49 KJS::JSValue *result = KJS::jsNull(); \
50 KJSEmbed::QObjectBinding *imp = KJSEmbed::extractBindingImp<KJSEmbed::QObjectBinding>(exec, self ); \
51 if( imp ) \
52 { \
53 TYPE *object = imp->qobject<TYPE>(); \
54 if( object ) \
55 {
56
60#define END_QOBJECT_METHOD \
61 } \
62 else \
63 KJS::throwError(exec, KJS::ReferenceError, QString("QO: The internal object died %1:%2.").arg(__FILE__).arg(__LINE__));\
64 } \
65 else \
66 KJS::throwError(exec, KJS::ReferenceError, QString("QObject died."));\
67 return result; \
68}
69
70class QObject;
71class QMetaMethod;
72
73namespace KJSEmbed {
74
75KJS_BINDING( QObjectFactory )
76
77class EventProxy;
78
79class KJSEMBED_EXPORT QObjectBinding : public ObjectBinding
80{
81 public:
82
83 QObjectBinding( KJS::ExecState *exec, QObject *object );
84 virtual ~QObjectBinding();
85
86 static void publishQObject( KJS::ExecState *exec, KJS::JSObject *target, QObject *object);
87
94 enum Access {
95 None = 0x00,
96
97 ScriptableSlots = 0x01,
98 NonScriptableSlots = 0x02,
99 PrivateSlots = 0x04,
100 ProtectedSlots = 0x08,
101 PublicSlots = 0x10,
102 AllSlots = ScriptableSlots|NonScriptableSlots|PrivateSlots|ProtectedSlots|PublicSlots,
103
104 ScriptableSignals = 0x100,
105 NonScriptableSignals = 0x200,
106 PrivateSignals = 0x400,
107 ProtectedSignals = 0x800,
108 PublicSignals = 0x1000,
109 AllSignals = ScriptableSignals|NonScriptableSignals|PrivateSignals|ProtectedSignals|PublicSignals,
110
111 ScriptableProperties = 0x10000,
112 NonScriptableProperties = 0x20000,
113 AllProperties = ScriptableProperties|NonScriptableProperties,
114
115 GetParentObject = 0x100000,
116 SetParentObject = 0x200000,
117 ChildObjects = 0x400000,
118 AllObjects = GetParentObject|SetParentObject|ChildObjects
119 };
120
121 Q_DECLARE_FLAGS(AccessFlags, Access)
122
123
126 AccessFlags access() const;
127
131 void setAccess(AccessFlags access);
132
136 void put(KJS::ExecState *exec, const KJS::Identifier &propertyName, KJS::JSValue *value, int attr=KJS::None);
137
141 bool canPut(KJS::ExecState *exec, const KJS::Identifier &propertyName) const;
142
147 bool getOwnPropertySlot( KJS::ExecState *exec, const KJS::Identifier &propertyName, KJS::PropertySlot &slot );
148
152 static KJS::JSValue *propertyGetter( KJS::ExecState *exec, KJS::JSObject*, const KJS::Identifier& name, const KJS::PropertySlot& );
153
158 KJS::UString toString(KJS::ExecState *exec) const;
159
164 KJS::UString className() const;
165
170 void watchObject( QObject *object );
171
176 template <typename T>
177 T *qobject() const
178 {
179 QObject* object = QObjectBinding::object<QObject>();
180 if (object)
181 return qobject_cast<T*>(object);
182 else
183 return 0;
184 }
185
186 private:
187 EventProxy *m_evproxy;
188 QObjectCleanupHandler *m_cleanupHandler;
189 AccessFlags m_access;
190};
191
192Q_DECLARE_OPERATORS_FOR_FLAGS(QObjectBinding::AccessFlags)
193
194class KJSEMBED_EXPORT SlotBinding : public KJS::InternalFunctionImp
195{
196 public:
197 SlotBinding(KJS::ExecState *exec, const QMetaMethod &memberName);
198 KJS::JSValue *callAsFunction( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args );
199 bool implementsCall() const { return true; }
200 bool implementsConstruct() const { return false; }
201
202 protected:
203 QByteArray m_memberName;
204};
205
230KJSEMBED_EXPORT KJS::JSObject *createQObject(KJS::ExecState *exec, QObject *value, KJSEmbed::ObjectBinding::Ownership owner = KJSEmbed::ObjectBinding::JSOwned);
231
232
233}
234#endif
235
236//kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;
binding_support.h
KJS_BINDING
#define KJS_BINDING(NAME)
Definition: binding_support.h:34
KJSEmbed::EventProxy
Filters events for a QObject and forwards them to a JS handler.
Definition: eventproxy.h:45
KJSEmbed::ObjectBinding
Definition: object_binding.h:89
KJSEmbed::ObjectBinding::Ownership
Ownership
Definition: object_binding.h:91
KJSEmbed::ObjectBinding::JSOwned
@ JSOwned
Definition: object_binding.h:91
KJSEmbed::QObjectBinding
Definition: qobject_binding.h:80
KJSEmbed::QObjectBinding::Access
Access
Enumeration of access-flags that could be OR-combined to define what parts of the QObject should be p...
Definition: qobject_binding.h:94
KJSEmbed::QObjectBinding::qobject
T * qobject() const
Definition: qobject_binding.h:177
KJSEmbed::SlotBinding
Definition: qobject_binding.h:195
KJSEmbed::SlotBinding::implementsConstruct
bool implementsConstruct() const
Definition: qobject_binding.h:200
KJSEmbed::SlotBinding::m_memberName
QByteArray m_memberName
Definition: qobject_binding.h:203
KJSEmbed::SlotBinding::implementsCall
bool implementsCall() const
Definition: qobject_binding.h:199
QObject
KJSEMBED_EXPORT
#define KJSEMBED_EXPORT
Definition: kjseglobal.h:32
KJSEmbed
Definition: application.h:33
KJSEmbed::createQObject
KJSEMBED_EXPORT KJS::JSObject * createQObject(KJS::ExecState *exec, QObject *value, KJSEmbed::ObjectBinding::Ownership owner=KJSEmbed::ObjectBinding::JSOwned)
Returns a binding object for the specified QObject.
Definition: qobject_binding.cpp:735
KJS
Implement QString-KJS::UString conversion methods.
Definition: kjs_object_model.h:29
object_binding.h
className
END_QOBJECT_METHOD QByteArray className
Definition: qobject_binding.cpp:832
value
QVariant value
Definition: settings.cpp:35
None
@ None
Definition: variant_binding.cpp:130
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kjsembed

Skip menu "kjsembed"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal