Skip to content

Commit 5ed7b5c

Browse files
7134956bbogush
authored andcommitted
Qt: UI: Settings: Add serial port selector.
Port selection from list. List updated on click.
1 parent bea147a commit 5ed7b5c

File tree

6 files changed

+148
-58
lines changed

6 files changed

+148
-58
lines changed

qt/clickcombobox.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "clickcombobox.h"
2+
3+
ClickComboBox::ClickComboBox(QWidget *parent) : QComboBox(parent)
4+
{
5+
}
6+
7+
ClickComboBox::~ClickComboBox()
8+
{
9+
}
10+
11+
void ClickComboBox::mousePressEvent(QMouseEvent *e)
12+
{
13+
QString text = currentText();
14+
emit needFill();
15+
bool signalState = blockSignals(true);
16+
setCurrentText(text);
17+
blockSignals(signalState);
18+
19+
QComboBox::mousePressEvent(e);
20+
}

qt/clickcombobox.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef CLICKCOMBOBOX_H
2+
#define CLICKCOMBOBOX_H
3+
4+
#include <QComboBox>
5+
6+
class ClickComboBox : public QComboBox
7+
{
8+
Q_OBJECT
9+
10+
public:
11+
ClickComboBox(QWidget *parent = nullptr);
12+
~ClickComboBox();
13+
14+
protected:
15+
void mousePressEvent(QMouseEvent *e);
16+
17+
signals:
18+
void needFill();
19+
};
20+
21+
#endif // CLICKCOMBOBOX_H

qt/qt.pro

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
QT += core gui
1313

14-
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
14+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets serialport
1515

1616
TARGET = nando
1717
TEMPLATE = app
@@ -44,7 +44,8 @@ SOURCES += main.cpp\
4444
settings_programmer_dialog.cpp \
4545
err.cpp \
4646
about_dialog.cpp \
47-
firmware_update_dialog.cpp
47+
firmware_update_dialog.cpp \
48+
clickcombobox.cpp
4849

4950
HEADERS += main_window.h \
5051
chip_db.h \
@@ -69,7 +70,8 @@ HEADERS += main_window.h \
6970
about_dialog.h \
7071
version.h \
7172
firmware_update_dialog.h \
72-
settings.h
73+
settings.h \
74+
clickcombobox.h
7375

7476
FORMS += main_window.ui \
7577
parallel_chip_db_dialog.ui \

qt/settings_programmer_dialog.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
#include "settings_programmer_dialog.h"
77
#include "ui_settings_programmer_dialog.h"
88

9+
static const char blankString[] = QT_TRANSLATE_NOOP("SettingsDialog", "N/A");
10+
911
SettingsProgrammerDialog::SettingsProgrammerDialog(QWidget *parent) :
1012
QDialog(parent),
1113
ui(new Ui::SettingsProgrammerDialog)
1214
{
1315
ui->setupUi(this);
16+
connect(ui->portInfoListBox, &ClickComboBox::needFill, this, &SettingsProgrammerDialog::fillPortsInfo);
1417
}
1518

1619
SettingsProgrammerDialog::~SettingsProgrammerDialog()
@@ -20,12 +23,13 @@ SettingsProgrammerDialog::~SettingsProgrammerDialog()
2023

2124
void SettingsProgrammerDialog::setUsbDevName(const QString &name)
2225
{
23-
ui->usbDevNameLineEdit->setText(name);
26+
fillPortsInfo();
27+
ui->portInfoListBox->setCurrentIndex(ui->portInfoListBox->findText(name, Qt::MatchStartsWith));
2428
}
2529

2630
QString SettingsProgrammerDialog::getUsbDevName()
2731
{
28-
return ui->usbDevNameLineEdit->text();
32+
return ui->portInfoListBox->currentText().split(':')[0];
2933
}
3034

3135
void SettingsProgrammerDialog::setSkipBB(bool skip)
@@ -67,3 +71,34 @@ bool SettingsProgrammerDialog::isAlertEnabled()
6771
{
6872
return ui->enableAlertCheckBox->isChecked();
6973
}
74+
75+
void SettingsProgrammerDialog::fillPortsInfo()
76+
{
77+
QString selected = ui->portInfoListBox->currentText();
78+
ui->portInfoListBox->clear();
79+
QString description;
80+
QString manufacturer;
81+
QString serialNumber;
82+
const auto infos = QSerialPortInfo::availablePorts();
83+
for (const QSerialPortInfo &info : infos) {
84+
QStringList list;
85+
description = info.description();
86+
manufacturer = info.manufacturer();
87+
serialNumber = info.serialNumber();
88+
#ifdef Q_OS_WIN32
89+
list << info.portName()
90+
#else
91+
list << info.systemLocation()
92+
#endif
93+
<< (!description.isEmpty() ? description : blankString)
94+
<< (!manufacturer.isEmpty() ? manufacturer : blankString)
95+
<< (info.vendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : blankString)
96+
+ ":" + (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : blankString)
97+
<< (!serialNumber.isEmpty() ? serialNumber : blankString);
98+
99+
ui->portInfoListBox->findText(list.first() + description, Qt::MatchStartsWith);
100+
ui->portInfoListBox->addItem(list.first() + ": " + description, list);
101+
}
102+
103+
ui->portInfoListBox->setCurrentText(selected);
104+
}

