1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

Merged in filnet/librepilot/LP-430_add_description_to_serial_device_display_name (pull request #347)

LP-430 add description to serial devices display name
This commit is contained in:
Lalanne Laurent 2016-10-23 14:19:58 +00:00
commit e00c0fad63
4 changed files with 34 additions and 10 deletions

View File

@ -40,6 +40,30 @@
#include <QEventLoop>
namespace Core {
QString DevListItem::getConName() const
{
if (connection == NULL) {
return "";
}
return connection->shortName() + ": " + device.displayName;
}
QString DevListItem::getConDescription() const
{
if (connection == NULL) {
return "";
}
QString description = device.displayName;
if (!device.description.isEmpty()) {
description += " - " + device.description;
}
// truncate description if too long
if (description.length() > 50) {
description = description.left(50) + "...";
}
return description;
}
ConnectionManager::ConnectionManager(Internal::MainWindow *mainWindow) :
QWidget(mainWindow),
m_availableDevList(0),
@ -458,7 +482,7 @@ void ConnectionManager::updateConnectionDropdown()
// add all the list again to the combobox
foreach(DevListItem d, m_devList) {
m_availableDevList->addItem(d.getConName());
m_availableDevList->setItemData(m_availableDevList->count() - 1, d.getConName(), Qt::ToolTipRole);
m_availableDevList->setItemData(m_availableDevList->count() - 1, d.getConDescription(), Qt::ToolTipRole);
if (!m_ioDev && d.getConName().startsWith("USB")) {
if (m_mainWindow->generalSettings()->autoConnect() || m_mainWindow->generalSettings()->autoSelect()) {
m_availableDevList->setCurrentIndex(m_availableDevList->count() - 1);

View File

@ -49,20 +49,16 @@ namespace Internal {
class MainWindow;
} // namespace Internal
class DevListItem {
class CORE_EXPORT DevListItem {
public:
DevListItem(IConnection *c, IConnection::device d) :
connection(c), device(d) {}
DevListItem() : connection(NULL) {}
QString getConName()
{
if (connection == NULL) {
return "";
}
return connection->shortName() + ": " + device.displayName;
}
QString getConName() const;
QString getConDescription() const;
bool operator==(const DevListItem &rhs)
{

View File

@ -50,6 +50,7 @@ public:
struct device {
QString name;
QString displayName;
QString description;
bool operator==(device i)
{
return this->name == i.name;

View File

@ -139,11 +139,14 @@ QList <Core::IConnection::device> SerialConnection::availableDevices()
// sort the list by port number (nice idea from PT_Dreamer :))
qSort(ports.begin(), ports.end(), sortPorts);
foreach(QSerialPortInfo port, ports) {
device d;
d.displayName = port.portName();
d.name = port.portName();
d.displayName = port.portName();
d.description = port.description();
list.append(d);
}
}