Index: sources/gui/qml/compounds/CheckListScrollView.qml =================================================================== diff -u -rcdf80193148db0831cf2c1067732ddc6f6dac5fb -r83ffaef436920eba534cde428e14d168ea931bea --- sources/gui/qml/compounds/CheckListScrollView.qml (.../CheckListScrollView.qml) (revision cdf80193148db0831cf2c1067732ddc6f6dac5fb) +++ sources/gui/qml/compounds/CheckListScrollView.qml (.../CheckListScrollView.qml) (revision 83ffaef436920eba534cde428e14d168ea931bea) @@ -28,6 +28,8 @@ */ Item { id: _root + property var model: [] + ScrollBar { backColor: Colors.backgroundMain flickable: _listView @@ -36,7 +38,7 @@ } ListView { id: _listView - model: ["Step 1", "Step 2", "Step 3", "Step 4"] + model: _root.model clip: true spacing: 7 width: _root.width @@ -55,7 +57,7 @@ } color: Colors.textMain - text: qsTr("Test Description") + text: name elide: Text.ElideLeft font.pixelSize: 24 } @@ -76,8 +78,8 @@ } diameter: _delegate.height * 0.5 visible : true - done : true - failed : true + done : result < 2 + failed : result == 0 } } } Index: sources/gui/qml/main.qml =================================================================== diff -u -rcdf80193148db0831cf2c1067732ddc6f6dac5fb -r83ffaef436920eba534cde428e14d168ea931bea --- sources/gui/qml/main.qml (.../main.qml) (revision cdf80193148db0831cf2c1067732ddc6f6dac5fb) +++ sources/gui/qml/main.qml (.../main.qml) (revision 83ffaef436920eba534cde428e14d168ea931bea) @@ -134,6 +134,8 @@ VTreatmentRinseback { id: vTreatmentRinseback } VTreatmentRecirculate { id: vTreatmentRecirculate } VHDAccelerometer { id: vHDAccelerometer } + VHDPostSingleResult { id: vHDPostSingleResult } + VHDPostFinalResult { id: vHDPostFinalResult } // ---- DG VDGDrainPump { id: vDGDrainPump } VDGHeaters { id: vDGHeaters } @@ -145,6 +147,8 @@ VDGTemperatures { id: vDGTemperatures } VDGValvesStates { id: vDGValvesStates } VDGAccelerometer { id: vDGAccelerometer } + VDGPostSingleResult { id: vDGPostSingleResult } + VDGPostFinalResult { id: vDGPostFinalResult } // --- Pre-Treatment Progress Data VPreTreatmentAdjustmentInitTreatment { id: vPreTreatmentAdjustmentInitTreatment } Index: sources/gui/qml/pages/post/PostInProgress.qml =================================================================== diff -u -rcdf80193148db0831cf2c1067732ddc6f6dac5fb -r83ffaef436920eba534cde428e14d168ea931bea --- sources/gui/qml/pages/post/PostInProgress.qml (.../PostInProgress.qml) (revision cdf80193148db0831cf2c1067732ddc6f6dac5fb) +++ sources/gui/qml/pages/post/PostInProgress.qml (.../PostInProgress.qml) (revision 83ffaef436920eba534cde428e14d168ea931bea) @@ -66,6 +66,7 @@ } CheckListScrollView { id: _hdListView + model: vHDPostSingleResult width: _rectangle.width / 3 anchors { top: _hdTestsTitle.bottom @@ -85,6 +86,7 @@ } CheckListScrollView { id: _dgListView + model: vDGPostSingleResult width: _rectangle.width / 3 anchors { top: _dgTestsTitle.bottom Index: sources/view/dg/data/VDGPostSingleResultData.cpp =================================================================== diff -u -r4e708c6e93443b01ac26c71a466708916ede4abf -r83ffaef436920eba534cde428e14d168ea931bea --- sources/view/dg/data/VDGPostSingleResultData.cpp (.../VDGPostSingleResultData.cpp) (revision 4e708c6e93443b01ac26c71a466708916ede4abf) +++ sources/view/dg/data/VDGPostSingleResultData.cpp (.../VDGPostSingleResultData.cpp) (revision 83ffaef436920eba534cde428e14d168ea931bea) @@ -17,8 +17,167 @@ // Project #include "GuiController.h" -VIEW_DEF(VDGPostSingleResult, DGPostSingleResultData) +using namespace View; -void VDGPostSingleResult::onActionReceive(const DGPostSingleResultData &vData) { +VDGPostSingleResult::VDGPostSingleResult(QAbstractListModel *parent) : QAbstractListModel(parent) +{ + initConnections(); +} + +/*! + * \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; + + 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)); } + +/*! + * \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); + } +} Index: sources/view/dg/data/VDGPostSingleResultData.h =================================================================== diff -u -r4e708c6e93443b01ac26c71a466708916ede4abf -r83ffaef436920eba534cde428e14d168ea931bea --- sources/view/dg/data/VDGPostSingleResultData.h (.../VDGPostSingleResultData.h) (revision 4e708c6e93443b01ac26c71a466708916ede4abf) +++ sources/view/dg/data/VDGPostSingleResultData.h (.../VDGPostSingleResultData.h) (revision 83ffaef436920eba534cde428e14d168ea931bea) @@ -16,11 +16,13 @@ // Qt #include +#include // Project #include "main.h" // Doxygen : don't remove #include "VView.h" #include "MDGPostSingleResultData.h" +#include "MSettings.h" // namespace namespace View { @@ -32,12 +34,38 @@ * \sa Model::MDGPostSingleResultData * */ -class VDGPostSingleResult : public QObject { +class VDGPostSingleResult : public QAbstractListModel { Q_OBJECT - PROPERTY( quint32, result, 0) - PROPERTY( quint32, index, 0) + PROPERTY(quint32, result, 0) + PROPERTY(quint32, index, 0) - VIEW_DEC(VDGPostSingleResult, DGPostSingleResultData) + VIEW_DEC_SLOT(DGPostSingleResultData) + VIEW_DEC_SLOT(SettingsData) + +private: + struct PostTest { + QString name; + quint32 result = 2; + }; + + QList _tests; + +public: + explicit VDGPostSingleResult(QAbstractListModel *parent = nullptr); + + enum TestDataRole { + TestNameRole = Qt::UserRole + 1, + TestResultRole, + }; +protected: + int rowCount (const QModelIndex &parent = QModelIndex()) const override; + QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override; + QHash roleNames() const override; + bool setData(int vIndex, const QVariant &vValue, const TestDataRole &vRole); + void removeAllRows(); +private: + void initConnections(); + void addSelfTest(const PostTest &vTest); }; } Index: sources/view/hd/data/VHDPostSingleResultData.cpp =================================================================== diff -u -r4e708c6e93443b01ac26c71a466708916ede4abf -r83ffaef436920eba534cde428e14d168ea931bea --- sources/view/hd/data/VHDPostSingleResultData.cpp (.../VHDPostSingleResultData.cpp) (revision 4e708c6e93443b01ac26c71a466708916ede4abf) +++ sources/view/hd/data/VHDPostSingleResultData.cpp (.../VHDPostSingleResultData.cpp) (revision 83ffaef436920eba534cde428e14d168ea931bea) @@ -17,8 +17,168 @@ // Project #include "GuiController.h" -VIEW_DEF(VHDPostSingleResult, HDPostSingleResultData) +using namespace View; -void VHDPostSingleResult::onActionReceive(const HDPostSingleResultData &vData) { +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); + } +} Index: sources/view/hd/data/VHDPostSingleResultData.h =================================================================== diff -u -r4e708c6e93443b01ac26c71a466708916ede4abf -r83ffaef436920eba534cde428e14d168ea931bea --- sources/view/hd/data/VHDPostSingleResultData.h (.../VHDPostSingleResultData.h) (revision 4e708c6e93443b01ac26c71a466708916ede4abf) +++ sources/view/hd/data/VHDPostSingleResultData.h (.../VHDPostSingleResultData.h) (revision 83ffaef436920eba534cde428e14d168ea931bea) @@ -16,11 +16,13 @@ // Qt #include +#include // Project #include "main.h" // Doxygen : don't remove #include "VView.h" #include "MHDPostSingleResultData.h" +#include "MSettings.h" // namespace namespace View { @@ -32,12 +34,38 @@ * \sa Model::MHDPostSingleResultData * */ -class VHDPostSingleResult : public QObject { +class VHDPostSingleResult : public QAbstractListModel { Q_OBJECT - PROPERTY( quint32, result, 0) - PROPERTY( quint32, index, 0) + PROPERTY(quint32, result, 0) + PROPERTY(quint32, index, 0) - VIEW_DEC(VHDPostSingleResult, HDPostSingleResultData) + VIEW_DEC_SLOT(HDPostSingleResultData) + VIEW_DEC_SLOT(SettingsData) + +private: + struct PostTest { + QString name; + quint32 result = 2; + }; + + QList _tests; + +public: + explicit VHDPostSingleResult(QAbstractListModel *parent = nullptr); + + enum TestDataRole { + TestNameRole = Qt::UserRole + 1, + TestResultRole, + }; +protected: + int rowCount (const QModelIndex &parent = QModelIndex()) const override; + QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override; + QHash roleNames() const override; + bool setData(int vIndex, const QVariant &vValue, const TestDataRole &vRole); + void removeAllRows(); +private: + void initConnections(); + void addSelfTest(const PostTest &vTest); }; }