d/control: Recommend gdb
[gammaray-debian.git] / probe.h
blob44694ea48ddf040ffcee6ce15694b8f3c79ef43e
1 /*
2 probe.h
4 This file is part of GammaRay, the Qt application inspection and
5 manipulation tool.
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
27 #include <qobject.h>
28 #include "probeinterface.h"
29 #include <QReadWriteLock>
30 #include <QSet>
31 #include <QQueue>
33 class QPoint;
34 class QTimer;
35 class QGraphicsItem;
37 namespace GammaRay {
39 class ConnectionModel;
40 class ObjectListModel;
41 class ObjectTreeModel;
42 class ToolModel;
44 class MainWindow;
46 /**
47 * Creates Probe instance in main thread and deletes self afterwards.
49 class ProbeCreator : public QObject
51 Q_OBJECT
52 public:
53 enum Type {
54 CreateOnly,
55 CreateAndFindExisting
57 ProbeCreator(Type t);
59 private slots:
60 void createProbe();
62 private:
63 Type m_type;
66 class Q_DECL_EXPORT Probe : public QObject, public ProbeInterface
68 Q_OBJECT
69 public:
70 virtual ~Probe();
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;
96 /**
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);
116 signals:
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);
126 protected:
127 bool eventFilter(QObject *receiver, QEvent *event);
129 private slots:
130 void delayedInit();
131 void queuedObjectsFullyConstructed();
132 void handleObjectDestroyed(QObject *obj);
134 private:
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