From 9767def438c4265319c3eef99e0531ee5164054e Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Mon, 17 Mar 2014 10:52:24 +0100 Subject: Rename misleading class name The API is: ListView { model: wifiManager.networks } currently if user calls print(wifiManager.networks) it will print: QWifiNetworkList The docs of ListView states that model property expects a subclass of QAbstractListModel. QWifiNetworkList sounds like a subclass of QList which is misleading. This patch renames the class to QWifiNetworkListModel. This does not change the public API (doesn't brake compatibility in any way), just improves the documentation of library. Task-number: QTEE-445 Change-Id: I71f07cb22617f3a7f41a0403d1c63c4357310325 Reviewed-by: Andy Nichols --- src/imports/wifi/pluginmain.cpp | 2 +- src/imports/wifi/qwifimanager.h | 8 +-- src/imports/wifi/qwifinetworklist.cpp | 112 ----------------------------- src/imports/wifi/qwifinetworklist.h | 51 ------------- src/imports/wifi/qwifinetworklistmodel.cpp | 112 +++++++++++++++++++++++++++++ src/imports/wifi/qwifinetworklistmodel.h | 51 +++++++++++++ src/imports/wifi/wifi.pro | 4 +- 7 files changed, 170 insertions(+), 170 deletions(-) delete mode 100644 src/imports/wifi/qwifinetworklist.cpp delete mode 100644 src/imports/wifi/qwifinetworklist.h create mode 100644 src/imports/wifi/qwifinetworklistmodel.cpp create mode 100644 src/imports/wifi/qwifinetworklistmodel.h (limited to 'src/imports') diff --git a/src/imports/wifi/pluginmain.cpp b/src/imports/wifi/pluginmain.cpp index 3c560f9..97f16f3 100644 --- a/src/imports/wifi/pluginmain.cpp +++ b/src/imports/wifi/pluginmain.cpp @@ -68,7 +68,7 @@ public: Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.wifi")); qmlRegisterType(uri, 0, 1, "WifiManager"); - qmlRegisterType(); + qmlRegisterType(); qmlRegisterSingletonType(uri, 0, 1, "Interface", global_object_wifi); } }; diff --git a/src/imports/wifi/qwifimanager.h b/src/imports/wifi/qwifimanager.h index 432f411..4b76368 100644 --- a/src/imports/wifi/qwifimanager.h +++ b/src/imports/wifi/qwifimanager.h @@ -25,7 +25,7 @@ #include -#include "qwifinetworklist.h" +#include "qwifinetworklistmodel.h" class QWifiManagerEventThread; @@ -37,7 +37,7 @@ class QWifiManager : public QObject Q_PROPERTY(bool backendReady READ isbackendReady NOTIFY backendReadyChanged) Q_PROPERTY(bool scanning READ scanning WRITE setScanning NOTIFY scanningChanged) Q_PROPERTY(QString connectedSSID READ connectedSSID NOTIFY connectedSSIDChanged) - Q_PROPERTY(QWifiNetworkList *networks READ networks CONSTANT) + Q_PROPERTY(QWifiNetworkListModel *networks READ networks CONSTANT) public: enum NetworkState { @@ -50,7 +50,7 @@ public: QWifiManager(); ~QWifiManager(); - QWifiNetworkList *networks() { return &m_networks; } + QWifiNetworkListModel *networks() { return &m_networks; } QString connectedSSID() const { return m_connectedSSID; } bool scanning() const { return m_scanning; } void setScanning(bool scanning); @@ -87,7 +87,7 @@ private: friend class QWifiManagerEventThread; QString m_connectedSSID; - QWifiNetworkList m_networks; + QWifiNetworkListModel m_networks; QWifiManagerEventThread *m_eventThread; int m_scanTimer; diff --git a/src/imports/wifi/qwifinetworklist.cpp b/src/imports/wifi/qwifinetworklist.cpp deleted file mode 100644 index 0bb9ead..0000000 --- a/src/imports/wifi/qwifinetworklist.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://qt.digia.com/ -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://qt.digia.com/ -** -****************************************************************************/ -#include "qwifinetworklist.h" - -#include - -const int ID_NETWORK = (Qt::ItemDataRole) (Qt::UserRole + 1); - -QWifiNetworkList::QWifiNetworkList(QWifiManager *manager) - : m_manager(manager) -{ -} - -QHash QWifiNetworkList::roleNames() const -{ - QHash names; - names.insert(ID_NETWORK, "network"); - return names; -} - -QVariant QWifiNetworkList::data(const QModelIndex &index, int role) const -{ - QWifiNetwork *n = m_networks.at(index.row()); - switch (role) { - case ID_NETWORK: return QVariant::fromValue((QObject *) n); - } - - qWarning("QWifiNetworkList::data(), undefined role: %d\n", role); - - return QVariant(); -} - -QWifiNetwork *QWifiNetworkList::networkForSSID(const QByteArray &ssid, int *pos) -{ - for (int i=0; issid() == ssid) { - if (pos) - *pos = i; - return m_networks.at(i); - } - } - return 0; -} - -void QWifiNetworkList::parseScanResults(const QByteArray &results) -{ - QList lines = results.split('\n'); - - QSet sensibleNetworks; - for (int i=1; i info = lines.at(i).split('\t'); - if (info.size() < 5 || info.at(4).isEmpty() || info.at(0).isEmpty()) - continue; - int pos = 0; - if (!sensibleNetworks.contains(info.at(4))) - sensibleNetworks.insert(info.at(4)); - QWifiNetwork *existingNetwork = networkForSSID(info.at(4), &pos); - if (!existingNetwork) { - QWifiNetwork *network = new QWifiNetwork(); - network->setBssid(info.at(0)); - network->setFlags(info.at(3)); - // signal strength is in dBm - network->setSignalStrength(info.at(2).toInt()); - network->setSsid(info.at(4)); - beginInsertRows(QModelIndex(), m_networks.size(), m_networks.size()); - m_networks << network; - endInsertRows(); - } else { - // ssids are the same, compare bssids.. - if (existingNetwork->bssid() == info.at(0)) { - // same access point, simply update the signal strength - existingNetwork->setSignalStrength(info.at(2).toInt()); - dataChanged(createIndex(pos, 0), createIndex(pos, 0)); - } else if (existingNetwork->signalStrength() < info.at(2).toInt()) { - // replace with a stronger access point within the same network - m_networks.at(pos)->setBssid(info.at(0)); - m_networks.at(pos)->setFlags(info.at(3)); - m_networks.at(pos)->setSignalStrength(info.at(2).toInt()); - m_networks.at(pos)->setSsid(info.at(4)); - dataChanged(createIndex(pos, 0), createIndex(pos, 0)); - } - } - } - // remove networks that have gone out of range - for (int i = 0; i < m_networks.size(); ++i) { - if (!sensibleNetworks.contains(m_networks.at(i)->ssid())) { - beginRemoveRows(QModelIndex(), i, i); - delete m_networks.takeAt(i); - endRemoveRows(); - } else { - ++i; - } - } -} - - diff --git a/src/imports/wifi/qwifinetworklist.h b/src/imports/wifi/qwifinetworklist.h deleted file mode 100644 index 84e78fc..0000000 --- a/src/imports/wifi/qwifinetworklist.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://qt.digia.com/ -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://qt.digia.com/ -** -****************************************************************************/ -#ifndef QWIFINETWORKLIST_H -#define QWIFINETWORKLIST_H - -#include -#include - -#include "qwifinetwork.h" - -class QWifiManager; - -class QWifiNetworkList : public QAbstractListModel -{ - Q_OBJECT - -public: - - QWifiNetworkList(QWifiManager *manager); - - void parseScanResults(const QByteArray &data); - - QWifiNetwork *networkForSSID(const QByteArray &ssid, int *pos); - - int rowCount(const QModelIndex &) const { return m_networks.size(); } - QVariant data(const QModelIndex &index, int role) const; - - QHash roleNames() const; - -private: - QWifiManager *m_manager; - QList m_networks; -}; - -#endif // QWIFINETWORKLIST_H diff --git a/src/imports/wifi/qwifinetworklistmodel.cpp b/src/imports/wifi/qwifinetworklistmodel.cpp new file mode 100644 index 0000000..bd1d37d --- /dev/null +++ b/src/imports/wifi/qwifinetworklistmodel.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use the contact form at +** http://qt.digia.com/ +** +** This file is part of Qt Enterprise Embedded. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** the contact form at http://qt.digia.com/ +** +****************************************************************************/ +#include "qwifinetworklistmodel.h" + +#include + +const int ID_NETWORK = (Qt::ItemDataRole) (Qt::UserRole + 1); + +QWifiNetworkListModel::QWifiNetworkListModel(QWifiManager *manager) + : m_manager(manager) +{ +} + +QHash QWifiNetworkListModel::roleNames() const +{ + QHash names; + names.insert(ID_NETWORK, "network"); + return names; +} + +QVariant QWifiNetworkListModel::data(const QModelIndex &index, int role) const +{ + QWifiNetwork *n = m_networks.at(index.row()); + switch (role) { + case ID_NETWORK: return QVariant::fromValue((QObject *) n); + } + + qWarning("QWifiNetworkListModel::data(), undefined role: %d\n", role); + + return QVariant(); +} + +QWifiNetwork *QWifiNetworkListModel::networkForSSID(const QByteArray &ssid, int *pos) +{ + for (int i=0; issid() == ssid) { + if (pos) + *pos = i; + return m_networks.at(i); + } + } + return 0; +} + +void QWifiNetworkListModel::parseScanResults(const QByteArray &results) +{ + QList lines = results.split('\n'); + + QSet sensibleNetworks; + for (int i=1; i info = lines.at(i).split('\t'); + if (info.size() < 5 || info.at(4).isEmpty() || info.at(0).isEmpty()) + continue; + int pos = 0; + if (!sensibleNetworks.contains(info.at(4))) + sensibleNetworks.insert(info.at(4)); + QWifiNetwork *existingNetwork = networkForSSID(info.at(4), &pos); + if (!existingNetwork) { + QWifiNetwork *network = new QWifiNetwork(); + network->setBssid(info.at(0)); + network->setFlags(info.at(3)); + // signal strength is in dBm + network->setSignalStrength(info.at(2).toInt()); + network->setSsid(info.at(4)); + beginInsertRows(QModelIndex(), m_networks.size(), m_networks.size()); + m_networks << network; + endInsertRows(); + } else { + // ssids are the same, compare bssids.. + if (existingNetwork->bssid() == info.at(0)) { + // same access point, simply update the signal strength + existingNetwork->setSignalStrength(info.at(2).toInt()); + dataChanged(createIndex(pos, 0), createIndex(pos, 0)); + } else if (existingNetwork->signalStrength() < info.at(2).toInt()) { + // replace with a stronger access point within the same network + m_networks.at(pos)->setBssid(info.at(0)); + m_networks.at(pos)->setFlags(info.at(3)); + m_networks.at(pos)->setSignalStrength(info.at(2).toInt()); + m_networks.at(pos)->setSsid(info.at(4)); + dataChanged(createIndex(pos, 0), createIndex(pos, 0)); + } + } + } + // remove networks that have gone out of range + for (int i = 0; i < m_networks.size(); ++i) { + if (!sensibleNetworks.contains(m_networks.at(i)->ssid())) { + beginRemoveRows(QModelIndex(), i, i); + delete m_networks.takeAt(i); + endRemoveRows(); + } else { + ++i; + } + } +} + + diff --git a/src/imports/wifi/qwifinetworklistmodel.h b/src/imports/wifi/qwifinetworklistmodel.h new file mode 100644 index 0000000..2827c8a --- /dev/null +++ b/src/imports/wifi/qwifinetworklistmodel.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use the contact form at +** http://qt.digia.com/ +** +** This file is part of Qt Enterprise Embedded. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** the contact form at http://qt.digia.com/ +** +****************************************************************************/ +#ifndef QWIFINETWORKLISTMODEL_H +#define QWIFINETWORKLISTMODEL_H + +#include +#include + +#include "qwifinetwork.h" + +class QWifiManager; + +class QWifiNetworkListModel : public QAbstractListModel +{ + Q_OBJECT + +public: + + QWifiNetworkListModel(QWifiManager *manager); + + void parseScanResults(const QByteArray &data); + + QWifiNetwork *networkForSSID(const QByteArray &ssid, int *pos); + + int rowCount(const QModelIndex &) const { return m_networks.size(); } + QVariant data(const QModelIndex &index, int role) const; + + QHash roleNames() const; + +private: + QWifiManager *m_manager; + QList m_networks; +}; + +#endif // QWIFINETWORKLISTMODEL_H diff --git a/src/imports/wifi/wifi.pro b/src/imports/wifi/wifi.pro index 0231479..b920978 100644 --- a/src/imports/wifi/wifi.pro +++ b/src/imports/wifi/wifi.pro @@ -8,12 +8,12 @@ SOURCES += \ pluginmain.cpp \ qwifimanager.cpp \ qwifinetwork.cpp \ - qwifinetworklist.cpp + qwifinetworklistmodel.cpp HEADERS += \ qwifimanager.h \ qwifinetwork.h \ - qwifinetworklist.h + qwifinetworklistmodel.h LIBS += -lhardware_legacy -lcutils -- cgit v1.2.3