Changeset - 9b553a2ff43b
[Not reviewed]
portlist
0 2 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-09-03 14:43:13
hy@ozderya.net
connected cbPortList to PortList model, and synchronized with toolbar combobox
2 files changed with 25 insertions and 34 deletions:
0 comments (0 inline, 0 general)
portcontrol.cpp
Show inline comments
 
@@ -43,8 +43,16 @@ PortControl::PortControl(QSerialPort* po
 
                     this, &PortControl::openActionTriggered);
 
    portToolBar.addAction(&openAction);
 

	
 
    portToolBar.addWidget(&tbPortListBox);
 
    tbPortListBox.setModel(&portList);
 
    portToolBar.addWidget(&tbPortList);
 
    tbPortList.setModel(&portList);
 

	
 
    ui->cbPortList->setModel(&portList);
 
    QObject::connect(ui->cbPortList,
 
                     SELECT<int>::OVERLOAD_OF(&QComboBox::activated),
 
                     this, &PortControl::onCbPortListActivated);
 
    QObject::connect(&tbPortList,
 
                     SELECT<int>::OVERLOAD_OF(&QComboBox::activated),
 
                     this, &PortControl::onTbPortListActivated);
 

	
 
    // setup buttons
 
    QObject::connect(ui->pbReloadPorts, &QPushButton::clicked,
 
@@ -121,37 +129,7 @@ PortControl::~PortControl()
 

	
 
void PortControl::loadPortList()
 
{
 
    QString currentSelection = ui->cbPortList->currentText();
 

	
 
    ui->cbPortList->clear();
 

	
 
    discoveredPorts.clear();
 
    for (auto port : QSerialPortInfo::availablePorts())
 
    {
 
        QString pName = port.portName();
 
        if (!port.description().isEmpty()) pName += QString(" ") + port.description();
 
        if (port.hasProductIdentifier())
 
        {
 
            QString vID = QString("%1").arg(port.vendorIdentifier(), 4, 16, QChar('0'));
 
            QString pID = QString("%1").arg(port.productIdentifier(), 4, 16, QChar('0'));
 
            pName = pName + " [" + vID + ":" + pID + "]";
 
        }
 
        ui->cbPortList->addItem(pName);
 
        discoveredPorts << port.portName();
 
    }
 

	
 
    ui->cbPortList->addItems(userEnteredPorts);
 

	
 
    // find current selection in the new list, maybe it doesn't exist anymore?
 
    int currentSelectionIndex = ui->cbPortList->findText(currentSelection);
 
    if (currentSelectionIndex >= 0)
 
    {
 
        ui->cbPortList->setCurrentIndex(currentSelectionIndex);
 
    }
 
    else // our port doesn't exist anymore, close port if it's open
 
    {
 
        if (serialPort->isOpen()) togglePort();
 
    }
 
    portList.loadPortList();
 
}
 

	
 
void PortControl::loadBaudRateList()
 
@@ -306,3 +284,13 @@ void PortControl::openActionTriggered(bo
 
{
 
    togglePort();
 
}
 

	
 
void PortControl::onCbPortListActivated(int index)
 
{
 
    tbPortList.setCurrentIndex(index);
 
}
 

	
 
void PortControl::onTbPortListActivated(int index)
 
{
 
    ui->cbPortList->setCurrentIndex(index);
 
}
portcontrol.h
Show inline comments
 
@@ -56,7 +56,7 @@ private:
 

	
 
    QToolBar portToolBar;
 
    QAction openAction;
 
    QComboBox tbPortListBox;
 
    QComboBox tbPortList;
 
    PortList portList;
 

	
 
    QStringList discoveredPorts; // list of port names returned by availablePorts
 
@@ -80,6 +80,9 @@ private slots:
 
    void onPortNameChanged(QString portName);
 
    void openActionTriggered(bool checked);
 

	
 
    void onCbPortListActivated(int index);
 
    void onTbPortListActivated(int index);
 

	
 
signals:
 
    void skipByteRequested();
 
    void portToggled(bool open);
0 comments (0 inline, 0 general)