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
 
@@ -217,19 +217,27 @@ void PortControl::togglePort()
 
        emit portToggled(false);
 
    }
 
    else
 
    {
 
        // 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());
 

	
 
        // open port
 
        if (serialPort->open(QIODevice::ReadWrite))
portlist.cpp
Show inline comments
 
@@ -87,17 +87,17 @@ void PortList::loadPortList()
 
        appendRow(new PortListItem(portName));
 
    }
 
    QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
 
                     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;
 
        }
 
    }
 
    return -1; // not found
 
}
portlist.h
Show inline comments
 
@@ -47,13 +47,13 @@ class PortList : public QStandardItemMod
 
{
 
    Q_OBJECT
 
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;
 

	
 
private slots:
 
    void onRowsInserted(QModelIndex parent, int start, int end);
0 comments (0 inline, 0 general)