Qt 4.8
qobject_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QOBJECT_P_H
43 #define QOBJECT_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists for the convenience
50 // of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
51 // file may change from version to version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include "QtCore/qobject.h"
57 #include "QtCore/qpointer.h"
58 #include "QtCore/qsharedpointer.h"
59 #include "QtCore/qcoreevent.h"
60 #include "QtCore/qlist.h"
61 #include "QtCore/qvector.h"
62 #include "QtCore/qreadwritelock.h"
63 #include "QtCore/qvariant.h"
64 #include "QtCore/qmetaobject.h"
65 #include "QtCore/qvarlengtharray.h"
66 
68 
69 class QVariant;
70 class QThreadData;
72 namespace QtSharedPointer { struct ExternalRefCountData; }
73 
74 /* mirrored in QtTestLib, DON'T CHANGE without prior warning */
76 {
77  typedef void (*BeginCallback)(QObject *caller, int method_index, void **argv);
78  typedef void (*EndCallback)(QObject *caller, int method_index);
79  BeginCallback signal_begin_callback,
81  EndCallback signal_end_callback,
83 };
85 
87 
89 
91 {
92 public:
93  static void (*destroyed)(QAbstractDeclarativeData *, QObject *);
94  static void (*parentChanged)(QAbstractDeclarativeData *, QObject *, QObject *);
95  static void (*objectNameChanged)(QAbstractDeclarativeData *, QObject *);
96 };
97 
99 {
101 
102 public:
103  struct ExtraData
104  {
106 #ifndef QT_NO_USERDATA
108 #endif
111  };
112 
113  typedef void (*StaticMetaCallFunction)(QObject *, QMetaObject::Call, int, void **);
114  struct Connection
115  {
116  QObject *sender;
117  QObject *receiver;
118  StaticMetaCallFunction callFunction;
119  // The next pointer for the singly-linked ConnectionList
121  //senders linked list
127  ushort connectionType : 3; // 0 == auto, 1 == direct, 2 == queued, 4 == blocking
128  ~Connection();
129  int method() const { return method_offset + method_relative; }
130  };
131  // ConnectionList is a singly-linked list
132  struct ConnectionList {
133  ConnectionList() : first(0), last(0) {}
136  };
137 
138  struct Sender
139  {
140  QObject *sender;
141  int signal;
142  int ref;
143  };
144 
145 
146  QObjectPrivate(int version = QObjectPrivateVersion);
147  virtual ~QObjectPrivate();
148  void deleteChildren();
149 
150  void setParent_helper(QObject *);
151  void moveToThread_helper();
152  void setThreadData_helper(QThreadData *currentData, QThreadData *targetData);
153  void _q_reregisterTimers(void *pointer);
154 
155  bool isSender(const QObject *receiver, const char *signal) const;
156  QObjectList receiverList(const char *signal) const;
157  QObjectList senderList() const;
158 
159  void addConnection(int signal, Connection *c);
160  void cleanConnectionLists();
161 
162 #ifdef QT3_SUPPORT
163  void sendPendingChildInsertedEvents();
164 #endif
165 
166  static inline Sender *setCurrentSender(QObject *receiver,
167  Sender *sender);
168  static inline void resetCurrentSender(QObject *receiver,
169  Sender *currentSender,
170  Sender *previousSender);
171 #ifdef QT_JAMBI_BUILD
172  static int *setDeleteWatch(QObjectPrivate *d, int *newWatch);
173  static void resetDeleteWatch(QObjectPrivate *d, int *oldWatch, int deleteWatch);
174 #endif
175  static void clearGuards(QObject *);
176 
177  static QObjectPrivate *get(QObject *o) {
178  return o->d_func();
179  }
180 
181  int signalIndex(const char *signalName) const;
182  inline bool isSignalConnected(uint signalIdx) const;
183 
184  // To allow arbitrary objects to call connectNotify()/disconnectNotify() without making
185  // the API public in QObject. This is used by QDeclarativeNotifierEndpoint.
186  inline void connectNotify(const char *signal);
187  inline void disconnectNotify(const char *signal);
188 
189  static inline void signalSignature(const QMetaMethod &signal,
190  QVarLengthArray<char> *result);
191 
192 public:
194  ExtraData *extraData; // extra data set by the user
195  QThreadData *threadData; // id of the thread that owns the object
196 
198 
199  Connection *senders; // linked list of connections connected to this object
200  Sender *currentSender; // object currently activating the object
201  mutable quint32 connectedSignals[2];
202 
203 #ifdef QT3_SUPPORT
204  QVector< QWeakPointer<QObject> > pendingChildInsertedEvents;
205 #else
206  // preserve binary compatibility with code compiled without Qt 3 support
207  // keeping the binary layout stable helps the Qt Creator debugger
208  void *unused;
209 #endif
210 
212  union {
214  QAbstractDeclarativeData *declarativeData; //extra data used by the declarative module
215  };
216 
217  // these objects are all used to indicate that a QObject was deleted
218  // plus QPointer, which keeps a separate list
220 #ifdef QT_JAMBI_BUILD
221  int *deleteWatch;
222 #endif
223 };
224 
225 
237 inline bool QObjectPrivate::isSignalConnected(uint signal_index) const
238 {
239  return signal_index >= sizeof(connectedSignals) * 8
240  || (connectedSignals[signal_index >> 5] & (1 << (signal_index & 0x1f))
243 }
244 
245 inline void QObjectPrivate::connectNotify(const char *signal)
246 {
247  q_ptr->connectNotify(signal);
248 }
249 
250 inline void QObjectPrivate::disconnectNotify(const char *signal)
251 {
252  q_ptr->disconnectNotify(signal);
253 }
254 
256  QVarLengthArray<char> *result)
257 {
258  Q_ASSERT(result);
259  const int signatureLength = qstrlen(signal.signature());
260  if (signatureLength == 0) {
261  result->append((char)0);
262  return;
263  }
264  result->reserve(signatureLength + 2);
265  result->append((char)(QSIGNAL_CODE + '0'));
266  result->append(signal.signature(), signatureLength + 1);
267 }
268 
270  Sender *sender)
271 {
272  Sender *previousSender = receiver->d_func()->currentSender;
273  receiver->d_func()->currentSender = sender;
274  return previousSender;
275 }
276 
278  Sender *currentSender,
279  Sender *previousSender)
280 {
281  // ref is set to zero when this object is deleted during the metacall
282  if (currentSender->ref == 1)
283  receiver->d_func()->currentSender = previousSender;
284  // if we've recursed, we need to tell the caller about the objects deletion
285  if (previousSender)
286  previousSender->ref = currentSender->ref;
287 }
288 
289 
292 
293 class QSemaphore;
295 {
296 public:
297  QMetaCallEvent(ushort method_offset, ushort method_relative, QObjectPrivate::StaticMetaCallFunction callFunction , const QObject *sender, int signalId,
298  int nargs = 0, int *types = 0, void **args = 0, QSemaphore *semaphore = 0);
299  ~QMetaCallEvent();
300 
301  inline int id() const { return method_offset_ + method_relative_; }
302  inline const QObject *sender() const { return sender_; }
303  inline int signalId() const { return signalId_; }
304  inline void **args() const { return args_; }
305 
306  virtual void placeMetaCall(QObject *object);
307 
308 private:
309  const QObject *sender_;
311  int nargs_;
312  int *types_;
313  void **args_;
318 };
319 
321 {
322 public:
323  inline QBoolBlocker(bool &b, bool value=true):block(b), reset(b){block = value;}
324  inline ~QBoolBlocker(){block = reset; }
325 private:
326  bool &block;
327  bool reset;
328 };
329 
331 
332 
334 {
336  virtual int metaCall(QMetaObject::Call, int _id, void **) { return _id; }
337  virtual int createProperty(const char *, const char *) { return -1; }
338 };
339 
341 
342 #endif // QOBJECT_P_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
static Sender * setCurrentSender(QObject *receiver, Sender *sender)
Definition: qobject_p.h:269
BeginCallback slot_begin_callback
Definition: qobject_p.h:79
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QSemaphore class provides a general counting semaphore.
Definition: qsemaphore.h:57
virtual int createProperty(const char *, const char *)
Definition: qobject_p.h:337
EndCallback slot_end_callback
Definition: qobject_p.h:81
static void signalSignature(const QMetaMethod &signal, QVarLengthArray< char > *result)
Definition: qobject_p.h:255
QObjectPrivate::StaticMetaCallFunction callFunction_
Definition: qobject_p.h:315
QSemaphore * semaphore_
Definition: qobject_p.h:314
const QObject * sender() const
Definition: qobject_p.h:302
Connection * senders
Definition: qobject_p.h:199
Q_CORE_EXPORT QTextStream & reset(QTextStream &s)
The QString class provides a Unicode character string.
Definition: qstring.h:83
void Q_CORE_EXPORT qt_register_signal_spy_callbacks(const QSignalSpyCallbackSet &callback_set)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
Sender * currentSender
Definition: qobject_p.h:200
void ** args_
Definition: qobject_p.h:313
ushort method_relative_
Definition: qobject_p.h:317
QThreadData * threadData
Definition: qobject_p.h:195
void append(const T &t)
BeginCallback signal_begin_callback
Definition: qobject_p.h:79
virtual int metaCall(QMetaObject::Call, int _id, void **)
Definition: qobject_p.h:336
QList< QPointer< QObject > > eventFilters
Definition: qobject_p.h:211
ushort method_offset_
Definition: qobject_p.h:316
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Q_DECLARE_TYPEINFO(QObjectPrivate::Connection, Q_MOVABLE_TYPE)
void(* StaticMetaCallFunction)(QObject *, QMetaObject::Call, int, void **)
Definition: qobject_p.h:113
QList< QVariant > propertyValues
Definition: qobject_p.h:110
virtual ~QAbstractDynamicMetaObject()
Definition: qobject_p.h:335
void * unused
Definition: qobject_p.h:208
QBasicAtomicPointer< int > argumentTypes
Definition: qobject_p.h:124
unsigned int uint
Definition: qglobal.h:996
QList< QByteArray > propertyNames
Definition: qobject_p.h:109
static void resetCurrentSender(QObject *receiver, Sender *currentSender, Sender *previousSender)
Definition: qobject_p.h:277
const QObject * sender_
Definition: qobject_p.h:309
void ** args() const
Definition: qobject_p.h:304
QVector< QObjectUserData * > userData
Definition: qobject_p.h:107
QAbstractDeclarativeData * declarativeData
Definition: qobject_p.h:214
QString objectName
Definition: qobject_p.h:193
EndCallback signal_end_callback
Definition: qobject_p.h:81
void connectNotify(const char *signal)
Definition: qobject_p.h:245
QSignalSpyCallbackSet Q_CORE_EXPORT qt_signal_spy_callback_set
bool & block
Definition: qobject_p.h:326
Connection * nextConnectionList
Definition: qobject_p.h:120
#define QSIGNAL_CODE
Definition: qobjectdefs.h:244
uint qstrlen(const char *str)
Definition: qbytearray.h:79
bool isSignalConnected(uint signalIdx) const
Returns true if the signal with index signal_index from object sender is connected.
Definition: qobject_p.h:237
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
static const struct @32 types[]
unsigned short ushort
Definition: qglobal.h:995
ExtraData * extraData
Definition: qobject_p.h:194
QBoolBlocker(bool &b, bool value=true)
Definition: qobject_p.h:323
unsigned int quint32
Definition: qglobal.h:938
int id() const
Definition: qobject_p.h:301
QObject * currentChildBeingDeleted
Definition: qobject_p.h:213
void Q_CORE_EXPORT qDeleteInEventHandler(QObject *o)
Definition: qobject.cpp:4348
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
void disconnectNotify(const char *signal)
Definition: qobject_p.h:250
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
StaticMetaCallFunction callFunction
Definition: qobject_p.h:118
int signalId() const
Definition: qobject_p.h:303
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
QObjectConnectionListVector * connectionLists
Definition: qobject_p.h:197
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
Definition: qobject_p.h:219
#define QT_VERSION
This macro expands a numeric value of the form 0xMMNNPP (MM = major, NN = minor, PP = patch) that spe...
Definition: qglobal.h:51
void reserve(int size)