refactoring for better separation of concerns
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#include "networksmodel.h"
|
||||
|
||||
NetworksModel::NetworksModel(QObject *parent)
|
||||
:
|
||||
QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
int NetworksModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return this->m_networks.count();
|
||||
}
|
||||
|
||||
QVariant NetworksModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (index.row() < 0 || index.row() >= this->m_networks.count())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
if (!index.isValid())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
const Network& network = this->m_networks.at(index.row());
|
||||
qDebug() << "role: " << role << " vs. " << NameRole;
|
||||
qDebug() << "network: " << network.name();
|
||||
if (role == NameRole)
|
||||
{
|
||||
return network.name();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void NetworksModel::scan()
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
QList<Network> networks = this->m_networkScanner.scanForNetworks();
|
||||
for (const Network& network: networks)
|
||||
{
|
||||
qDebug() << "Got network: " << network.name() << Qt::endl;
|
||||
}
|
||||
this->m_networks = networks;
|
||||
|
||||
qDebug() << "now have " << this->m_networks.size() << Qt::endl;
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> NetworksModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[NetworksModel::NetworkRoles::NameRole] = "name";
|
||||
return roles;
|
||||
}
|
||||
Reference in New Issue
Block a user