SerialTerminal: Save and restore selected port name

+ Populate serial ports on startup.

Change-Id: Ie7216bb09ba1ffbb0036019cb4974a14119fc55f
Reviewed-by: Benjamin Balga <balga.benjamin@gmail.com>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Orgad Shaneh
2018-11-15 11:58:05 +02:00
committed by Orgad Shaneh
parent fc5caf3e0f
commit 08b38cff4c
6 changed files with 26 additions and 1 deletions

View File

@@ -79,6 +79,13 @@ void SerialDeviceModel::enablePort(const QString &portName)
m_disabledPorts.remove(portName); m_disabledPorts.remove(portName);
} }
int SerialDeviceModel::indexForPort(const QString &portName) const
{
return Utils::indexOf(m_ports, [portName](const QSerialPortInfo &port) {
return port.portName() == portName;
});
}
void SerialDeviceModel::update() void SerialDeviceModel::update()
{ {
// Called from the combobox before popup, thus updated only when needed and immediately // Called from the combobox before popup, thus updated only when needed and immediately

View File

@@ -46,6 +46,7 @@ public:
void disablePort(const QString &portName); void disablePort(const QString &portName);
void enablePort(const QString &portName); void enablePort(const QString &portName);
int indexForPort(const QString &portName) const;
void update(); void update();

View File

@@ -381,7 +381,8 @@ void SerialOutputPane::createToolButtons()
m_portsSelection = new ComboBox; m_portsSelection = new ComboBox;
m_portsSelection->setSizeAdjustPolicy(QComboBox::AdjustToContents); m_portsSelection->setSizeAdjustPolicy(QComboBox::AdjustToContents);
m_portsSelection->setModel(m_devicesModel); m_portsSelection->setModel(m_devicesModel);
connect(m_portsSelection, &ComboBox::opened, m_devicesModel, &SerialDeviceModel::update); updatePortsList();
connect(m_portsSelection, &ComboBox::opened, this, &SerialOutputPane::updatePortsList);
connect(m_portsSelection, static_cast<void (ComboBox::*)(int)>(&ComboBox::currentIndexChanged), connect(m_portsSelection, static_cast<void (ComboBox::*)(int)>(&ComboBox::currentIndexChanged),
this, &SerialOutputPane::activePortNameChanged); this, &SerialOutputPane::activePortNameChanged);
// TODO: the ports are not updated with the box opened (if the user wait for it) -> add a timer? // TODO: the ports are not updated with the box opened (if the user wait for it) -> add a timer?
@@ -409,6 +410,12 @@ void SerialOutputPane::updateLineEndingsComboBox()
m_lineEndingsSelection->setCurrentIndex(m_settings.defaultLineEndingIndex); m_lineEndingsSelection->setCurrentIndex(m_settings.defaultLineEndingIndex);
} }
void SerialOutputPane::updatePortsList()
{
m_devicesModel->update();
m_portsSelection->setCurrentIndex(m_devicesModel->indexForPort(m_settings.portName));
}
int SerialOutputPane::indexOf(const SerialControl *rc) const int SerialOutputPane::indexOf(const SerialControl *rc) const
{ {
return Utils::indexOf(m_serialControlTabs, [rc](const SerialControlTab &tab) { return Utils::indexOf(m_serialControlTabs, [rc](const SerialControlTab &tab) {
@@ -618,6 +625,8 @@ void SerialOutputPane::activePortNameChanged(int index)
// Update current port name // Update current port name
m_currentPortName = pn; m_currentPortName = pn;
m_settings.setPortName(pn);
emit settingsChanged(m_settings);
} }
void SerialOutputPane::activeBaudRateChanged(int index) void SerialOutputPane::activeBaudRateChanged(int index)

View File

@@ -114,6 +114,7 @@ private:
void createToolButtons(); void createToolButtons();
void updateLineEndingsComboBox(); void updateLineEndingsComboBox();
void updatePortsList();
void contextMenuRequested(const QPoint &pos, int index); void contextMenuRequested(const QPoint &pos, int index);

View File

@@ -120,6 +120,12 @@ void Settings::setBaudRate(qint32 br)
edited = true; edited = true;
} }
void Settings::setPortName(const QString &name)
{
portName = name;
edited = true;
}
QByteArray Settings::defaultLineEnding() const QByteArray Settings::defaultLineEnding() const
{ {
return defaultLineEndingIndex >= (unsigned int)lineEndings.size() return defaultLineEndingIndex >= (unsigned int)lineEndings.size()

View File

@@ -62,6 +62,7 @@ public:
void load(QSettings *settings); void load(QSettings *settings);
void setBaudRate(qint32 br); void setBaudRate(qint32 br);
void setPortName(const QString &name);
QByteArray defaultLineEnding() const; QByteArray defaultLineEnding() const;
QString defaultLineEndingText() const; QString defaultLineEndingText() const;