mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
15b2dbede4
Commit c69ca4df80
removed the roleNames
function, which is not needed according to the docs, as a default function
is provided. For unknown reasons this broke the QML combo box.
Reinstate the function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
53 lines
1.2 KiB
C++
53 lines
1.2 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[Qt::DisplayRole] = "display";
|
|
return roles;
|
|
}
|
|
|
|
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(const QString &address) const
|
|
{
|
|
for (int i = 0; i < m_addresses.count(); i++)
|
|
if (m_addresses.at(i).contains(address, Qt::CaseInsensitive))
|
|
return i;
|
|
return -1;
|
|
}
|