| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 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 | | - |
| 44 | QT_BEGIN_NAMESPACE | - |
| 45 | | - |
| 46 | /*! | - |
| 47 | \class QObjectCleanupHandler | - |
| 48 | \inmodule QtCore | - |
| 49 | \brief The QObjectCleanupHandler class watches the lifetime of multiple QObjects. | - |
| 50 | | - |
| 51 | \ingroup objectmodel | - |
| 52 | | - |
| 53 | A QObjectCleanupHandler is useful whenever you need to know when a | - |
| 54 | number of \l{QObject}s that are owned by someone else have been | - |
| 55 | deleted. This is important, for example, when referencing memory | - |
| 56 | in an application that has been allocated in a shared library. | - |
| 57 | | - |
| 58 | To keep track of some \l{QObject}s, create a | - |
| 59 | QObjectCleanupHandler, and add() the objects you are interested | - |
| 60 | in. If you are no longer interested in tracking a particular | - |
| 61 | object, use remove() to remove it from the cleanup handler. If an | - |
| 62 | object being tracked by the cleanup handler gets deleted by | - |
| 63 | someone else it will automatically be removed from the cleanup | - |
| 64 | handler. You can delete all the objects in the cleanup handler | - |
| 65 | with clear(), or by destroying the cleanup handler. isEmpty() | - |
| 66 | returns true if the QObjectCleanupHandler has no objects to keep | - |
| 67 | track of. | - |
| 68 | | - |
| 69 | \sa QPointer | - |
| 70 | */ | - |
| 71 | | - |
| 72 | /*! | - |
| 73 | Constructs an empty QObjectCleanupHandler. | - |
| 74 | */ | - |
| 75 | QObjectCleanupHandler::QObjectCleanupHandler() | - |
| 76 | { | - |
| 77 | } | - |
| 78 | | - |
| 79 | /*! | - |
| 80 | Destroys the cleanup handler. All objects in this cleanup handler | - |
| 81 | will be deleted. | - |
| 82 | | - |
| 83 | \sa clear() | - |
| 84 | */ | - |
| 85 | QObjectCleanupHandler::~QObjectCleanupHandler() | - |
| 86 | { | - |
| 87 | clear(); never executed (the execution status of this line is deduced): clear(); | - |
| 88 | } | 0 |
| 89 | | - |
| 90 | /*! | - |
| 91 | Adds \a object to this cleanup handler and returns the pointer to | - |
| 92 | the object. | - |
| 93 | | - |
| 94 | \sa remove() | - |
| 95 | */ | - |
| 96 | QObject *QObjectCleanupHandler::add(QObject* object) | - |
| 97 | { | - |
| 98 | if (!object) | 0 |
| 99 | return 0; never executed: return 0; | 0 |
| 100 | | - |
| 101 | connect(object, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(QObject*))); never executed (the execution status of this line is deduced): connect(object, "2""destroyed(QObject*)", this, "1""objectDestroyed(QObject*)"); | - |
| 102 | cleanupObjects.insert(0, object); never executed (the execution status of this line is deduced): cleanupObjects.insert(0, object); | - |
| 103 | return object; never executed: return object; | 0 |
| 104 | } | - |
| 105 | | - |
| 106 | /*! | - |
| 107 | Removes the \a object from this cleanup handler. The object will | - |
| 108 | not be destroyed. | - |
| 109 | | - |
| 110 | \sa add() | - |
| 111 | */ | - |
| 112 | void QObjectCleanupHandler::remove(QObject *object) | - |
| 113 | { | - |
| 114 | int index; never executed (the execution status of this line is deduced): int index; | - |
| 115 | if ((index = cleanupObjects.indexOf(object)) != -1) { never evaluated: (index = cleanupObjects.indexOf(object)) != -1 | 0 |
| 116 | cleanupObjects.removeAt(index); never executed (the execution status of this line is deduced): cleanupObjects.removeAt(index); | - |
| 117 | disconnect(object, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(QObject*))); never executed (the execution status of this line is deduced): disconnect(object, "2""destroyed(QObject*)", this, "1""objectDestroyed(QObject*)"); | - |
| 118 | } | 0 |
| 119 | } | 0 |
| 120 | | - |
| 121 | /*! | - |
| 122 | Returns true if this cleanup handler is empty or if all objects in | - |
| 123 | this cleanup handler have been destroyed; otherwise return false. | - |
| 124 | | - |
| 125 | \sa add(), remove(), clear() | - |
| 126 | */ | - |
| 127 | bool QObjectCleanupHandler::isEmpty() const | - |
| 128 | { | - |
| 129 | return cleanupObjects.isEmpty(); never executed: return cleanupObjects.isEmpty(); | 0 |
| 130 | } | - |
| 131 | | - |
| 132 | /*! | - |
| 133 | Deletes all objects in this cleanup handler. The cleanup handler | - |
| 134 | becomes empty. | - |
| 135 | | - |
| 136 | \sa isEmpty() | - |
| 137 | */ | - |
| 138 | void QObjectCleanupHandler::clear() | - |
| 139 | { | - |
| 140 | while (!cleanupObjects.isEmpty()) never evaluated: !cleanupObjects.isEmpty() | 0 |
| 141 | delete cleanupObjects.takeFirst(); never executed: delete cleanupObjects.takeFirst(); | 0 |
| 142 | } | 0 |
| 143 | | - |
| 144 | void QObjectCleanupHandler::objectDestroyed(QObject *object) | - |
| 145 | { | - |
| 146 | remove(object); never executed (the execution status of this line is deduced): remove(object); | - |
| 147 | } | 0 |
| 148 | | - |
| 149 | QT_END_NAMESPACE | - |
| 150 | | - |
| | |