2017-10-06 14:51:30 +00:00
|
|
|
// 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];
|
|
|
|
}
|
|
|
|
|
2018-05-21 15:36:04 +00:00
|
|
|
int ConnectionListModel::rowCount(const QModelIndex&) const
|
2017-10-06 14:51:30 +00:00
|
|
|
{
|
|
|
|
return m_addresses.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionListModel::addAddress(const QString address)
|
|
|
|
{
|
2018-01-23 20:50:11 +00:00
|
|
|
if (!m_addresses.contains(address)) {
|
|
|
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
|
|
|
m_addresses.append(address);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
2017-10-06 14:51:30 +00:00
|
|
|
}
|
2017-10-11 17:31:45 +00:00
|
|
|
|
|
|
|
void ConnectionListModel::removeAllAddresses()
|
|
|
|
{
|
|
|
|
beginRemoveRows(QModelIndex(), 0, rowCount());
|
|
|
|
m_addresses.clear();
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
2018-08-08 12:54:10 +00:00
|
|
|
|
|
|
|
int ConnectionListModel::indexOf(QString address)
|
|
|
|
{
|
2018-09-23 05:53:43 +00:00
|
|
|
const QRegExp re(address, Qt::CaseInsensitive);
|
|
|
|
return m_addresses.indexOf(re);
|
2018-08-08 12:54:10 +00:00
|
|
|
}
|