// Qt // Project #include "VNetworkModel.h" #include "WifiInterface.h" using namespace View; /*! * \brief VNetworkModel::initConnections * Makes the necessary connections. Called inside VIEW_DEF_CLASS */ void VNetworkModel::initConnections() { connect(this, SIGNAL(didScan()), &_WifiInterface, SLOT(doScan())); } /*! * \brief VNetworkModel::addNetwork * Adds a network to the network model * \param network (Network) - the network to add to the model */ void VNetworkModel::addNetwork(const Network &network) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); _networks << network; endInsertRows(); } /*! * \brief VNetworkModel::rowCount * Gets the number of networks * \param parent - (QModelIndex) the parent QModelIndex * \return (int) - the number of networks */ int VNetworkModel::rowCount(const QModelIndex & parent) const { Q_UNUSED(parent); return _networks.count(); } /*! * \brief VNetworkModel::data * Returns the network properties at the specified index * \param index (QModelIndex) contains the row of data to lookup * \param role - (int) the property index to return. See NetworkDataRole * \return (QVariant) - the value for the specified network property */ QVariant VNetworkModel::data(const QModelIndex & index, int role) const { if (index.row() < 0 || index.row() >= _networks.count()) return QVariant(); const Network &network = _networks[index.row()]; if (role == SSIDRole) return network.ssid(); else if (role == SecurityLevelRole) return network.security(); else if (role == StatusRole) return network.status(); return QVariant(); } /*! * \brief VNetworkModel::roleNames * Translates how to access specific properties of the data for QML from the NetworkDataRole enum * \return (QHash) - maps enums to property names */ QHash VNetworkModel::roleNames() const { QHash roles; roles[SSIDRole] = "ssid"; roles[SecurityLevelRole] = "security_level"; roles[StatusRole] = "status"; return roles; } /*! * \brief VNetworkModel::doScan * Handles when a user clicks the Scan button */ void VNetworkModel::doScan() { emit didScan(); }