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

0001 /*
0002  *   Copyright 2017 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 
0020 #ifndef OBJECTWATCHER_H
0021 #define OBJECTWATCHER_H
0022 
0023 #include <QObject>
0024 #include <QVariant>
0025 #include <QHash>
0026 
0027 class ObjectWatcher : public QObject
0028 {
0029     Q_OBJECT
0030 public:
0031     struct PropertyValue {
0032         PropertyValue(const QVariant &value = {}) : lastValue(value) {}
0033         QVariant lastValue;
0034         int times = 0;
0035 
0036         void integrateValue(QObject* object, const QMetaProperty& prop, const QVariant& value);
0037     };
0038 
0039     explicit ObjectWatcher(QObject* object);
0040 
0041     Q_SLOT void propertyChanged();
0042 
0043 private:
0044     QObject* const m_watched;
0045     QHash<QByteArray, PropertyValue> m_values;
0046 };
0047 
0048 #endif