Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_signal_auto_connection.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef __KIS_SIGNAL_AUTO_CONNECTOR_H
8#define __KIS_SIGNAL_AUTO_CONNECTOR_H
9
10#include <QObject>
11#include <QSharedPointer>
12#include <QVector>
13
36{
37public:
41 template<class Sender, class Signal, class Receiver, class Method>
42 inline KisSignalAutoConnection(Sender sender, Signal signal,
43 Receiver receiver, Method method,
44 Qt::ConnectionType type = Qt::AutoConnection)
45 : m_connection(QObject::connect(sender, signal, receiver, method, type))
46 {
47 }
48
50 {
51 QObject::disconnect(m_connection);
52 }
53
54private:
56
57private:
58 QMetaObject::Connection m_connection;
59};
60
62
63
72{
73public:
80 template<class Sender, class Signal, class Receiver, class Method>
81 inline void addConnection(Sender sender, Signal signal,
82 Receiver receiver, Method method,
83 Qt::ConnectionType type = Qt::AutoConnection)
84 {
86 new KisSignalAutoConnection(sender, signal,
87 receiver, method, type)));
88 }
89
95 template<class Sender, class Signal, class Receiver, class Method>
96 inline void addUniqueConnection(Sender sender, Signal signal,
97 Receiver receiver, Method method)
98 {
100 new KisSignalAutoConnection(sender, signal,
101 receiver, method, Qt::UniqueConnection)));
102 }
103
107 inline void clear() {
108 m_connections.clear();
109 }
110
111 inline bool isEmpty() {
112 return m_connections.isEmpty();
113 }
114
115private:
117};
118
119#endif /* __KIS_SIGNAL_AUTO_CONNECTOR_H */
QMetaObject::Connection m_connection
KisSignalAutoConnection(Sender sender, Signal signal, Receiver receiver, Method method, Qt::ConnectionType type=Qt::AutoConnection)
KisSignalAutoConnection(const KisSignalAutoConnection &rhs)
void addUniqueConnection(Sender sender, Signal signal, Receiver receiver, Method method)
QVector< KisSignalAutoConnectionSP > m_connections
void addConnection(Sender sender, Signal signal, Receiver receiver, Method method, Qt::ConnectionType type=Qt::AutoConnection)
QSharedPointer< KisSignalAutoConnection > KisSignalAutoConnectionSP