qpidctrl  0.7.1
qpidcommportselector.cpp
Go to the documentation of this file.
1 #include "qpidcommportselector.h"
2 #include "ui_qpidcommportselector.h"
3 #include "qpidcommport.h"
4 #include <QComboBox>
5 #include <QLineEdit>
6 #include <QSpinBox>
7 #include <QLabel>
8 #include "qextserialenumerator.h"
9 
11  QWidget(parent),
12  ui(new Ui::QPidCommPortSelector)
13 {
14  ui->setupUi(this);
15 
16  connect(ui->m_PortType, SIGNAL(currentIndexChanged(int)), ui->m_PortTypePages, SLOT(setCurrentIndex(int)));
17 }
18 
20 {
21  delete ui;
22 }
23 
25 {
26  m_CommPort = port;
27 
28  ui->m_PortType->clear();
29  ui->m_PortType->addItems(m_CommPort->commPortTypes());
30 
31  ui->m_SerialPortBaud->clear();
32  ui->m_SerialPortBaud->addItems(m_CommPort->commPortBaudRates());
33 
34  ui->m_SerialPortDataBits->clear();
35  ui->m_SerialPortDataBits->addItems(m_CommPort->commPortDataBits());
36 
37  ui->m_SerialPortFlowControl->clear();
38  ui->m_SerialPortFlowControl->addItems(m_CommPort->commPortFlowControls());
39 
40  ui->m_SerialPortParity->clear();
41  ui->m_SerialPortParity->addItems(m_CommPort->commPortParitys());
42 
43  ui->m_SerialPortStopBits->clear();
44  ui->m_SerialPortStopBits->addItems(m_CommPort->commPortStopBits());
45 
46  connect(ui->m_PortType, SIGNAL(currentIndexChanged(int)), this, SLOT(onPortTypeChanged(int)));
47 
48  onPortTypeChanged(m_CommPort->get_CommPortType());
49 
50  QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
51 
52  QString portName = m_CommPort->get_SerialPortName();
53 
54  for (int i=0; i<ports.count(); i++) {
55  QextPortInfo port = ports.value(i);
56 
57  QString aPortName = port.portName;
58 
59  ui->m_SerialPortName->addItem(aPortName);
60 
61  if (portName == aPortName) {
62  ui->m_SerialPortName->setCurrentIndex(i);
63  }
64  }
65 
66  ui->m_SerialPortBaud->setCurrentIndex(m_CommPort->get_SerialPortBaud());
67  ui->m_SerialPortDataBits->setCurrentIndex(m_CommPort->get_SerialPortBits());
68  ui->m_SerialPortFlowControl->setCurrentIndex(m_CommPort->get_SerialPortFlowControl());
69  ui->m_SerialPortParity->setCurrentIndex(m_CommPort->get_SerialPortParity());
70  ui->m_SerialPortStopBits->setCurrentIndex(m_CommPort->get_SerialPortStopBits());
71 
72  ui->m_SocketHostAddress->setText(m_CommPort->get_SocketHostAddress());
73  ui->m_SocketPortNumber->setValue(m_CommPort->get_SocketPortNumber());
74 
75  ui->m_EpicsPVName->setText(m_CommPort->get_EpicsPVName());
76 }
77 
79 {
80  ui->m_PortType->setCurrentIndex(newType);
81  ui->m_SerialPortName->setEnabled(false);
82  ui->m_SocketHostAddress->setEnabled(false);
83  ui->m_SocketPortNumber->setEnabled(false);
84  ui->m_EpicsPVName->setEnabled(false);
85  ui->m_SerialPortNameLabel->setEnabled(false);
86  ui->m_SocketHostAddressLabel->setEnabled(false);
87  ui->m_SocketPortNumberLabel->setEnabled(false);
88  ui->m_EpicsPVNameLabel->setEnabled(false);
89 
90  switch (newType) {
92  break;
93 
95  ui->m_SerialPortName->setEnabled(true);
96  ui->m_SerialPortNameLabel->setEnabled(true);
97  break;
98 
100  ui->m_SocketHostAddress->setEnabled(true);
101  ui->m_SocketPortNumber->setEnabled(true);
102  ui->m_SocketHostAddressLabel->setEnabled(true);
103  ui->m_SocketPortNumberLabel->setEnabled(true);
104  break;
105 
107  ui->m_EpicsPVName->setEnabled(true);
108  ui->m_EpicsPVNameLabel->setEnabled(true);
109  break;
110 
111  }
112 }
113 
115 {
116  if (m_CommPort) {
117  m_CommPort->set_CommPortType(ui->m_PortType->currentIndex());
118 
119  m_CommPort->set_SerialPortName(ui->m_SerialPortName->currentText());
120 
121  m_CommPort->set_SocketHostAddress(ui->m_SocketHostAddress->text());
122  m_CommPort->set_SocketPortNumber(ui->m_SocketPortNumber->value());
123 
124  m_CommPort->set_EpicsPVName(ui->m_EpicsPVName->text());
125  m_CommPort->set_SerialPortBaud(ui->m_SerialPortBaud->currentIndex());
126  m_CommPort->set_SerialPortBits(ui->m_SerialPortDataBits->currentIndex());
127  m_CommPort->set_SerialPortFlowControl(ui->m_SerialPortFlowControl->currentIndex());
128  m_CommPort->set_SerialPortParity(ui->m_SerialPortParity->currentIndex());
129  m_CommPort->set_SerialPortStopBits(ui->m_SerialPortStopBits->currentIndex());
130  }
131 }
QPidCommPortPtr m_CommPort
QPidCommPortSelector(QWidget *parent=0)
void onPortTypeChanged(int newType)
Ui::QPidCommPortSelector * ui
void setCommPort(QPidCommPortPtr port)
QSharedPointer< QPidCommPort > QPidCommPortPtr