Changeset - cf2136c2b501
[Not reviewed]
portlist
0 3 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-09-05 01:35:49
hy@ozderya.net
use full port text (not just name) for selections
3 files changed with 14 insertions and 6 deletions:
0 comments (0 inline, 0 general)
portcontrol.cpp
Show inline comments
 
@@ -220,13 +220,21 @@ void PortControl::togglePort()
 
    {
 
        // we get the port name from the edit text, which may not be
 
        // in the portList if user hasn't pressed Enter
 
        QString portName = ui->cbPortList->currentText();
 
        int portIndex = portList.indexOf(portName);
 
        // Also note that, portText may not be the `portName`
 
        QString portText = ui->cbPortList->currentText();
 
        QString portName;
 
        int portIndex = portList.indexOf(portText);
 
        if (portIndex < 0) // not in list, add to model and update the selections
 
        {
 
            portList.appendRow(new PortListItem(portName));
 
            portList.appendRow(new PortListItem(portText));
 
            ui->cbPortList->setCurrentIndex(portList.rowCount()-1);
 
            tbPortList.setCurrentIndex(portList.rowCount()-1);
 
            portName = portText;
 
        }
 
        else
 
        {
 
            // get the port name from the data field
 
            portName = static_cast<PortListItem*>(portList.item(portIndex))->portName();
 
        }
 

	
 
        serialPort->setPortName(ui->cbPortList->currentData(PortNameRole).toString());
portlist.cpp
Show inline comments
 
@@ -90,11 +90,11 @@ void PortList::loadPortList()
 
                     this, SLOT(onRowsInserted(QModelIndex, int, int)));
 
}
 

	
 
int PortList::indexOf(QString portName)
 
int PortList::indexOf(QString portText)
 
{
 
    for (int i = 0; i < rowCount(); i++)
 
    {
 
        if (static_cast<PortListItem*>(item(i))->portName() == portName)
 
        if (item(i)->text() == portText)
 
        {
 
            return i;
 
        }
portlist.h
Show inline comments
 
@@ -50,7 +50,7 @@ public:
 
    PortList(QObject* parent=0);
 

	
 
    void loadPortList();
 
    int indexOf(QString portName); // return -1 if not found
 
    int indexOf(QString portText); // return -1 if not found
 

	
 
private:
 
    QStringList userEnteredPorts;
0 comments (0 inline, 0 general)