mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Move ConnectionListModel into its own source file
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
030c094854
commit
7aacaf60da
7 changed files with 69 additions and 57 deletions
|
@ -91,6 +91,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
|
||||||
gpslocation.cpp
|
gpslocation.cpp
|
||||||
cloudstorage.cpp
|
cloudstorage.cpp
|
||||||
downloadfromdcthread.cpp
|
downloadfromdcthread.cpp
|
||||||
|
connectionlistmodel.cpp
|
||||||
|
|
||||||
#Subsurface Qt have the Subsurface structs QObjectified for easy access via QML.
|
#Subsurface Qt have the Subsurface structs QObjectified for easy access via QML.
|
||||||
subsurface-qt/DiveObjectHelper.cpp
|
subsurface-qt/DiveObjectHelper.cpp
|
||||||
|
|
|
@ -10,47 +10,6 @@ extern QMap<QString, dc_descriptor_t *> descriptorLookup;
|
||||||
|
|
||||||
BTDiscovery *BTDiscovery::m_instance = NULL;
|
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)
|
static dc_descriptor_t *getDeviceType(QString btName)
|
||||||
// central function to convert a BT name to a Subsurface known vendor/model pair
|
// central function to convert a BT name to a Subsurface known vendor/model pair
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,22 +21,6 @@
|
||||||
void saveBtDeviceInfo(const char* devaddr, QBluetoothDeviceInfo deviceInfo);
|
void saveBtDeviceInfo(const char* devaddr, QBluetoothDeviceInfo deviceInfo);
|
||||||
QBluetoothDeviceInfo getBtDeviceInfo(const char* devaddr);
|
QBluetoothDeviceInfo getBtDeviceInfo(const char* devaddr);
|
||||||
|
|
||||||
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 {
|
class BTDiscovery : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
44
core/connectionlistmodel.cpp
Normal file
44
core/connectionlistmodel.cpp
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
|
|
||||||
|
#include "core/connectionlistmodel.h"
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
22
core/connectionlistmodel.h
Normal file
22
core/connectionlistmodel.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef CONNECTIONLISTMODEL_H
|
||||||
|
#define CONNECTIONLISTMODEL_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "dive.h"
|
#include "dive.h"
|
||||||
#include "libdivecomputer.h"
|
#include "libdivecomputer.h"
|
||||||
|
#include "connectionlistmodel.h"
|
||||||
#include "core/btdiscovery.h"
|
#include "core/btdiscovery.h"
|
||||||
|
|
||||||
/* Helper object for access of Device Data in QML */
|
/* Helper object for access of Device Data in QML */
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "qt-models/gpslistmodel.h"
|
#include "qt-models/gpslistmodel.h"
|
||||||
#include "mobile-widgets/qmlprofile.h"
|
#include "mobile-widgets/qmlprofile.h"
|
||||||
#include "core/downloadfromdcthread.h"
|
#include "core/downloadfromdcthread.h"
|
||||||
|
#include "core/connectionlistmodel.h"
|
||||||
#include "qt-models/diveimportedmodel.h"
|
#include "qt-models/diveimportedmodel.h"
|
||||||
#include "qt-models/messagehandlermodel.h"
|
#include "qt-models/messagehandlermodel.h"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue