mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Improve interface
This commit is contained in:
parent
333e663ad1
commit
256b24ff21
|
@ -34,28 +34,16 @@ public:
|
|||
|
||||
bool clearHistory() override;
|
||||
|
||||
CHANGED_SIGNAL_IMPL(QString, AboutFriend, name)
|
||||
CHANGED_SIGNAL_IMPL(QString, AboutFriend, status)
|
||||
CHANGED_SIGNAL_IMPL(QString, AboutFriend, publicKey)
|
||||
SIGNAL_IMPL(AboutFriend, nameChanged, const QString&)
|
||||
SIGNAL_IMPL(AboutFriend, statusChanged, const QString&)
|
||||
SIGNAL_IMPL(AboutFriend, publicKeyChanged, const QString&)
|
||||
|
||||
CHANGED_SIGNAL_IMPL(QPixmap, AboutFriend, avatar)
|
||||
CHANGED_SIGNAL_IMPL(QString, AboutFriend, note)
|
||||
SIGNAL_IMPL(AboutFriend, avatarChanged, const QPixmap&)
|
||||
SIGNAL_IMPL(AboutFriend, noteChanged, const QString&)
|
||||
|
||||
CHANGED_SIGNAL_IMPL(QString, AboutFriend, autoAcceptDir)
|
||||
CHANGED_SIGNAL_IMPL(AutoAcceptCallFlags, AboutFriend, autoAcceptCall)
|
||||
CHANGED_SIGNAL_IMPL(bool, AboutFriend, autoGroupInvite)
|
||||
|
||||
signals:
|
||||
void nameChanged(const QString& name);
|
||||
void statusChanged(const QString& status);
|
||||
void publicKeyChanged(const QString& pk);
|
||||
|
||||
void avatarChanged(const QPixmap& avatar);
|
||||
void noteChanged(const QString& val);
|
||||
|
||||
void autoAcceptDirChanged(const QString& path);
|
||||
void autoAcceptCallChanged(const AutoAcceptCallFlags& flag);
|
||||
void autoGroupInviteChanged(const bool& enabled);
|
||||
SIGNAL_IMPL(AboutFriend, autoAcceptDirChanged, const QString&)
|
||||
SIGNAL_IMPL(AboutFriend, autoAcceptCallChanged, AutoAcceptCallFlags)
|
||||
SIGNAL_IMPL(AboutFriend, autoGroupInviteChanged, bool)
|
||||
|
||||
private:
|
||||
const Friend* const f;
|
||||
|
|
|
@ -39,16 +39,16 @@ public:
|
|||
virtual bool clearHistory() = 0;
|
||||
|
||||
/* signals */
|
||||
CHANGED_SIGNAL(QString, name);
|
||||
CHANGED_SIGNAL(QString, status);
|
||||
CHANGED_SIGNAL(QString, publicKey);
|
||||
DECLARE_SIGNAL(nameChanged, const QString&);
|
||||
DECLARE_SIGNAL(statusChanged, const QString&);
|
||||
DECLARE_SIGNAL(publicKeyChanged, const QString&);
|
||||
|
||||
CHANGED_SIGNAL(QPixmap, avatar);
|
||||
CHANGED_SIGNAL(QString, note);
|
||||
DECLARE_SIGNAL(avatarChanged, const QPixmap&);
|
||||
DECLARE_SIGNAL(noteChanged, const QString&);
|
||||
|
||||
CHANGED_SIGNAL(QString, autoAcceptDir);
|
||||
CHANGED_SIGNAL(AutoAcceptCallFlags, autoAcceptCall);
|
||||
CHANGED_SIGNAL(bool, autoGroupInvite);
|
||||
DECLARE_SIGNAL(autoAcceptDirChanged, const QString&);
|
||||
DECLARE_SIGNAL(autoAcceptCallChanged, AutoAcceptCallFlags);
|
||||
DECLARE_SIGNAL(autoGroupInviteChanged, bool);
|
||||
};
|
||||
|
||||
#endif // I_ABOUT_FRIEND_H
|
||||
|
|
|
@ -3,17 +3,15 @@
|
|||
|
||||
#include <functional>
|
||||
|
||||
#define CHANGED_SIGNAL(type, name) \
|
||||
using Slot_##name = std::function<void (const type& val)>; \
|
||||
virtual void connectTo_##name##Changed(Slot_##name slot) = 0; \
|
||||
virtual void connectTo_##name##Changed(QObject* handler, Slot_##name slot) = 0
|
||||
#define DECLARE_SIGNAL(name, ...) \
|
||||
using Slot_##name = std::function<void (__VA_ARGS__)>; \
|
||||
virtual void connectTo_##name(Slot_##name slot) const = 0
|
||||
|
||||
#define CHANGED_SIGNAL_IMPL(type, classname, name) \
|
||||
void connectTo_##name##Changed(Slot_##name slot) override { \
|
||||
connect(this, &classname::name##Changed, slot); \
|
||||
} \
|
||||
void connectTo_##name##Changed(QObject* handler, Slot_##name slot) override { \
|
||||
connect(this, &classname::name##Changed, handler, slot); \
|
||||
#define SIGNAL_IMPL(classname, name, ...) \
|
||||
using Slot_##name = std::function<void (__VA_ARGS__)>; \
|
||||
Q_SIGNAL void name(__VA_ARGS__); \
|
||||
void connectTo_##name(Slot_##name slot) const override { \
|
||||
connect(this, &classname::name, slot); \
|
||||
}
|
||||
|
||||
#endif // INTERFACE_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user