Index: sources/view/dg/data/VDGPostSingleResultData.cpp =================================================================== diff -u -rc8263f48423cf7791f5ef7d46157b9278708d663 -r8f45330e0b1af61e029bece73c9f23669ada56c1 --- sources/view/dg/data/VDGPostSingleResultData.cpp (.../VDGPostSingleResultData.cpp) (revision c8263f48423cf7791f5ef7d46157b9278708d663) +++ sources/view/dg/data/VDGPostSingleResultData.cpp (.../VDGPostSingleResultData.cpp) (revision 8f45330e0b1af61e029bece73c9f23669ada56c1) @@ -19,168 +19,16 @@ using namespace View; -VDGPostSingleResult::VDGPostSingleResult(QAbstractListModel *parent) : QAbstractListModel(parent) -{ - initConnections(); -} +VIEW_DEF(VDGPostSingleResult, DGPostSingleResultData) /*! - * \brief VDGPostSingleResult::initConnections - * Initializes the connections - */ -void VDGPostSingleResult::initConnections() -{ - ACTION_VIEW_CONNECTION(DGPostSingleResultData); - ACTION_VIEW_CONNECTION(SettingsData); -} - -/*! - * \brief VDGPostSingleResult::addSelfTest - * Adds a self test - * \param vTest - the post test to add - */ -void VDGPostSingleResult::addSelfTest(const PostTest &vTest) -{ - LOG_DEBUG(QString("Adding DG 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 VDGPostSingleResult::removeAllRows() -{ - beginRemoveRows(QModelIndex(), 0, rowCount()); - _tests.clear(); - endRemoveRows(); -} - -/*! - * \brief VDGPostSingleResult::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 VDGPostSingleResult::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 VDGPostSingleResult::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 VDGPostSingleResult::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; - - emit dataChanged(sibling(vIndex, 0, QModelIndex()), - sibling(vIndex,0, QModelIndex()), - QVector() << vRole); - return true; -} - -/*! - * \brief VNetworkModel::rowCount - * Gets the number of tests - * \param parent - the parent QModelIndex - * \return - the number of networks - */ -int VDGPostSingleResult::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 VDGPostSingleResult::roleNames() const -{ - QHash roles; - roles[TestNameRole] = "name"; - roles[TestResultRole] = "result"; - return roles; -} - - -/*! * \brief VDGPostSingleResult::onActionReceive * Called when the DG self test has a result * \param vData - contains the index of the test and its result */ void VDGPostSingleResult::onActionReceive(const DGPostSingleResultData &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)); + LOG_EVENT(QString("DG power on self test with index %1 completed with result %3") + .arg(vData.mIndex) + .arg(vData.mResult)); } - -/*! - * \brief VDGPostSingleResult::onActionReceive - * Called when the settings data is read from disk on startup - * \param vData - the settings data - */ -void VDGPostSingleResult::onActionReceive(const SettingsData &) -{ - // POST Settings folder and filename (category): PowerOnSelfTests/PowerOnSelfTests - QStringList tests; - for (const auto &group : _Settings.groups()) - { - if (group == "DGPostSelfTests") - { - tests = _Settings.keys(group); - } - } - for (const QString &test : tests) - { - PostTest posttest; - posttest.name = test; - addSelfTest(posttest); - } -}