qt/settings_programmer_dialog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define SETTINGS_PROGRAMMER_DIALOG_H
88

99
#include <QDialog>
10+
#include <QSerialPortInfo>
1011

1112
namespace Ui {
1213
class SettingsProgrammerDialog;
@@ -32,6 +33,9 @@ class SettingsProgrammerDialog : public QDialog
3233

3334
private:
3435
Ui::SettingsProgrammerDialog *ui;
36+
37+
private slots:
38+
void fillPortsInfo();
3539
};
3640

3741
#endif // SETTINGS_PROGRAMMER_DIALOG_H

qt/settings_programmer_dialog.ui

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,33 @@
1616
<layout class="QGridLayout" name="gridLayout_2">
1717
<item row="0" column="0">
1818
<layout class="QGridLayout" name="gridLayout">
19-
<item row="0" column="0">
20-
<layout class="QHBoxLayout" name="horizontalLayout">
21-
<item>
22-
<widget class="QLabel" name="usbDevNameLabel">
23-
<property name="sizePolicy">
24-
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
25-
<horstretch>0</horstretch>
26-
<verstretch>0</verstretch>
27-
</sizepolicy>
28-
</property>
29-
<property name="text">
30-
<string>USB device name</string>
31-
</property>
32-
</widget>
33-
</item>
34-
<item>
35-
<widget class="QLineEdit" name="usbDevNameLineEdit">
36-
<property name="sizePolicy">
37-
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
38-
<horstretch>0</horstretch>
39-
<verstretch>0</verstretch>
40-
</sizepolicy>
41-
</property>
42-
<property name="minimumSize">
43-
<size>
44-
<width>100</width>
45-
<height>0</height>
46-
</size>
47-
</property>
48-
</widget>
49-
</item>
50-
</layout>
51-
</item>
5219
<item row="3" column="0">
5320
<widget class="QCheckBox" name="enableHwEccCheckBox">
5421
<property name="text">
5522
<string>Enable HW ECC</string>
5623
</property>
5724
</widget>
5825
</item>
26+
<item row="1" column="0">
27+
<widget class="QCheckBox" name="skipBBCheckBox">
28+
<property name="text">
29+
<string>Skip bad blocks</string>
30+
</property>
31+
<property name="checked">
32+
<bool>true</bool>
33+
</property>
34+
</widget>
35+
</item>
36+
<item row="2" column="0">
37+
<widget class="QCheckBox" name="incSpareCheckBox">
38+
<property name="text">
39+
<string>Include spare area</string>
40+
</property>
41+
<property name="checked">
42+
<bool>false</bool>
43+
</property>
44+
</widget>
45+
</item>
5946
<item row="5" column="0">
6047
<spacer name="verticalSpacer">
6148
<property name="orientation">
@@ -69,16 +56,6 @@
6956
</property>
7057
</spacer>
7158
</item>
72-
<item row="1" column="0">
73-
<widget class="QCheckBox" name="skipBBCheckBox">
74-
<property name="text">
75-
<string>Skip bad blocks</string>
76-
</property>
77-
<property name="checked">
78-
<bool>true</bool>
79-
</property>
80-
</widget>
81-
</item>
8259
<item row="6" column="0">
8360
<widget class="QDialogButtonBox" name="buttonBox">
8461
<property name="orientation">
@@ -89,27 +66,58 @@
8966
</property>
9067
</widget>
9168
</item>
92-
<item row="2" column="0">
93-
<widget class="QCheckBox" name="incSpareCheckBox">
94-
<property name="text">
95-
<string>Include spare area</string>
96-
</property>
97-
<property name="checked">
98-
<bool>false</bool>
99-
</property>
100-
</widget>
101-
</item>
10269
<item row="4" column="0">
10370
<widget class="QCheckBox" name="enableAlertCheckBox">
10471
<property name="text">
10572
<string>Alert after completion</string>
10673
</property>
10774
</widget>
10875
</item>
76+
<item row="0" column="0">
77+
<layout class="QHBoxLayout" name="horizontalLayout">
78+
<item>
79+
<widget class="QLabel" name="usbDevNameLabel">
80+
<property name="sizePolicy">
81+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
82+
<horstretch>0</horstretch>
83+
<verstretch>0</verstretch>
84+
</sizepolicy>
85+
</property>
86+
<property name="text">
87+
<string>USB device name</string>
88+
</property>
89+
</widget>
90+
</item>
91+
<item>
92+
<widget class="ClickComboBox" name="portInfoListBox" native="true">
93+
<property name="sizePolicy">
94+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
95+
<horstretch>0</horstretch>
96+
<verstretch>0</verstretch>
97+
</sizepolicy>
98+
</property>
99+
<property name="minimumSize">
100+
<size>
101+
<width>100</width>
102+
<height>22</height>
103+
</size>
104+
</property>
105+
</widget>
106+
</item>
107+
</layout>
108+
</item>
109109
</layout>
110110
</item>
111111
</layout>
112112
</widget>
113+
<customwidgets>
114+
<customwidget>
115+
<class>ClickComboBox</class>
116+
<extends>QWidget</extends>
117+
<header>clickcombobox.h</header>
118+
<container>1</container>
119+
</customwidget>
120+
</customwidgets>
113121
<resources/>
114122
<connections>
115123
<connection>

0 commit comments

Comments
 (0)