mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
dd1bdd3f81
commit
c21845aa01
2 changed files with 58 additions and 0 deletions
|
@ -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
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QLoggingCategory>
|
||||
#include <QAbstractListModel>
|
||||
#if defined(BT_SUPPORT)
|
||||
#include <QBluetoothLocalDevice>
|
||||
#include <QBluetoothDeviceDiscoveryAgent>
|
||||
|
@ -17,6 +18,22 @@
|
|||
#include <QAndroidJniEnvironment>
|
||||
#endif
|
||||
|
||||
class ConnectionListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum CLMRole {
|
||||
AddressRole = Qt::UserRole + 1
|
||||
};
|
||||
ConnectionListModel(QObject *parent = 0);
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
QVariant data(const QModelIndex &index, int role = AddressRole) const;
|
||||
QString address(int idx) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
void addAddress(const QString address);
|
||||
private:
|
||||
QStringList m_addresses;
|
||||
};
|
||||
|
||||
class BTDiscovery : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue