mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(interface): Add connectTo_* virtual method instead of signals
This commit is contained in:
parent
918cdf1368
commit
a626888daa
|
@ -89,7 +89,7 @@ void AboutFriend::setAutoGroupInvite(bool enabled)
|
|||
const ToxPk pk = f->getPublicKey();
|
||||
Settings::getInstance().setAutoGroupInvite(pk, enabled);
|
||||
Settings::getInstance().savePersonal();
|
||||
emit autoGroupInviteChaged(enabled);
|
||||
emit autoGroupInviteChanged(enabled);
|
||||
}
|
||||
|
||||
bool AboutFriend::clearHistory()
|
||||
|
|
|
@ -34,6 +34,29 @@ public:
|
|||
|
||||
bool clearHistory() override;
|
||||
|
||||
CHANGED_SIGNAL_IMPL(QString, AboutFriend, name)
|
||||
CHANGED_SIGNAL_IMPL(QString, AboutFriend, status)
|
||||
CHANGED_SIGNAL_IMPL(QString, AboutFriend, publicKey)
|
||||
|
||||
CHANGED_SIGNAL_IMPL(QPixmap, AboutFriend, avatar)
|
||||
CHANGED_SIGNAL_IMPL(QString, AboutFriend, note)
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
const Friend* const f;
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef I_ABOUT_FRIEND_H
|
||||
#define I_ABOUT_FRIEND_H
|
||||
|
||||
#include "src/model/interface.h"
|
||||
#include <QObject>
|
||||
|
||||
class IAboutFriend : public QObject
|
||||
|
@ -37,17 +38,17 @@ public:
|
|||
|
||||
virtual bool clearHistory() = 0;
|
||||
|
||||
signals:
|
||||
void nameChanged(const QString& name) const;
|
||||
void statusChanged(const QString& status) const;
|
||||
void publicKeyChanged(const QString& pk) const;
|
||||
/* signals */
|
||||
CHANGED_SIGNAL(QString, name);
|
||||
CHANGED_SIGNAL(QString, status);
|
||||
CHANGED_SIGNAL(QString, publicKey);
|
||||
|
||||
void avatarChanged(const QPixmap& avatar) const;
|
||||
void noteChanged(const QString& note) const;
|
||||
CHANGED_SIGNAL(QPixmap, avatar);
|
||||
CHANGED_SIGNAL(QString, note);
|
||||
|
||||
void autoAcceptDirChanged(const QString& dir);
|
||||
void autoAcceptCallChanged(AutoAcceptCall flag);
|
||||
void autoGroupInviteChaged(bool enabled);
|
||||
CHANGED_SIGNAL(QString, autoAcceptDir);
|
||||
CHANGED_SIGNAL(AutoAcceptCallFlags, autoAcceptCall);
|
||||
CHANGED_SIGNAL(bool, autoGroupInvite);
|
||||
};
|
||||
|
||||
#endif // I_ABOUT_FRIEND_H
|
||||
|
|
19
src/model/interface.h
Normal file
19
src/model/interface.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef INTERFACE_H
|
||||
#define INTERFACE_H
|
||||
|
||||
#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 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); \
|
||||
}
|
||||
|
||||
#endif // INTERFACE_H
|
Loading…
Reference in New Issue
Block a user