From: Manuel Nickschas Date: Fri, 24 Sep 2010 17:27:28 +0000 (+0200) Subject: Prettify qDebug() output for events X-Git-Tag: 0.8-beta1~116 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=80cd03dc284fecbac2b7db1ede215f82023b72d9 Prettify qDebug() output for events --- diff --git a/src/common/event.cpp b/src/common/event.cpp index 3803ab96..01d96426 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -25,3 +25,14 @@ Event::Event(EventManager::EventType type) { } + +QDebug operator<<(QDebug dbg, Event *e) { + dbg.nospace() << qPrintable(e->className()) << "(" + << "type = 0x" << qPrintable(QString::number(e->type(), 16)); + e->debugInfo(dbg); + //<< ", data = " << e->data(); // we don't use data anywhere yet + dbg.nospace() << ", flags = 0x" << qPrintable(QString::number(e->flags(), 16)) + << ")"; + return dbg.space(); +} + diff --git a/src/common/event.h b/src/common/event.h index 9fd6373f..82cd1aca 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -21,6 +21,8 @@ #ifndef EVENT_H #define EVENT_H +#include + #include "eventmanager.h" class Event { @@ -39,15 +41,23 @@ public: inline void stop() { setFlag(EventManager::Stopped); } inline bool isStopped() { return _flags.testFlag(EventManager::Stopped); } - inline void setData(const QVariant &data) { _data = data; } - inline QVariant data() const { return _data; } + //inline void setData(const QVariant &data) { _data = data; } + //inline QVariant data() const { return _data; } + +protected: + virtual inline QString className() const { return "Event"; } + virtual inline void debugInfo(QDebug &dbg) const { Q_UNUSED(dbg); } private: EventManager::EventType _type; EventManager::EventFlags _flags; - QVariant _data; + //QVariant _data; + + friend QDebug operator<<(QDebug dbg, Event *e); }; +QDebug operator<<(QDebug dbg, Event *e); + /*******/ #endif diff --git a/src/common/eventmanager.cpp b/src/common/eventmanager.cpp index 2a20b214..552765a2 100644 --- a/src/common/eventmanager.cpp +++ b/src/common/eventmanager.cpp @@ -48,6 +48,10 @@ EventManager::EventType EventManager::eventGroupByName(const QString &name) cons return type == Invalid? Invalid : static_cast(type & EventGroupMask); } +QString EventManager::enumName(EventType type) const { + return eventEnum().valueToKey(type); +} + /* NOTE: Registering and calling handlers works fine even if they specify a subclass of Event as their parameter. However, this most probably is a result from a reinterpret_cast somewhere deep inside Qt, so there is *no* @@ -102,6 +106,7 @@ void EventManager::registerEventHandler(QList events, QObject *object // not threadsafe! if we should want that, we need to add a mutexed queue somewhere in this general area. void EventManager::sendEvent(Event *event) { + // qDebug() << "Sending" << event; dispatchEvent(event); } diff --git a/src/common/eventmanager.h b/src/common/eventmanager.h index d7480d1c..73ff8b7e 100644 --- a/src/common/eventmanager.h +++ b/src/common/eventmanager.h @@ -105,6 +105,7 @@ public: EventType eventTypeByName(const QString &name) const; EventType eventGroupByName(const QString &name) const; + QString enumName(EventType type) const; public slots: void registerObject(QObject *object, Priority priority = NormalPriority, const QString &methodPrefix = "handle"); diff --git a/src/common/ircevent.h b/src/common/ircevent.h index 6704013d..0f4336df 100644 --- a/src/common/ircevent.h +++ b/src/common/ircevent.h @@ -37,6 +37,14 @@ public: inline QStringList params() const { return _params; } inline void setParams(const QStringList ¶ms) { _params = params; } +protected: + virtual inline QString className() const { return "IrcEvent"; } + virtual inline void debugInfo(QDebug &dbg) const { + NetworkEvent::debugInfo(dbg); + dbg << ", prefix = " << qPrintable(prefix()) + << ", params = " << params(); + } + private: QString _prefix; QStringList _params; @@ -56,6 +64,16 @@ public: inline QString target() const { return _target; } inline void setTarget(const QString &target) { _target = target; } +protected: + virtual inline QString className() const { return "IrcEventNumeric"; } + virtual inline void debugInfo(QDebug &dbg) const { + dbg << ", num = " << number(); + NetworkEvent::debugInfo(dbg); + dbg << ", target = " << qPrintable(target()) + << ", prefix = " << qPrintable(prefix()) + << ", params = " << params(); + } + private: uint _number; QString _target; @@ -75,6 +93,16 @@ public: inline QByteArray rawMessage() const { return _rawMessage; } inline void setRawMessage(const QByteArray &rawMessage) { _rawMessage = rawMessage; } +protected: + virtual inline QString className() const { return "IrcEventRawMessage"; } + virtual inline void debugInfo(QDebug &dbg) const { + NetworkEvent::debugInfo(dbg); + dbg << ", target = " << qPrintable(target()) + << ", prefix = " << qPrintable(prefix()) + << ", msg = " << rawMessage(); + } + + private: QByteArray _rawMessage; }; diff --git a/src/common/messageevent.h b/src/common/messageevent.h index 10803cbc..11e9987e 100644 --- a/src/common/messageevent.h +++ b/src/common/messageevent.h @@ -52,6 +52,18 @@ public: inline void setMsgFlag(Message::Flag flag) { _msgFlags |= flag; } inline void setMsgFlags(Message::Flags flags) { _msgFlags = flags; } +protected: + virtual inline QString className() const { return "MessageEvent"; } + virtual inline void debugInfo(QDebug &dbg) const { + NetworkEvent::debugInfo(dbg); + dbg.nospace() << ", sender = " << qPrintable(sender()) + << ", target = " << qPrintable(target()) + << ", text = " << text() + << ", msgtype = " << qPrintable(QString::number(msgType(), 16)) + << ", buffertype = " << qPrintable(QString::number(bufferType(), 16)) + << ", msgflags = " << qPrintable(QString::number(msgFlags(), 16)); + } + private: BufferInfo::Type bufferTypeByTarget(const QString &target) const; diff --git a/src/common/networkevent.h b/src/common/networkevent.h index dfa492d7..67b47a0f 100644 --- a/src/common/networkevent.h +++ b/src/common/networkevent.h @@ -38,6 +38,10 @@ public: inline NetworkId networkId() const { return network()? network()->networkId() : NetworkId(); } inline Network *network() const { return _network; } +protected: + virtual inline QString className() const { return "NetworkEvent"; } + virtual inline void debugInfo(QDebug &dbg) const { dbg.nospace() << ", net = " << qPrintable(_network->networkName()); } + private: Network *_network; }; @@ -53,6 +57,13 @@ public: inline Network::ConnectionState connectionState() const { return _state; } inline void setConnectionState(Network::ConnectionState state) { _state = state; } +protected: + virtual inline QString className() const { return "NetworkConnectionEvent"; } + virtual inline void debugInfo(QDebug &dbg) const { + NetworkEvent::debugInfo(dbg); + dbg.nospace() << ", state = " << qPrintable(QString::number(_state)); + } + private: Network::ConnectionState _state; }; @@ -68,6 +79,13 @@ public: inline QByteArray data() const { return _data; } inline void setData(const QByteArray &data) { _data = data; } +protected: + virtual inline QString className() const { return "NetworkDataEvent"; } + virtual inline void debugInfo(QDebug &dbg) const { + NetworkEvent::debugInfo(dbg); + dbg.nospace() << ", data = " << data(); + } + private: QByteArray _data; };