From 4a6573db1ed6d3c003fc75f3c461a3e43c21ba57 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Thu, 20 Oct 2016 00:27:30 +0200 Subject: [PATCH] LP-430 show serial port description as tooltip in connection drop down --- .../plugins/coreplugin/connectionmanager.cpp | 26 ++++++++++++++++++- .../plugins/coreplugin/connectionmanager.h | 12 +++------ .../gcs/src/plugins/coreplugin/iconnection.h | 1 + .../plugins/serialconnection/serialplugin.cpp | 4 +-- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/ground/gcs/src/plugins/coreplugin/connectionmanager.cpp b/ground/gcs/src/plugins/coreplugin/connectionmanager.cpp index a225b97e6..1e1cc0410 100644 --- a/ground/gcs/src/plugins/coreplugin/connectionmanager.cpp +++ b/ground/gcs/src/plugins/coreplugin/connectionmanager.cpp @@ -40,6 +40,30 @@ #include 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); diff --git a/ground/gcs/src/plugins/coreplugin/connectionmanager.h b/ground/gcs/src/plugins/coreplugin/connectionmanager.h index b19cc7c5d..50a9257a4 100644 --- a/ground/gcs/src/plugins/coreplugin/connectionmanager.h +++ b/ground/gcs/src/plugins/coreplugin/connectionmanager.h @@ -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) { diff --git a/ground/gcs/src/plugins/coreplugin/iconnection.h b/ground/gcs/src/plugins/coreplugin/iconnection.h index a5ebbc17d..3a1de98f7 100644 --- a/ground/gcs/src/plugins/coreplugin/iconnection.h +++ b/ground/gcs/src/plugins/coreplugin/iconnection.h @@ -50,6 +50,7 @@ public: struct device { QString name; QString displayName; + QString description; bool operator==(device i) { return this->name == i.name; diff --git a/ground/gcs/src/plugins/serialconnection/serialplugin.cpp b/ground/gcs/src/plugins/serialconnection/serialplugin.cpp index 3bc11cc3f..964ec45e7 100644 --- a/ground/gcs/src/plugins/serialconnection/serialplugin.cpp +++ b/ground/gcs/src/plugins/serialconnection/serialplugin.cpp @@ -145,9 +145,7 @@ QList SerialConnection::availableDevices() d.name = port.portName(); d.displayName = port.portName(); - if (!port.description().isEmpty()) { - d.displayName += " - " + port.description(); - } + d.description = port.description(); list.append(d); }