/*! * * Copyright (c) 2021 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file VHDPostSingleResultData.cpp * \author (last) Peter Lucia * \date (last) 19-May-2021 * \author (original) Peter Lucia * \date (original) 19-May-2021 * */ #include "VHDPostSingleResultData.h" // Project #include "GuiController.h" using namespace View; VHDPostSingleResult::VHDPostSingleResult(QAbstractListModel *parent) : QAbstractListModel(parent) { initConnections(); } /*! * \brief VHDPostSingleResult::initConnections * Initializes the connections */ void VHDPostSingleResult::initConnections() { ACTION_VIEW_CONNECTION(HDPostSingleResultData); ACTION_VIEW_CONNECTION(SettingsData); } /*! * \brief VHDPostSingleResult::addSelfTest * Adds a self test * \param vTest - the post test to add */ void VHDPostSingleResult::addSelfTest(const PostTest &vTest) { LOG_DEBUG(QString("Adding HD power on self test %1").arg(vTest.name)); beginInsertRows(QModelIndex(), rowCount(), rowCount()); _tests << vTest; endInsertRows(); } /*! * \brief VNetworkModel::removeRows * Removes all rows from the model */ void VHDPostSingleResult::removeAllRows() { beginRemoveRows(QModelIndex(), 0, rowCount()); _tests.clear(); endRemoveRows(); } /*! * \brief VHDPostSingleResult::data * Returns the test properties at the specified index * \param index (QModelIndex) contains the row of data to lookup * \param role - (int) the property index to return. See TestDataRole * \return (QVariant) - the value for the specified test property */ QVariant VHDPostSingleResult::data(const QModelIndex & index, int role) const { if (index.row() < 0 || index.row() >= _tests.count()) return QVariant(); switch (role) { case TestNameRole: return _tests[index.row()].name; case TestResultRole: return _tests[index.row()].result; } return QVariant(); } /*! * \brief VHDPostSingleResult::setData * \param vIndex - the test number * \param vValue - the new value for the role * \param vRole - the role to update * \return true upon success, false otherwise */ bool VHDPostSingleResult::setData(int vIndex, const QVariant &vValue, const TestDataRole &vRole) { if (vIndex < 0 || vIndex >= rowCount()) return false; PostTest &test = _tests[vIndex]; if (vRole == TestNameRole) test.name = vValue.toString(); else if (vRole == TestResultRole) { bool ok = false; quint32 result = vValue.toInt(&ok); if (!ok) return false; test.result = result; } else return false; // FIXME: emit dataChanged... return true; } /*! * \brief VNetworkModel::rowCount * Gets the number of tests * \param parent - the parent QModelIndex * \return - the number of networks */ int VHDPostSingleResult::rowCount(const QModelIndex & parent) const { Q_UNUSED(parent); return _tests.count(); } /*! * \brief VNetworkModel::roleNames * Translates how to access specific properties of the data for QML from the TestDataRole enum * \return (QHash) - maps enums to property names */ QHash VHDPostSingleResult::roleNames() const { QHash roles; roles[TestNameRole] = "name"; roles[TestResultRole] = "result"; return roles; } /*! * \brief VHDPostSingleResult::onActionReceive * Called when the HD self test has a result * \param vData - contains the index of the test and its result */ void VHDPostSingleResult::onActionReceive(const HDPostSingleResultData &vData) { Q_UNUSED(vData) if (vData.mIndex >= (quint32)rowCount()) { LOG_DEBUG("The test index received from FW is greater than number of loaded UI power on self tests."); return; } if (!setData(vData.mIndex, QVariant(vData.mResult), TestResultRole)) LOG_DEBUG(QString("Could not set data for test index %1 with result %2").arg(vData.mIndex, vData.mResult)); } /*! * \brief VHDPostSingleResult::onActionReceive * Called when the settings data is read from disk on startup * \param vData - the settings data */ void VHDPostSingleResult::onActionReceive(const SettingsData &) { // POST Settings folder and filename (category): PowerOnSelfTests/PowerOnSelfTests QStringList tests; for (const auto &group : _Settings.groups()) { if (group == "HDPostSelfTests") { tests = _Settings.keys(group); } } for (const QString &test : tests) { PostTest posttest; posttest.name = test; addSelfTest(posttest); } }