mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
8b8863b640
Preparation primarily for mobile. When we want to switch in one session from BT to cable connection and vise versa, we need a way to clear the model data containing the possible connections in use. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
// 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();
|
|
}
|
|
|
|
void ConnectionListModel::removeAllAddresses()
|
|
{
|
|
beginRemoveRows(QModelIndex(), 0, rowCount());
|
|
m_addresses.clear();
|
|
endRemoveRows();
|
|
}
|