-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPushButton.cpp
93 lines (78 loc) · 2.26 KB
/
PushButton.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) 2015-2021 Josh Blum
// SPDX-License-Identifier: BSL-1.0
#include <Pothos/Framework.hpp>
#include <Pothos/Object/Containers.hpp>
#include <QPushButton>
#include <map>
/***********************************************************************
* |PothosDoc Push Button
*
* The push button widget emits a specified value when clicked
* on the "triggered" signal.
*
* |category /Widgets
* |keywords click button
*
* |param title The title text displayed on this widget
* |default "My Push Button"
* |widget StringEntry()
*
* |param args Arguments to pass into the toggled signal.
* Example: ["test", 42] - the downstream slot takes two arguments.
* |default []
* |preview valid
*
* |mode graphWidget
* |factory /widgets/push_button()
* |setter setTitle(title)
* |setter setArgs(args)
**********************************************************************/
class PushButton : public QPushButton, public Pothos::Block
{
Q_OBJECT
public:
static Block *make(void)
{
return new PushButton();
}
PushButton(void):
QPushButton(nullptr)
{
this->registerSignal("triggered");
this->registerCall(this, POTHOS_FCN_TUPLE(PushButton, widget));
this->registerCall(this, POTHOS_FCN_TUPLE(PushButton, setTitle));
this->registerCall(this, POTHOS_FCN_TUPLE(PushButton, setArgs));
this->registerCall(this, POTHOS_FCN_TUPLE(PushButton, getArgs));
connect(this, &QPushButton::clicked, this, &PushButton::handleClicked);
}
QWidget *widget(void)
{
return this;
}
void setTitle(const QString &title)
{
QMetaObject::invokeMethod((QPushButton*)this, "handleSetText", Qt::QueuedConnection, Q_ARG(QString, title));
}
void setArgs(const Pothos::ObjectVector &args)
{
_args = args;
}
Pothos::ObjectVector getArgs(void) const
{
return _args;
}
private slots:
void handleClicked(void)
{
this->opaqueCallMethod("triggered", _args.data(), _args.size());
}
void handleSetText(const QString &text)
{
this->setText(text);
}
private:
Pothos::ObjectVector _args;
};
static Pothos::BlockRegistry registerPushButton(
"/widgets/push_button", &PushButton::make);
#include "PushButton.moc"