15 #include "interfacelistconnector.h"
20 #include <QPushButton>
22 #include <QTableWidget>
23 #include <QApplication>
25 XInterfaceListConnector::XInterfaceListConnector(
26 const shared_ptr<XInterfaceList> &node, QTableWidget *item)
28 connect(m_pItem, SIGNAL(cellClicked(
int,
int)),
29 this, SLOT(cellClicked(
int,
int)) );
30 item->setColumnCount(5);
32 item->setColumnWidth(0, (
int)(def * 1.5));
33 item->setColumnWidth(1, (
int)(def * 1.2));
34 item->setColumnWidth(2, (
int)(def * 2));
35 item->setColumnWidth(3, (
int)(def * 2));
36 item->setColumnWidth(4, (
int)(def * 1));
38 labels += i18n(
"Driver");
39 labels += i18n(
"Control");
40 labels += i18n(
"Device");
41 labels += i18n(
"Port");
42 labels += i18n(
"Addr");
43 item->setHorizontalHeaderLabels(labels);
47 for(
int idx = 0; idx < shot.size(); ++idx) {
49 e.emitter = node.get();
50 e.caught = shot.list()->at(idx);
59 for(
auto it = m_cons.begin(); it != m_cons.end(); it++) {
60 if(it->interface->control().get() == node) {
61 if(shot[ *it->interface->control()]) {
63 QApplication::style()->standardIcon(QStyle::SP_MediaStop));
64 it->btn->setText(i18n(
"&STOP"));
68 QApplication::style()->standardIcon(QStyle::SP_MediaPlay));
69 it->btn->setText(i18n(
"&RUN"));
76 auto interface = static_pointer_cast<
XInterface>(e.caught);
77 int i = m_pItem->rowCount();
78 m_pItem->insertRow(i);
79 m_pItem->setItem(i, 0,
new QTableWidgetItem(interface->getLabel().c_str()));
80 m_cons.push_back(tcons());
81 tcons &con(m_cons.back());
82 con.interface = interface;
83 con.btn =
new QPushButton(m_pItem);
84 con.btn->setCheckable(
true);
85 con.btn->setAutoDefault(
false);
86 con.btn->setFlat(
true);
87 con.concontrol = xqcon_create<XQToggleButtonConnector>(interface->control(), con.btn);
88 m_pItem->setCellWidget(i, 1, con.btn);
89 QComboBox *cmbdev(
new QComboBox(m_pItem) );
90 con.condev = xqcon_create<XQComboBoxConnector>(interface->device(), cmbdev,
Snapshot( *interface->device()));
91 m_pItem->setCellWidget(i, 2, cmbdev);
92 QLineEdit *edPort(
new QLineEdit(m_pItem) );
93 con.conport = xqcon_create<XQLineEditConnector>(interface->port(), edPort,
false);
94 m_pItem->setCellWidget(i, 3, edPort);
95 QSpinBox *numAddr(
new QSpinBox(m_pItem) );
96 numAddr->setRange(0, 255);
97 numAddr->setSingleStep(1);
98 con.conaddr = xqcon_create<XQSpinBoxUnsignedConnector>(interface->address(), numAddr);
99 m_pItem->setCellWidget(i, 4, numAddr);
102 con.lsnOnControlChanged = tr[ *interface->control()].onValueChanged().connectWeakly(
103 shared_from_this(), &XInterfaceListConnector::onControlChanged,
104 XListener::FLAG_MAIN_THREAD_CALL);
106 onControlChanged(shot, interface->control().get());
111 for(
auto it = m_cons.begin(); it != m_cons.end();) {
112 if(it->interface == e.released) {
113 for(
int i = 0; i < m_pItem->rowCount(); i++) {
114 if(m_pItem->cellWidget(i, 1) == it->btn) m_pItem->removeRow(i);
116 it = m_cons.erase(it);
124 XInterfaceListConnector::cellClicked (
int row,
int ) {
125 for(
auto it = m_cons.begin(); it != m_cons.end(); it++)
127 if(m_pItem->cellWidget(row, 1) == it->btn)
128 it->interface->driver()->showForms();