Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SignalCurry.h « src - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1b5d9d3e0fbb8b4233d2b0eb59c20a6c6098eb84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2005-2020 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#ifndef MUMBLE_SIGNAL_CURRY_H_
#define MUMBLE_SIGNAL_CURRY_H_

#include <QObject>
#include <QVariant>

/**
 * \brief Small class for binding a QVariant parameter to a parameterless signal.
 * Static usage:
 *    SignalCurry::curry(sender, SIGNAL(emitted()), receiver, SLOT(called(QVariant)), curryParameter);
 */
class SignalCurry : public QObject {
	Q_OBJECT
	Q_DISABLE_COPY(SignalCurry)
private:
	bool bDeleteAfterFirstUse;
	QVariant qvData;

public:
	SignalCurry(QVariant data, bool deleteAfterFirstUse = false, QObject *p = 0)
		: QObject(p), bDeleteAfterFirstUse(deleteAfterFirstUse), qvData(data) {}

	static void curry(QObject *sender, const char *signal, QObject *receiver, const char *slot, QVariant data) {
		SignalCurry *c = new SignalCurry(data);
		connect(receiver, slot, c, SIGNAL(called(QVariant)));
		connect(sender, signal, c, SLOT(call));
	}

signals:
	void called(QVariant data);
public slots:
	void call() {
		emit called(qvData);
		if (bDeleteAfterFirstUse)
			deleteLater();
	}
};


#endif