Commit 9e8697c4 authored by Urs Fleisch's avatar Urs Fleisch
Browse files

SignalEmissionDumper in DebugUtils to monitor signal emissions.

parent c09f47de
......@@ -6,4 +6,6 @@ set(utils_SRCS
utils/coreplatformtools.cpp
)
set(utils_MOC_HDRS)
set(utils_MOC_HDRS
utils/debugutils.h
)
......@@ -27,6 +27,69 @@
#ifndef QT_NO_DEBUG
#include "debugutils.h"
#include <QMetaObject>
#include <QMetaMethod>
/**
* Constructor.
* @param parent parent object
*/
DebugUtils::SignalEmissionDumper::SignalEmissionDumper(QObject* parent) :
QObject(parent)
{
}
/**
* Destructor.
*/
DebugUtils::SignalEmissionDumper::~SignalEmissionDumper()
{
}
/**
* Monitor signal emissions of object
* @param obj object to monitor
*/
void DebugUtils::SignalEmissionDumper::connectObject(QObject* obj)
{
const QMetaObject* metaObject = obj->metaObject();
for (int i = 0; i < metaObject->methodCount(); ++i) {
#if QT_VERSION >= 0x050000
QByteArray sig = metaObject->method(i).methodSignature();
#else
QByteArray sig = metaObject->method(i).signature();
#endif
if (metaObject->indexOfSignal(sig) != -1) {
sig.prepend(QSIGNAL_CODE + '0');
connect(obj, sig, this, SLOT(printSignal()));
}
}
}
/**
* @brief Print emitted signal to debug output.
*/
void DebugUtils::SignalEmissionDumper::printSignal()
{
if (QObject* obj = sender()) {
int idx = senderSignalIndex();
if (idx != -1) {
#if QT_VERSION >= 0x050000
QByteArray sig = obj->metaObject()->method(idx).methodSignature();
#else
QByteArray sig = obj->metaObject()->method(idx).signature();
#endif
if (!sig.isEmpty()) {
qDebug("SIGNAL OUT %s::%s %s",
obj->metaObject()->className(),
qPrintable(obj->objectName().isEmpty()
? QLatin1String("unnamed") : obj->objectName()),
sig.constData());
}
}
}
}
/**
* Dump an item model.
......
......@@ -36,6 +36,33 @@ class QAbstractItemModel;
namespace DebugUtils {
/**
* Displays information about signals emitted by an object.
*/
class KID3_CORE_EXPORT SignalEmissionDumper : public QObject {
Q_OBJECT
public:
/**
* Constructor.
* @param parent parent object
*/
explicit SignalEmissionDumper(QObject* parent = 0);
/**
* Destructor.
*/
virtual ~SignalEmissionDumper();
/**
* Monitor signal emissions of object
* @param obj object to monitor
*/
void connectObject(QObject* obj);
private slots:
void printSignal();
};
/**
* Dump an item model.
* @param model item model to dump
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment