mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Move ConnectionListModel into its own source file
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
030c094854
commit
7aacaf60da
7 changed files with 69 additions and 57 deletions
44
core/connectionlistmodel.cpp
Normal file
44
core/connectionlistmodel.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// 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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue