# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2015-09-05 01:35:49 # Node ID cf2136c2b50122827de9ddac52192d2836e47f8c # Parent 73e87165649b8da02ade345ecd4fea86a683a84c use full port text (not just name) for selections diff --git a/portcontrol.cpp b/portcontrol.cpp --- a/portcontrol.cpp +++ b/portcontrol.cpp @@ -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(portList.item(portIndex))->portName(); } serialPort->setPortName(ui->cbPortList->currentData(PortNameRole).toString()); diff --git a/portlist.cpp b/portlist.cpp --- a/portlist.cpp +++ b/portlist.cpp @@ -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(item(i))->portName() == portName) + if (item(i)->text() == portText) { return i; } diff --git a/portlist.h b/portlist.h --- a/portlist.h +++ b/portlist.h @@ -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;