Qt 4.8
qobjectcleanuphandler.cpp
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 #include "qobjectcleanuphandler.h"
43 
45 
78 {
79 }
80 
88 {
89  clear();
90 }
91 
99 {
100  if (!object)
101  return 0;
102 
104  cleanupObjects.insert(0, object);
105  return object;
106 }
107 
115 {
116  int index;
117  if ((index = cleanupObjects.indexOf(object)) != -1) {
118  cleanupObjects.removeAt(index);
120  }
121 }
122 
130 {
131  return cleanupObjects.isEmpty();
132 }
133 
141 {
142  while (!cleanupObjects.isEmpty())
143  delete cleanupObjects.takeFirst();
144 }
145 
147 {
148  remove(object);
149 }
150 
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define SLOT(a)
Definition: qobjectdefs.h:226
void remove(QObject *object)
Removes the object from this cleanup handler.
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
bool isEmpty() const
Returns true if this cleanup handler is empty or if all objects in this cleanup handler have been des...
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define SIGNAL(a)
Definition: qobjectdefs.h:227
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QObjectCleanupHandler()
Constructs an empty QObjectCleanupHandler.
~QObjectCleanupHandler()
Destroys the cleanup handler.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
QObject * add(QObject *object)
Adds object to this cleanup handler and returns the pointer to the object.
quint16 index
void clear()
Deletes all objects in this cleanup handler.
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480