summaryrefslogtreecommitdiffstats
path: root/core/btdiscovery.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2017-07-16 21:45:21 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-07-16 21:53:44 -0700
commitc21845aa016786fb92a08c5d01029218ad1e10fb (patch)
tree5fdfe1a325c94f653157e2bd4217aab15925c7c2 /core/btdiscovery.cpp
parentdd1bdd3f8110a74306538ad5c952769f82adf6ba (diff)
downloadsubsurface-c21845aa016786fb92a08c5d01029218ad1e10fb.tar.gz
Add ConnectionListModel
We'll use that to do a better job of showing the connection used when talking to a dive computer. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/btdiscovery.cpp')
-rw-r--r--core/btdiscovery.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp
index c25e6cfda..a9f8c861a 100644
--- a/core/btdiscovery.cpp
+++ b/core/btdiscovery.cpp
@@ -9,6 +9,47 @@ extern QMap<QString, dc_descriptor_t *> descriptorLookup;
BTDiscovery *BTDiscovery::m_instance = NULL;
+ConnectionListModel::ConnectionListModel(QObject *parent) :
+ QAbstractListModel(parent)
+{
+}
+
+QHash <int, QByteArray> ConnectionListModel::roleNames() const
+{
+ QHash<int, QByteArray> roles;
+ roles[AddressRole] = "address";
+ return roles;
+}
+
+QVariant ConnectionListModel::data(const QModelIndex &index, int role) const
+{
+ if (index.row() < 0 || index.row() >= m_addresses.count())
+ return QVariant();
+ if (role != AddressRole)
+ return QVariant();
+ return m_addresses[index.row()];
+}
+
+QString ConnectionListModel::address(int idx) const
+{
+ if (idx < 0 || idx >> m_addresses.count())
+ return QString();
+ return m_addresses[idx];
+}
+
+int ConnectionListModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent)
+ return m_addresses.count();
+}
+
+void ConnectionListModel::addAddress(const QString address)
+{
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ m_addresses.append(address);
+ endInsertRows();
+}
+
static dc_descriptor_t *getDeviceType(QString btName)
// central function to convert a BT name to a Subsurface known vendor/model pair
{