subsurface/core/connectionlistmodel.cpp
Dirk Hohndel 0ae57cfe92 Mobile/remember DCs: try to match device names
We only store the address part of the connection name, so don't try to find an
exact match, try to find the sub-string.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-23 11:49:30 -07:00

58 lines
1.3 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&) const
{
return m_addresses.count();
}
void ConnectionListModel::addAddress(const QString address)
{
if (!m_addresses.contains(address)) {
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_addresses.append(address);
endInsertRows();
}
}
void ConnectionListModel::removeAllAddresses()
{
beginRemoveRows(QModelIndex(), 0, rowCount());
m_addresses.clear();
endRemoveRows();
}
int ConnectionListModel::indexOf(QString address)
{
const QRegExp re(address, Qt::CaseInsensitive);
return m_addresses.indexOf(re);
}