Mantid
Loading...
Searching...
No Matches
ConvertTableToMatrixWorkspaceDialog.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 +
9// Qt
10#include <QCheckBox>
11#include <QComboBox>
12#include <QFileInfo>
13#include <QUrl>
14
15// Mantid
21
23// Declare the dialog. Name must match the class name
24DECLARE_DIALOG(ConvertTableToMatrixWorkspaceDialog)
25
26
28 : API::AlgorithmDialog(parent), m_form() {}
29
36 m_form.cbColumnX->clear();
37 m_form.cbColumnY->clear();
38 m_form.cbColumnE->clear();
39 std::string wsName = qWSName.toStdString();
40 if (wsName.empty())
41 return;
42 Mantid::API::ITableWorkspace_sptr tws = std::dynamic_pointer_cast<Mantid::API::ITableWorkspace>(
43 Mantid::API::AnalysisDataService::Instance().retrieve(wsName));
44 if (!tws)
45 return; // just in case
46 m_form.cbColumnE->insertItem(-1, ""); // the default value
47 std::vector<std::string> columns = tws->getColumnNames();
48 if (columns.empty())
49 return;
50 QString defaultXColumn;
51 QString defaultYColumn;
52 QString defaultEColumn;
53 for (std::vector<std::string>::const_iterator column = columns.begin(); column != columns.end(); ++column) {
54 QString qName = QString::fromStdString(*column);
55 m_form.cbColumnX->addItem(qName);
56 m_form.cbColumnY->addItem(qName);
57 m_form.cbColumnE->addItem(qName);
58 Mantid::API::Column_sptr col = tws->getColumn(*column);
59 if (col->getPlotType() == 1 && defaultXColumn.isEmpty()) // type X
60 {
61 defaultXColumn = qName;
62 }
63 if (col->getPlotType() == 2 && defaultYColumn.isEmpty()) // type Y
64 {
65 defaultYColumn = qName;
66 }
67 if (col->getPlotType() == 5 && defaultEColumn.isEmpty()) // type yErr
68 {
69 defaultEColumn = qName;
70 }
71 }
72 // set initial guesses for column names
73 if (!defaultXColumn.isEmpty()) {
74 int i = m_form.cbColumnX->findText(defaultXColumn);
75 if (i >= 0) {
76 m_form.cbColumnX->setCurrentIndex(i);
77 }
78 }
79 if (!defaultYColumn.isEmpty()) {
80 int i = m_form.cbColumnY->findText(defaultYColumn);
81 if (i >= 0) {
82 m_form.cbColumnY->setCurrentIndex(i);
83 }
84 }
85 if (!defaultEColumn.isEmpty()) {
86 int i = m_form.cbColumnE->findText(defaultEColumn);
87 if (i >= 0) {
88 m_form.cbColumnE->setCurrentIndex(i);
89 }
90 }
91}
92
93//--------------------------------------------------------------------------
94// Private methods (non-slot)
95//---------------------------------------------------------------------------
96
99 m_form.setupUi(this);
100
101 static_cast<QVBoxLayout *>(this->layout())->addLayout(createDefaultButtonLayout());
102 tie(m_form.cbInputWorkspace, "InputWorkspace", m_form.gridLayout);
103 tie(m_form.leOutputWorkspace, "OutputWorkspace", m_form.gridLayout);
104 tie(m_form.cbColumnX, "ColumnX", m_form.gridLayout);
105 tie(m_form.cbColumnY, "ColumnY", m_form.gridLayout);
106 tie(m_form.cbColumnE, "ColumnE", m_form.gridLayout);
107
108 QString presetInputWorkspace = this->getInputValue("InputWorkspace");
109 fillAndSetComboBox("InputWorkspace", m_form.cbInputWorkspace);
110 if (!presetInputWorkspace.isEmpty()) {
111 int i = m_form.cbInputWorkspace->findText(presetInputWorkspace);
112 if (i >= 0) {
113 m_form.cbInputWorkspace->setCurrentIndex(i);
114 }
115 }
116 connect(m_form.cbInputWorkspace, SIGNAL(currentTextChanged(const QString &)), this,
117 SLOT(fillColumnNames(const QString &)));
118 fillColumnNames(m_form.cbInputWorkspace->currentText());
119}
120} // namespace MantidQt::CustomDialogs
#define DECLARE_DIALOG(classname)
QString getInputValue(const QString &propName) const
Get an input value from the form, dealing with blank inputs etc.
void fillAndSetComboBox(const QString &propName, QComboBox *optionsBox) const
Fill a combo box for the named algorithm's allowed values.
QLayout * createDefaultButtonLayout(const QString &helpText=QString("?"), const QString &loadText=QString("Run"), const QString &cancelText=QString("Close"), const QString &keepOpenText=QString("Keep Open"))
Create a row layout of buttons with specified text.
QWidget * tie(QWidget *widget, const QString &property, QLayout *parent_layout=nullptr, bool readHistory=true)
Tie a widget to a property.
This class gives specialised dialog for the ConvertTableToMatrixWorkspace algorithm.
std::shared_ptr< Column > Column_sptr
Definition Column.h:232
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace