Mantid
Loading...
Searching...
No Matches
DiagResults.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------
8// Includes
9//----------------------
14#include <QCloseEvent>
15#include <QGridLayout>
16#include <QHBoxLayout>
17#include <QHashIterator>
18#include <QLabel>
19#include <QPushButton>
20#include <QRegExp>
21
22using namespace MantidQt::API;
23using namespace MantidQt::MantidWidgets;
24
25namespace {
27const int NUMTESTS = 5;
29const QString TESTS[NUMTESTS] = {"Hard mask", "First detector vanadium test", "Second detector vanadium test",
30 "Background test", "PSD Bleed test"};
31
32int find_test(const std::string &test_name) {
33 int found = -1;
34 for (int i = 0; i < NUMTESTS; i++) {
35 if (TESTS[i].toStdString() == test_name) {
36 found = i + 1;
37 return found;
38 }
39 }
40 return found;
41}
42} // namespace
43
44//----------------------
45// Public member functions
46//----------------------
48DiagResults::DiagResults(QWidget *parent) : MantidDialog(parent), m_Grid(new QGridLayout) {
49 setWindowTitle("Failed detectors list");
50
51 addRow("Test", "Number of failed spectra");
52 // make one row for each set of results
53 int row = 0;
54 for (auto col1 : TESTS) {
55 QString col2 = "N/A";
56 row = addRow(col1, col2);
57 }
58 row++;
59 auto *close = new QPushButton("Close");
60 m_Grid->addWidget(close, row, 1);
61 connect(close, SIGNAL(clicked()), this, SLOT(close()));
62
63 setLayout(m_Grid);
64
65 setAttribute(Qt::WA_DeleteOnClose, false);
66}
67
72void DiagResults::updateResults(const QString &testSummary) {
73 if (!testSummary.contains("Diagnostic Test Summary")) {
74 throw std::runtime_error("Diagnostic results string does not have expected format.");
75 }
76
77 QStringList results = testSummary.split("\n");
78 int nTestStrings = results.length();
79 int end_count(0);
80 // First result line is the header
81 for (int i = 0; i <= nTestStrings; ++i) {
82 QString testName = results[i].section(":", 0, 1);
83 std::string tn = testName.toStdString();
84 if (tn[0] == '=') {
85 end_count++;
86 if (end_count > 1)
87 break;
88 else
89 continue;
90 }
91 QStringList NameValPair = results[i].split(":");
92 tn = NameValPair[0].toStdString();
93 QStringList columns = NameValPair[1].split(QRegExp("\\s+"), Qt::SkipEmptyParts);
94 Q_ASSERT(columns.size() == 2);
95 QString status;
96 if (columns[0] == "None")
97 status = "N/A";
98 else
99 status = columns[1];
100 int test_ind = find_test(tn);
101 if (test_ind < 0)
102 continue;
103 updateRow(test_ind + 1, status);
104 }
105}
106
107//----------------------
108// Private member functions
109//----------------------
111int DiagResults::addRow(const QString &firstColumn, const QString &secondColumn) {
112 // set row to one past the end of the number of rows that currently exist
113 int row = m_Grid->rowCount();
114 m_Grid->addWidget(new QLabel(firstColumn), row, 0);
115 m_Grid->addWidget(new QLabel(secondColumn), row, 1);
116 return row;
117}
118
123void DiagResults::updateRow(int row, const QString &text) {
124 // Get the text label from the grid
125 QWidget *widget = m_Grid->itemAtPosition(row, 1)->widget();
126 QLabel *label = qobject_cast<QLabel *>(widget);
127 label->setText(text);
128}
129
131void DiagResults::closeEvent(QCloseEvent *event) {
132 emit died();
133 event->accept();
134}
void updateRow(int row, const QString &text)
Displays a summary of the results of tests in to text labels.
void updateResults(const QString &testSummary)
Update the results on the dialog.
Definition: DiagResults.cpp:72
QGridLayout * m_Grid
the layout that widgets are added to
Definition: DiagResults.h:37
void died()
is emitted just before the window dies to let the window that created this know the pointer it has is...
DiagResults(QWidget *parent)
Constructor.
Definition: DiagResults.cpp:48
void closeEvent(QCloseEvent *event) override
enables the run button on the parent window so the user can do more analysis
int addRow(const QString &firstColumn, const QString &secondColumn)
insert a row at the bottom of the grid