mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
The complicated setup with the AddressRole is unnecessary. All we want to be able to do is get the index of a specific text in the list. In hindsight I am puzzled why I implemented this in such a complex fashion. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
44 lines
1,016 B
C++
44 lines
1,016 B
C++
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include "core/connectionlistmodel.h"
|
|
|
|
ConnectionListModel::ConnectionListModel(QObject *parent) :
|
|
QAbstractListModel(parent)
|
|
{
|
|
}
|
|
|
|
QVariant ConnectionListModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if (index.row() < 0 || index.row() >= m_addresses.count())
|
|
return QVariant();
|
|
if (role != Qt::DisplayRole)
|
|
return QVariant();
|
|
return m_addresses[index.row()];
|
|
}
|
|
|
|
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);
|
|
}
|