File indexing completed on 2024-04-21 05:42:43

0001 /*
0002  *   Copyright 2014 by Aleix Pol Gonzalez <aleixpol@blue-systems.com>
0003  *
0004  *   This program is free software; you can redistribute it and/or modify
0005  *   it under the terms of the GNU Library General Public License as
0006  *   published by the Free Software Foundation; either version 2, or
0007  *   (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU General Public License for more details
0013  *
0014  *   You should have received a copy of the GNU Library General Public
0015  *   License along with this program; if not, write to the
0016  *   Free Software Foundation, Inc.,
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018  */
0019 #ifndef OBJECTDEBUG_H
0020 #define OBJECTDEBUG_H
0021 
0022 #include <QObject>
0023 #include <QPointer>
0024 #include <QSet>
0025 
0026 #include "kobjecttracking_export.h"
0027 
0028 class ObjectTimeTracker;
0029 class ObjectWatcher;
0030 
0031 class KOBJECTTRACKING_EXPORT ObjectDebug : public QObject
0032 {
0033     Q_OBJECT
0034     Q_PROPERTY(bool watch READ watch WRITE setWatch NOTIFY watchChanged)
0035     Q_PROPERTY(bool timeTracker READ timeTracker WRITE setTimeTracker NOTIFY timeTrackerChanged)
0036     Q_PROPERTY(bool inherit READ inherit WRITE setInherit)
0037 public:
0038     ObjectDebug(QObject* object);
0039     ~ObjectDebug() override;
0040 
0041     void setWatch(bool watch);
0042     bool watch() const;
0043 
0044     void setTimeTracker(bool timeTracker);
0045     bool timeTracker() const;
0046 
0047     void setInherit(bool inherit);
0048     bool inherit() const;
0049 
0050     static ObjectDebug *qmlAttachedProperties(QObject *object);
0051 
0052     bool eventFilter(QObject* watched, QEvent* event) override;
0053 
0054 Q_SIGNALS:
0055     void watchChanged(bool watch);
0056     void timeTrackerChanged(bool timeTracker);
0057     void independence(ObjectDebug* od);
0058 
0059 private:
0060     void addChild(QObject* child);
0061     void childDestroyed(QObject* object);
0062 
0063     QPointer<QObject> m_object;
0064     QPointer<ObjectTimeTracker> m_timeTracker;
0065     QPointer<ObjectWatcher> m_watcher;
0066     QSet<ObjectDebug*> m_children;
0067     bool m_inherit = false;
0068 };
0069 
0070 #endif