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 <QVector>
12
35{
36public:
40 template<class Sender, class Signal, class Receiver, class Method>
41 inline KisSignalAutoConnection(Sender sender, Signal signal,
42 Receiver receiver, Method method,
43 Qt::ConnectionType type = Qt::AutoConnection)
44 : m_connection(QObject::connect(sender, signal, receiver, method, type))
45 {
46 }
47
49 {
50 QObject::disconnect(m_connection);
51 }
52
53private:
55
56private:
57 QMetaObject::Connection m_connection;
58};
59
61
62
71{
72public:
79 template<class Sender, class Signal, class Receiver, class Method>
80 inline void addConnection(Sender sender, Signal signal,
81 Receiver receiver, Method method,
82 Qt::ConnectionType type = Qt::AutoConnection)
83 {
85 new KisSignalAutoConnection(sender, signal,
86 receiver, method, type)));
87 }
88
94 template<class Sender, class Signal, class Receiver, class Method>
95 inline void addUniqueConnection(Sender sender, Signal signal,
96 Receiver receiver, Method method)
97 {
99 new KisSignalAutoConnection(sender, signal,
100 receiver, method, Qt::UniqueConnection)));
101 }
102
106 inline void clear() {
107 m_connections.clear();
108 }
109
110 inline bool isEmpty() {
111 return m_connections.isEmpty();
112 }
113
114private:
116};
117
118#endif /* __KIS_SIGNAL_AUTO_CONNECTOR_H */
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
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