4 This file is part of GammaRay, the Qt application inspection and
7 Copyright (C) 2010-2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8 Author: Volker Krause <volker.krause@kdab.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef GAMMARAY_PROBE_H
25 #define GAMMARAY_PROBE_H
28 #include "probeinterface.h"
29 #include <QReadWriteLock>
39 class ConnectionModel
;
40 class ObjectListModel
;
41 class ObjectTreeModel
;
47 * Creates Probe instance in main thread and deletes self afterwards.
49 class ProbeCreator
: public QObject
66 class Q_DECL_EXPORT Probe
: public QObject
, public ProbeInterface
71 static Probe
*instance();
72 static bool isInitialized();
74 static void objectAdded(QObject
*obj
, bool fromCtor
= false);
75 static void objectRemoved(QObject
*obj
);
76 static void connectionAdded(QObject
*sender
, const char *signal
,
77 QObject
*receiver
, const char *method
,
78 Qt::ConnectionType type
);
79 static void connectionRemoved(QObject
*sender
, const char *signal
,
80 QObject
*receiver
, const char *method
);
82 static void findExistingObjects();
84 QAbstractItemModel
*objectListModel() const;
85 QAbstractItemModel
*objectTreeModel() const;
86 QAbstractItemModel
*connectionModel() const;
87 ToolModel
*toolModel() const;
89 static const char *connectLocation(const char *member
);
91 GammaRay::MainWindow
*window() const;
92 void setWindow(GammaRay::MainWindow
*window
);
94 QObject
*probe() const;
97 * Lock this to check the validity of a QObject
98 * and to access it safely afterwards.
100 QReadWriteLock
*objectLock() const;
102 * check whether @p obj is still valid
104 * NOTE: the objectLock must be locked when this is called!
106 bool isValidObject(QObject
*obj
) const;
109 * Returns true if @p obj belongs to the GammaRay Probe or Window.
111 * These objects should not be tracked or shown to the user,
112 * hence must be explictly filtered.
114 static bool filterObject(QObject
*obj
);
118 * Emitted when the user selected @p widget at position @p pos in the probed application.
120 void widgetSelected(QWidget
*widget
, const QPoint
&pos
);
122 void objectCreated(QObject
*obj
);
123 void objectDestroyed(QObject
*obj
);
124 void objectReparanted(QObject
*obj
);
127 bool eventFilter(QObject
*receiver
, QEvent
*event
);
131 void queuedObjectsFullyConstructed();
132 void handleObjectDestroyed(QObject
*obj
);
135 void objectFullyConstructed(QObject
*obj
);
137 explicit Probe(QObject
*parent
= 0);
138 static void addObjectRecursive(QObject
*obj
);
139 static Probe
*s_instance
;
141 ObjectListModel
*m_objectListModel
;
142 ObjectTreeModel
*m_objectTreeModel
;
143 ConnectionModel
*m_connectionModel
;
144 ToolModel
*m_toolModel
;
145 GammaRay::MainWindow
*m_window
;
146 QSet
<QObject
*> m_validObjects
;
147 QQueue
<QObject
*> m_queuedObjects
;
148 QTimer
*m_queueTimer
;
150 friend class ProbeCreator
;
155 #endif // GAMMARAY_PROBE_H