From 7aacaf60da7e73b9c57012e1846f709acb4d0ac2 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 6 Oct 2017 07:51:30 -0700 Subject: Move ConnectionListModel into its own source file Signed-off-by: Dirk Hohndel --- core/connectionlistmodel.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 core/connectionlistmodel.cpp (limited to 'core/connectionlistmodel.cpp') diff --git a/core/connectionlistmodel.cpp b/core/connectionlistmodel.cpp new file mode 100644 index 000000000..3e1e0d71c --- /dev/null +++ b/core/connectionlistmodel.cpp @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "core/connectionlistmodel.h" + +ConnectionListModel::ConnectionListModel(QObject *parent) : + QAbstractListModel(parent) +{ +} + +QHash ConnectionListModel::roleNames() const +{ + QHash 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(); +} -- cgit v1.2.3-70-g09d2