1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-18 08:54:15 +01:00

LP-430 show serial port description as tooltip in connection drop down

This commit is contained in:
Philippe Renon 2016-10-20 00:27:30 +02:00
parent 365f0ca3ad
commit 4a6573db1e
4 changed files with 31 additions and 12 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

@ -145,9 +145,7 @@ QList <Core::IConnection::device> 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);
}