1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-30 08:24:11 +01:00

GCS ConnectionManager: Use some cleaner code coventions

This commit is contained in:
James Cotton 2012-09-08 15:45:08 -05:00
parent 19eaa77a15
commit 8e8cbd0b75
2 changed files with 19 additions and 20 deletions

View File

@ -91,7 +91,7 @@ void ConnectionManager::init()
*/
bool ConnectionManager::connectDevice()
{
devListItem connection_device = findDevice(m_availableDevList->itemData(m_availableDevList->currentIndex(),Qt::ToolTipRole).toString());
DevListItem connection_device = findDevice(m_availableDevList->itemData(m_availableDevList->currentIndex(),Qt::ToolTipRole).toString());
if (!connection_device.connection)
return false;
@ -217,9 +217,9 @@ void ConnectionManager::onConnectPressed()
/**
* Find a device by its displayed (visible on screen) name
*/
devListItem ConnectionManager::findDevice(const QString &devName)
DevListItem ConnectionManager::findDevice(const QString &devName)
{
foreach (devListItem d, m_devList)
foreach (DevListItem d, m_devList)
{
if (d.getConName() == devName)
return d;
@ -227,7 +227,7 @@ devListItem ConnectionManager::findDevice(const QString &devName)
qDebug() << "findDevice: cannot find " << devName << " in device list";
devListItem d;
DevListItem d;
d.connection = NULL;
return d;
}
@ -276,21 +276,16 @@ void ConnectionManager::updateConnectionList(IConnection *connection)
// available device list then remove them. If they are connected, then
// disconnect them.
for (QLinkedList<devListItem>::iterator iter = m_devList.begin(); iter != m_devList.end(); )
for (QLinkedList<DevListItem>::iterator iter = m_devList.begin(); iter != m_devList.end(); )
{
if (iter->connection == connection)
{
// See if device exists in the updated availability list
bool found = false;
foreach (IConnection::device dev, availableDev)
if (iter->device == dev) // TODO: Need some way of indicating a IOConnection::device matches a devListItem
found = true;
bool found = availableDev.contains(iter->device);
if (!found) {
// we are currently using the one we are about to erase
if (m_connectionDevice.connection && m_connectionDevice.connection == connection && m_connectionDevice.device == iter->device)
{ // we are currently using the one we are about to erase
disconnectDevice();
}
iter = m_devList.erase(iter);
} else
@ -307,7 +302,7 @@ void ConnectionManager::updateConnectionList(IConnection *connection)
foreach (IConnection::device dev, availableDev)
{
bool found = false;
foreach (devListItem devList, m_devList)
foreach (DevListItem devList, m_devList)
if (devList.device == dev)
found = true;
@ -326,7 +321,7 @@ void ConnectionManager::updateConnectionList(IConnection *connection)
*/
void ConnectionManager::registerDevice(IConnection *conn, IConnection::device device)
{
devListItem d;
DevListItem d;
d.connection = conn;
d.device = device;
m_devList.append(d);
@ -364,7 +359,7 @@ void ConnectionManager::devChanged(IConnection *connection)
void ConnectionManager::updateConnectionDropdown()
{
//add all the list again to the combobox
foreach (devListItem d, m_devList)
foreach (DevListItem d, m_devList)
{
m_availableDevList->addItem(d.getConName());
m_availableDevList->setItemData(m_availableDevList->count()-1, d.getConName(), Qt::ToolTipRole);

View File

@ -56,7 +56,7 @@ namespace Internal {
} // namespace Internal
class devListItem
class DevListItem
{
public:
IConnection *connection;
@ -67,6 +67,10 @@ public:
return "";
return connection->shortName() + ": " + device.displayName;
}
bool operator==(const DevListItem &rhs) {
return connection == rhs.connection && device == rhs.device;
}
};
@ -81,7 +85,7 @@ public:
void init();
QIODevice* getCurrentConnection() { return m_ioDev; }
devListItem getCurrentDevice() { return m_connectionDevice;}
DevListItem getCurrentDevice() { return m_connectionDevice;}
bool disconnectDevice();
void suspendPolling();
void resumePolling();
@ -90,7 +94,7 @@ protected:
void updateConnectionList(IConnection *connection);
void registerDevice(IConnection *conn, IConnection::device device);
void updateConnectionDropdown();
devListItem findDevice(const QString &devName);
DevListItem findDevice(const QString &devName);
signals:
void deviceConnected(QIODevice *dev);
@ -108,11 +112,11 @@ private slots:
protected:
QComboBox *m_availableDevList;
QPushButton *m_connectBtn;
QLinkedList<devListItem> m_devList;
QLinkedList<DevListItem> m_devList;
QList<IConnection*> m_connectionsList;
//currently connected connection plugin
devListItem m_connectionDevice;
DevListItem m_connectionDevice;
//currently connected QIODevice
QIODevice *m_ioDev;