/*! * * 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 VUIPostSingleResultData.cpp * \author (last) Peter Lucia * \date (last) 21-May-2021 * \author (original) Peter Lucia * \date (original) 21-May-2021 * */ #include "VUIPostSingleResultData.h" // Project #include "GuiController.h" using namespace View; VUIPostSingleResult::VUIPostSingleResult(QAbstractListModel *parent) : QAbstractListModel(parent) { initConnections(); } /*! * \brief VUIPost::initConnections * Initializes the connections */ void VUIPostSingleResult::initConnections() { ACTION_VIEW_CONNECTION(SettingsData); } /*! * \brief VUIPost::addSelfTest * Adds a self test * \param vTest - the post test to add */ void VUIPostSingleResult::addSelfTest(const PostTest &vTest) { LOG_DEBUG(QString("Adding UI 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 VUIPostSingleResult::removeAllRows() { beginRemoveRows(QModelIndex(), 0, rowCount()); _tests.clear(); endRemoveRows(); } /*! * \brief VUIPost::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 VUIPostSingleResult::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 VUIPost::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 VUIPostSingleResult::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 VUIPostSingleResult::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 VUIPostSingleResult::roleNames() const { QHash roles; roles[TestNameRole] = "name"; roles[TestResultRole] = "result"; return roles; } /*! * \brief VUIPost::onActionReceive * Called when the settings data is read from disk on startup * \param vData - the settings data */ void VUIPostSingleResult::onActionReceive(const SettingsData &) { // POST Settings folder and filename (category): PowerOnSelfTests/PowerOnSelfTests QStringList tests; for (const auto &group : _Settings.groups()) { if (group == "UIPostSelfTests") { tests = _Settings.keys(group); } } for (const QString &test : tests) { PostTest posttest; posttest.name = test; addSelfTest(posttest); } }