Changeset c21845aa in subsurface


Ignore:
Timestamp:
Jul 16, 2017, 9:53:44 PM (3 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
a4f045a
Parents:
dd1bdd3
git-author:
Dirk Hohndel <dirk@…> (07/16/17 21:45:21)
git-committer:
Dirk Hohndel <dirk@…> (07/16/17 21:53:44)
Message:

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@…>

Location:
core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/btdiscovery.cpp

    r9397dbb rc21845aa  
    99
    1010BTDiscovery *BTDiscovery::m_instance = NULL;
     11
     12ConnectionListModel::ConnectionListModel(QObject *parent) :
     13        QAbstractListModel(parent)
     14{
     15}
     16
     17QHash <int, QByteArray> ConnectionListModel::roleNames() const
     18{
     19        QHash<int, QByteArray> roles;
     20        roles[AddressRole] = "address";
     21        return roles;
     22}
     23
     24QVariant ConnectionListModel::data(const QModelIndex &index, int role) const
     25{
     26        if (index.row() < 0 || index.row() >= m_addresses.count())
     27                return QVariant();
     28        if (role != AddressRole)
     29                return QVariant();
     30        return m_addresses[index.row()];
     31}
     32
     33QString ConnectionListModel::address(int idx) const
     34{
     35        if (idx < 0 || idx >> m_addresses.count())
     36                return QString();
     37        return m_addresses[idx];
     38}
     39
     40int ConnectionListModel::rowCount(const QModelIndex &parent) const
     41{
     42        Q_UNUSED(parent)
     43        return m_addresses.count();
     44}
     45
     46void ConnectionListModel::addAddress(const QString address)
     47{
     48        beginInsertRows(QModelIndex(), rowCount(), rowCount());
     49        m_addresses.append(address);
     50        endInsertRows();
     51}
    1152
    1253static dc_descriptor_t *getDeviceType(QString btName)
  • core/btdiscovery.h

    rbec5f3c rc21845aa  
    66#include <QString>
    77#include <QLoggingCategory>
     8#include <QAbstractListModel>
    89#if defined(BT_SUPPORT)
    910#include <QBluetoothLocalDevice>
     
    1718#include <QAndroidJniEnvironment>
    1819#endif
     20
     21class ConnectionListModel : public QAbstractListModel {
     22        Q_OBJECT
     23public:
     24        enum CLMRole {
     25                AddressRole = Qt::UserRole + 1
     26        };
     27        ConnectionListModel(QObject *parent = 0);
     28        QHash<int, QByteArray> roleNames() const;
     29        QVariant data(const QModelIndex &index, int role = AddressRole) const;
     30        QString address(int idx) const;
     31        int rowCount(const QModelIndex &parent = QModelIndex()) const;
     32        void addAddress(const QString address);
     33private:
     34        QStringList m_addresses;
     35};
    1936
    2037class BTDiscovery : public QObject {
Note: See TracChangeset for help on using the changeset viewer.