Skip to content
Snippets Groups Projects
Commit 777b7759 authored by Samuel Jones's avatar Samuel Jones
Browse files

Re #26643 Add DecoderTest and update Item state on project save

parent e8707653
No related branches found
No related tags found
No related merge requests found
Showing with 148 additions and 47 deletions
...@@ -227,7 +227,7 @@ void Decoder::decodeRunsTable(QtRunsTableView *gui, ReductionJobs *redJobs, ...@@ -227,7 +227,7 @@ void Decoder::decodeRunsTable(QtRunsTableView *gui, ReductionJobs *redJobs,
const QMap<QString, QVariant> &map) { const QMap<QString, QVariant> &map) {
MantidQt::API::SignalBlocker signalBlockerView(gui); MantidQt::API::SignalBlocker signalBlockerView(gui);
bool projectSave = map[QString("projectSave")].toBool(); m_projectSave = map[QString("projectSave")].toBool();
auto runsTable = map[QString("runsTableModel")].toList(); auto runsTable = map[QString("runsTableModel")].toList();
// Clear // Clear
...@@ -255,9 +255,11 @@ void Decoder::decodeRunsTable(QtRunsTableView *gui, ReductionJobs *redJobs, ...@@ -255,9 +255,11 @@ void Decoder::decodeRunsTable(QtRunsTableView *gui, ReductionJobs *redJobs,
// Still need to do this for groups // Still need to do this for groups
updateRunsTableViewFromModel(gui, redJobs); updateRunsTableViewFromModel(gui, redJobs);
if (projectSave) { if (m_projectSave) {
// Apply styling and restore completed state for output range values best // Apply styling and restore completed state for output range values best
// way to achieve this is yet to be decided. // way to achieve this is yet to be decided.
presenter->notifyRowOutputsChanged();
presenter->notifyRowStateChanged();
} }
gui->m_ui.filterBox->setText(map[QString("filterBox")].toString()); gui->m_ui.filterBox->setText(map[QString("filterBox")].toString());
} }
...@@ -275,6 +277,10 @@ Decoder::decodeGroup(const QMap<QString, QVariant> &map) { ...@@ -275,6 +277,10 @@ Decoder::decodeGroup(const QMap<QString, QVariant> &map) {
auto rows = decodeRows(map["rows"].toList()); auto rows = decodeRows(map["rows"].toList());
MantidQt::CustomInterfaces::ISISReflectometry::Group group( MantidQt::CustomInterfaces::ISISReflectometry::Group group(
map[QString("name")].toString().toStdString(), rows); map[QString("name")].toString().toStdString(), rows);
if (m_projectSave) {
auto itemState = map[QString("itemState")].toInt();
group.setState(State(itemState));
}
group.m_postprocessedWorkspaceName = group.m_postprocessedWorkspaceName =
map[QString("postprocessedWorkspaceName")].toString().toStdString(); map[QString("postprocessedWorkspaceName")].toString().toStdString();
return group; return group;
...@@ -317,21 +323,30 @@ Decoder::decodeRow(const QMap<QString, QVariant> &map) { ...@@ -317,21 +323,30 @@ Decoder::decodeRow(const QMap<QString, QVariant> &map) {
if (scaleFactorPresent) { if (scaleFactorPresent) {
scaleFactor = map[QString("scaleFactor")].toDouble(); scaleFactor = map[QString("scaleFactor")].toDouble();
} }
if (scaleFactorPresent) { if (scaleFactorPresent) {
return MantidQt::CustomInterfaces::ISISReflectometry::Row( auto row = MantidQt::CustomInterfaces::ISISReflectometry::Row(
number, map[QString("theta")].toDouble(), number, map[QString("theta")].toDouble(),
decodeTransmissionRunPair(map[QString("transRunNums")].toMap()), decodeTransmissionRunPair(map[QString("transRunNums")].toMap()),
decodeRangeInQ(map[QString("qRange")].toMap()), scaleFactor, decodeRangeInQ(map[QString("qRange")].toMap()), scaleFactor,
decodeReductionOptions(map[QString("reductionOptions")].toMap()), decodeReductionOptions(map[QString("reductionOptions")].toMap()),
decodeReductionWorkspace(map[QString("reductionWorkspaces")].toMap())); decodeReductionWorkspace(map[QString("reductionWorkspaces")].toMap()));
if (m_projectSave) {
auto itemState = map[QString("itemState")].toInt();
row.setState(State(itemState));
}
return row;
} else { } else {
return MantidQt::CustomInterfaces::ISISReflectometry::Row( auto row = MantidQt::CustomInterfaces::ISISReflectometry::Row(
number, map[QString("theta")].toDouble(), number, map[QString("theta")].toDouble(),
decodeTransmissionRunPair(map[QString("transRunNums")].toMap()), decodeTransmissionRunPair(map[QString("transRunNums")].toMap()),
decodeRangeInQ(map[QString("qRange")].toMap()), boost::none, decodeRangeInQ(map[QString("qRange")].toMap()), boost::none,
decodeReductionOptions(map[QString("reductionOptions")].toMap()), decodeReductionOptions(map[QString("reductionOptions")].toMap()),
decodeReductionWorkspace(map[QString("reductionWorkspaces")].toMap())); decodeReductionWorkspace(map[QString("reductionWorkspaces")].toMap()));
if (m_projectSave) {
auto itemState = map[QString("itemState")].toInt();
row.setState(State(itemState));
}
return row;
} }
} }
......
...@@ -79,6 +79,7 @@ private: ...@@ -79,6 +79,7 @@ private:
void decodeEvent(const QtEventView *gui, const QMap<QString, QVariant> &map); void decodeEvent(const QtEventView *gui, const QMap<QString, QVariant> &map);
void updateRunsTableViewFromModel(QtRunsTableView *view, void updateRunsTableViewFromModel(QtRunsTableView *view,
const ReductionJobs *model); const ReductionJobs *model);
bool m_projectSave = false;
friend class CoderCommonTester; friend class CoderCommonTester;
}; };
......
...@@ -116,6 +116,7 @@ QMap<QString, QVariant> Encoder::encodeGroup( ...@@ -116,6 +116,7 @@ QMap<QString, QVariant> Encoder::encodeGroup(
const MantidQt::CustomInterfaces::ISISReflectometry::Group &group) { const MantidQt::CustomInterfaces::ISISReflectometry::Group &group) {
QMap<QString, QVariant> map; QMap<QString, QVariant> map;
map.insert(QString("name"), QVariant(QString::fromStdString(group.m_name))); map.insert(QString("name"), QVariant(QString::fromStdString(group.m_name)));
map.insert(QString("itemState"), QVariant(static_cast<int>(group.state())));
map.insert( map.insert(
QString("postprocessedWorkspaceName"), QString("postprocessedWorkspaceName"),
QVariant(QString::fromStdString(group.m_postprocessedWorkspaceName))); QVariant(QString::fromStdString(group.m_postprocessedWorkspaceName)));
...@@ -204,6 +205,7 @@ Encoder::encodeReductionOptions(const ReductionOptionsMap &rom) { ...@@ -204,6 +205,7 @@ Encoder::encodeReductionOptions(const ReductionOptionsMap &rom) {
QMap<QString, QVariant> Encoder::encodeRow( QMap<QString, QVariant> Encoder::encodeRow(
const MantidQt::CustomInterfaces::ISISReflectometry::Row &row) { const MantidQt::CustomInterfaces::ISISReflectometry::Row &row) {
QMap<QString, QVariant> map; QMap<QString, QVariant> map;
map.insert(QString("itemState"), QVariant(static_cast<int>(row.state())));
QList<QVariant> runNumbers; QList<QVariant> runNumbers;
for (const auto &runNumber : row.m_runNumbers) { for (const auto &runNumber : row.m_runNumbers) {
runNumbers.append(QVariant(QString::fromStdString(runNumber))); runNumbers.append(QVariant(QString::fromStdString(runNumber)));
......
...@@ -14,6 +14,8 @@ Item::Item() : m_itemState(), m_skipped(false) {} ...@@ -14,6 +14,8 @@ Item::Item() : m_itemState(), m_skipped(false) {}
State Item::state() const { return m_itemState.state(); } State Item::state() const { return m_itemState.state(); }
void Item::setState(State state) { m_itemState = ItemState(state); }
std::string Item::message() const { return m_itemState.message(); } std::string Item::message() const { return m_itemState.message(); }
void Item::resetState(bool resetChildren) { void Item::resetState(bool resetChildren) {
......
...@@ -29,6 +29,7 @@ public: ...@@ -29,6 +29,7 @@ public:
virtual bool isGroup() const = 0; virtual bool isGroup() const = 0;
State state() const; State state() const;
void setState(State state);
std::string message() const; std::string message() const;
virtual bool requiresProcessing(bool reprocessFailed) const; virtual bool requiresProcessing(bool reprocessFailed) const;
......
...@@ -14,6 +14,9 @@ ItemState::ItemState() ...@@ -14,6 +14,9 @@ ItemState::ItemState()
: m_state(State::ITEM_NOT_STARTED), m_message(boost::none), : m_state(State::ITEM_NOT_STARTED), m_message(boost::none),
m_progress(0.0) {} m_progress(0.0) {}
ItemState::ItemState(State state)
: m_state(state), m_message(boost::none), m_progress(0.0) {}
State ItemState::state() const { return m_state; } State ItemState::state() const { return m_state; }
std::string ItemState::message() const { std::string ItemState::message() const {
......
...@@ -16,12 +16,12 @@ namespace CustomInterfaces { ...@@ -16,12 +16,12 @@ namespace CustomInterfaces {
namespace ISISReflectometry { namespace ISISReflectometry {
enum class State { enum class State {
ITEM_NOT_STARTED, ITEM_NOT_STARTED = 0,
ITEM_STARTING, ITEM_STARTING = 1,
ITEM_RUNNING, ITEM_RUNNING = 2,
ITEM_COMPLETE, ITEM_COMPLETE = 3,
ITEM_ERROR, ITEM_ERROR = 4,
ITEM_WARNING ITEM_WARNING = 5
}; };
/** @class ItemState /** @class ItemState
...@@ -32,6 +32,7 @@ enum class State { ...@@ -32,6 +32,7 @@ enum class State {
class MANTIDQT_ISISREFLECTOMETRY_DLL ItemState { class MANTIDQT_ISISREFLECTOMETRY_DLL ItemState {
public: public:
ItemState(); ItemState();
ItemState(State state);
State state() const; State state() const;
std::string message() const; std::string message() const;
......
...@@ -32,6 +32,17 @@ namespace CustomInterfaces { ...@@ -32,6 +32,17 @@ namespace CustomInterfaces {
namespace ISISReflectometry { namespace ISISReflectometry {
class CoderCommonTester { class CoderCommonTester {
public: public:
void testMainWindowView(const QtMainWindowView &mwv,
const QMap<QString, QVariant> &map) {
auto list = map[QString("batches")].toList();
for (auto batchIndex = 0u; batchIndex < mwv.m_batchViews.size();
++batchIndex) {
testBatch(mwv.m_batchViews[batchIndex], mwv, list[batchIndex].toMap());
}
TS_ASSERT_EQUALS(map[QString("tag")].toString().toStdString(),
"ISIS Reflectometry")
}
void testBatch(const QtBatchView *gui, const QtMainWindowView &mwv, void testBatch(const QtBatchView *gui, const QtMainWindowView &mwv,
const QMap<QString, QVariant> &map) { const QMap<QString, QVariant> &map) {
Decoder batchFinder; Decoder batchFinder;
......
...@@ -21,41 +21,106 @@ ...@@ -21,41 +21,106 @@
#include <QVariant> #include <QVariant>
namespace { namespace {
const static QString JSON_STRING{ const static QString MAINWINDOW_JSON_STRING {
"{\"eventView\":{\"customButton\":false,\"customEdit\":\"\", " "{\"batches\": [{\"saveView\": {\"commaRadioButton\": true, "
"\"disabledSlicingButton\":false,\"logValueButton\":false,\"logValueEdit\":" "\"spaceRadioButton\": false, \"regexCheckBox\": false, \"savePathEdit\": "
"\"\",\"logValueTypeEdit\":\"\",\"uniformButton\":true,\"uniformEdit\":3," "\"\", \"saveReductionResultsCheckBox\": false, \"titleCheckBox\": false, "
"\"uniformEvenButton\":false,\"uniformEvenEdit\":2},\"experimentView\":{" "\"filterEdit\": \"\", \"tabRadioButton\": false, \"prefixEdit\": \"\", "
"\"analysisModeComboBox\":1,\"debugCheckbox\":true,\"endOverlapEdit\":13," "\"qResolutionCheckBox\": false, \"fileFormatComboBox\": 0}, \"runsView\": "
"\"floodCorComboBox\":1,\"floodWorkspaceWsSelector\":0," "{\"comboSearchInstrument\": 0, \"runsTable\": {\"projectSave\": true, "
"\"includePartialBinsCheckBox\":true,\"perAngleDefaults\":{\"columnsNum\":" "\"filterBox\": \"\", \"runsTableModel\": [{\"rows\": "
"9,\"rows\":[[\"123\",\"123\",\"213\",\"123\",\"123\",\"123\",\"123\"," "[{\"reductionWorkspaces\": {\"inputRunNumbers\": [\"13460\"], \"iVsQ\": "
"\"123\",\"123\"]],\"rowsNum\":1},\"polCorrCheckBox\":false," "\"\", \"transPair\": {\"firstTransRuns\": [], \"secondTransRuns\": []}, "
"\"reductionTypeComboBox\":2,\"startOverlapEdit\":12,\"stitchEdit\":\"\"," "\"iVsLambda\": \"\", \"iVsQBinned\": \"\"}, \"transRunNums\": "
"\"summationTypeComboBox\":1,\"transScaleRHSCheckBox\":true," "{\"firstTransRuns\": [], \"secondTransRuns\": []}, \"scaleFactorPresent\": "
"\"transStitchParamsEdit\":\"1\"},\"instrumentView\":{\"I0MonitorIndex\":3," "false, \"qRangeOutput\": {\"maxPresent\": false, \"stepPresent\": false, "
"\"correctDetectorsCheckBox\":false,\"detectorCorrectionTypeComboBox\":1," "\"minPresent\": false}, \"reductionOptions\": {}, \"theta\": 0.5, "
"\"intMonCheckBox\":false,\"lamMaxEdit\":18,\"lamMinEdit\":2.5," "\"runNumbers\": [\"13460\"], \"qRange\": {\"maxPresent\": false, "
"\"monBgMaxEdit\":20,\"monBgMinEdit\":19,\"monIntMaxEdit\":11," "\"stepPresent\": false, \"minPresent\": false}}], \"name\": \"123\", "
"\"monIntMinEdit\":5},\"runsView\":{\"comboSearchInstrument\":0," "\"postprocessedWorkspaceName\": \"\"}]}, \"textSearch\": \"123\"}, "
"\"runsTable\":{\"filterBox\":\"123\",\"projectSave\":false," "\"eventView\": {\"disabledSlicingButton\": true, \"customEdit\": \"\", "
"\"runsTableModel\":[{\"name\":\"123\",\"postprocessedWorkspaceName\":\"\"," "\"logValueButton\": false, \"logValueEdit\": \"\", \"uniformEvenButton\": "
"\"rows\":[{\"qRange\":{\"max\":0.1,\"maxPresent\":true,\"min\":0.1," "false, \"logValueTypeEdit\": \"\", \"uniformButton\": false, "
"\"minPresent\":true,\"step\":0.1,\"stepPresent\":true},\"qRangeOutput\":{" "\"uniformEdit\": 1.0, \"customButton\": false, \"uniformEvenEdit\": 1}, "
"\"maxPresent\":false,\"minPresent\":false,\"stepPresent\":false}," "\"experimentView\": {\"perAngleDefaults\": {\"columnsNum\": 9, \"rows\": "
"\"reductionOptions\":{\"ProcessingInstructions\":\"1-4\"}," "[[\"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\"]], \"rowsNum\": 1}, "
"\"reductionWorkspaces\":{\"iVsLambda\":\"\",\"iVsQ\":\"\",\"iVsQBinned\":" "\"startOverlapEdit\": 10.0, \"analysisModeComboBox\": 0, "
"\"\",\"inputRunNumbers\":[\"13460\"],\"transPair\":{\"firstTransRuns\":[" "\"reductionTypeComboBox\": 0, \"stitchEdit\": \"\", "
"\"123\"],\"secondTransRuns\":[\"1234\"]}},\"runNumbers\":[\"13460\"]," "\"floodWorkspaceWsSelector\": 0, \"includePartialBinsCheckBox\": false, "
"\"scaleFactor\":2,\"scaleFactorPresent\":true,\"theta\":0.5," "\"summationTypeComboBox\": 0, \"transScaleRHSCheckBox\": true, "
"\"transRunNums\":{\"firstTransRuns\":[\"123\"],\"secondTransRuns\":[" "\"debugCheckbox\": false, \"transStitchParamsEdit\": \"\", "
"\"1234\"]}}]}]},\"textSearch\":\"1120015\"},\"saveView\":{" "\"floodCorComboBox\": 0, \"endOverlapEdit\": 12.0, \"polCorrCheckBox\": "
"\"commaRadioButton\":false,\"fileFormatComboBox\":1,\"filterEdit\":" "false}, \"instrumentView\": {\"monBgMaxEdit\": 18.0, \"I0MonitorIndex\": 2, "
"\"123\",\"prefixEdit\":\"123\",\"qResolutionCheckBox\":true," "\"lamMinEdit\": 1.5, \"monIntMinEdit\": 4.0, \"intMonCheckBox\": true, "
"\"regexCheckBox\":true,\"savePathEdit\":\"123\"," "\"monIntMaxEdit\": 10.0, \"detectorCorrectionTypeComboBox\": 0, "
"\"saveReductionResultsCheckBox\":false,\"spaceRadioButton\":true," "\"correctDetectorsCheckBox\": true, \"lamMaxEdit\": 17.0, \"monBgMinEdit\": "
"\"tabRadioButton\":false,\"titleCheckBox\":true}}"}; "17.0}}, {\"saveView\": {\"commaRadioButton\": true, \"spaceRadioButton\": "
} "false, \"regexCheckBox\": false, \"savePathEdit\": \"\", "
"\"saveReductionResultsCheckBox\": false, \"titleCheckBox\": false, "
"\"filterEdit\": \"\", \"tabRadioButton\": false, \"prefixEdit\": \"\", "
"\"qResolutionCheckBox\": false, \"fileFormatComboBox\": 0}, \"runsView\": "
"{\"comboSearchInstrument\": 0, \"runsTable\": {\"projectSave\": true, "
"\"filterBox\": \"\", \"runsTableModel\": [{\"rows\": [{}], \"name\": "
"\"HiddenGroupName1\", \"postprocessedWorkspaceName\": \"\"}]}, "
"\"textSearch\": \"\"}, \"eventView\": {\"disabledSlicingButton\": true, "
"\"customEdit\": \"\", \"logValueButton\": false, \"logValueEdit\": \"\", "
"\"uniformEvenButton\": false, \"logValueTypeEdit\": \"\", "
"\"uniformButton\": false, \"uniformEdit\": 1.0, \"customButton\": false, "
"\"uniformEvenEdit\": 1}, \"experimentView\": {\"perAngleDefaults\": "
"{\"columnsNum\": 9, \"rows\": [[\"\", \"\", \"\", \"\", \"\", \"\", \"\", "
"\"\", \"\"]], \"rowsNum\": 1}, \"startOverlapEdit\": 10.0, "
"\"analysisModeComboBox\": 0, \"reductionTypeComboBox\": 0, \"stitchEdit\": "
"\"\", \"floodWorkspaceWsSelector\": 0, \"includePartialBinsCheckBox\": "
"false, \"summationTypeComboBox\": 0, \"transScaleRHSCheckBox\": true, "
"\"debugCheckbox\": false, \"transStitchParamsEdit\": \"\", "
"\"floodCorComboBox\": 0, \"endOverlapEdit\": 12.0, \"polCorrCheckBox\": "
"false}, \"instrumentView\": {\"monBgMaxEdit\": 18.0, \"I0MonitorIndex\": 2, "
"\"lamMinEdit\": 1.5, \"monIntMinEdit\": 4.0, \"intMonCheckBox\": true, "
"\"monIntMaxEdit\": 10.0, \"detectorCorrectionTypeComboBox\": 0, "
"\"correctDetectorsCheckBox\": true, \"lamMaxEdit\": 17.0, \"monBgMinEdit\": "
"17.0}}], \"tag\": \"ISIS Reflectometry\"}\" }";
const static QString BATCH_JSON_STRING{
"{\"eventView\":{\"customButton\":false,\"customEdit\":\"\", "
"\"disabledSlicingButton\":false,\"logValueButton\":false,"
"\"logValueEdit\":"
"\"\",\"logValueTypeEdit\":\"\",\"uniformButton\":true,\"uniformEdit\":3,"
"\"uniformEvenButton\":false,\"uniformEvenEdit\":2},\"experimentView\":{"
"\"analysisModeComboBox\":1,\"debugCheckbox\":true,\"endOverlapEdit\":13,"
"\"floodCorComboBox\":1,\"floodWorkspaceWsSelector\":0,"
"\"includePartialBinsCheckBox\":true,\"perAngleDefaults\":{"
"\"columnsNum\":"
"9,\"rows\":[[\"123\",\"123\",\"213\",\"123\",\"123\",\"123\",\"123\","
"\"123\",\"123\"]],\"rowsNum\":1},\"polCorrCheckBox\":false,"
"\"reductionTypeComboBox\":2,\"startOverlapEdit\":12,\"stitchEdit\":\"\","
"\"summationTypeComboBox\":1,\"transScaleRHSCheckBox\":true,"
"\"transStitchParamsEdit\":\"1\"},\"instrumentView\":{\"I0MonitorIndex\":"
"3,"
"\"correctDetectorsCheckBox\":false,\"detectorCorrectionTypeComboBox\":1,"
"\"intMonCheckBox\":false,\"lamMaxEdit\":18,\"lamMinEdit\":2.5,"
"\"monBgMaxEdit\":20,\"monBgMinEdit\":19,\"monIntMaxEdit\":11,"
"\"monIntMinEdit\":5},\"runsView\":{\"comboSearchInstrument\":0,"
"\"runsTable\":{\"filterBox\":\"123\",\"projectSave\":false,"
"\"runsTableModel\":[{\"name\":\"123\",\"postprocessedWorkspaceName\":"
"\"\","
"\"rows\":[{\"qRange\":{\"max\":0.1,\"maxPresent\":true,\"min\":0.1,"
"\"minPresent\":true,\"step\":0.1,\"stepPresent\":true},\"qRangeOutput\":"
"{"
"\"maxPresent\":false,\"minPresent\":false,\"stepPresent\":false},"
"\"reductionOptions\":{\"ProcessingInstructions\":\"1-4\"},"
"\"reductionWorkspaces\":{\"iVsLambda\":\"\",\"iVsQ\":\"\","
"\"iVsQBinned\":"
"\"\",\"inputRunNumbers\":[\"13460\"],\"transPair\":{\"firstTransRuns\":["
"\"123\"],\"secondTransRuns\":[\"1234\"]}},\"runNumbers\":[\"13460\"],"
"\"scaleFactor\":2,\"scaleFactorPresent\":true,\"theta\":0.5,"
"\"transRunNums\":{\"firstTransRuns\":[\"123\"],\"secondTransRuns\":["
"\"1234\"]}}]}]},\"textSearch\":\"1120015\"},\"saveView\":{"
"\"commaRadioButton\":false,\"fileFormatComboBox\":1,\"filterEdit\":"
"\"123\",\"prefixEdit\":\"123\",\"qResolutionCheckBox\":true,"
"\"regexCheckBox\":true,\"savePathEdit\":\"123\","
"\"saveReductionResultsCheckBox\":false,\"spaceRadioButton\":true,"
"\"tabRadioButton\":false,\"titleCheckBox\":true}}"};
} // namespace
/** /**
* QApplication * QApplication
...@@ -100,7 +165,7 @@ public: ...@@ -100,7 +165,7 @@ public:
void test_decodeBatch() { void test_decodeBatch() {
CoderCommonTester tester; CoderCommonTester tester;
auto map = MantidQt::API::loadJSONFromString(JSON_STRING); auto map = MantidQt::API::loadJSONFromString(BATCH_JSON_STRING);
QtMainWindowView mwv; QtMainWindowView mwv;
mwv.initLayout(); mwv.initLayout();
auto gui = dynamic_cast<QtBatchView *>(mwv.batches()[0]); auto gui = dynamic_cast<QtBatchView *>(mwv.batches()[0]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment