@@ -25,7 +25,10 @@ namespace SerialPABotBase{
2525
2626
2727
28- class SerialPABotBase2_SelectorWidget : public NoWheelCompactComboBox {
28+ class SerialPABotBase2_SelectorWidget
29+ : public NoWheelCompactComboBox
30+ , public SerialPortPoller::Listener
31+ {
2932public:
3033 SerialPABotBase2_SelectorWidget (
3134 ControllerSelectorWidget& parent,
@@ -52,7 +55,7 @@ class SerialPABotBase2_SelectorWidget : public NoWheelCompactComboBox{
5255 parent.session ().set_device (descriptor);
5356 }
5457
55- refresh_devices ();
58+ refresh_devices (SerialPortPoller::instance (). ports () );
5659
5760 connect (
5861 this , static_cast <void (QComboBox::*)(int )>(&QComboBox::activated),
@@ -69,13 +72,18 @@ class SerialPABotBase2_SelectorWidget : public NoWheelCompactComboBox{
6972 }
7073
7174 parent.session ().set_device (selected);
72- refresh_devices ();
75+ refresh_devices (SerialPortPoller::instance (). ports () );
7376 }
7477 );
78+
79+ SerialPortPoller::instance ().add_listener (*this );
80+ }
81+ ~SerialPABotBase2_SelectorWidget (){
82+ SerialPortPoller::instance ().remove_listener (*this );
7583 }
7684
77- void refresh_devices (){
78- SerialPortPoller::instance ().begin_refresh_now ();
85+ void refresh_devices (const QList<QSerialPortInfo>& ports ){
86+ // SerialPortPoller::instance().begin_refresh_now();
7987// cout << "Current = " << width() << " x " << height() << endl;
8088// cout << "sizeHint = " << sizeHint().width() << " x " << sizeHint().height() << endl;
8189// cout << "minimumContentsLength = " << this->minimumContentsLength() << endl;
@@ -87,7 +95,7 @@ class SerialPABotBase2_SelectorWidget : public NoWheelCompactComboBox{
8795
8896
8997 m_ports.emplace_back (new SerialPABotBase2_Descriptor ());
90- for (QSerialPortInfo& port : SerialPortPoller::instance (). ports () ){
98+ for (const QSerialPortInfo& port : ports){
9199 if (filter_serial_port (port)){
92100 m_ports.emplace_back (
93101 new SerialPABotBase2_Descriptor (port.portName ().toStdString ())
@@ -115,6 +123,10 @@ class SerialPABotBase2_SelectorWidget : public NoWheelCompactComboBox{
115123 setCurrentIndex (index);
116124 }
117125
126+ virtual void on_serial_ports_changed (const QList<QSerialPortInfo>& ports) override {
127+ refresh_devices (ports);
128+ }
129+
118130
119131private:
120132 ControllerSelectorWidget& m_parent;
0 commit comments