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 <QDesktopWidget>
13#include <QFileInfo>
14#include <QUrl>
15
16// Mantid
22
24// Declare the dialog. Name must match the class name
25DECLARE_DIALOG(ConvertTableToMatrixWorkspaceDialog)
26
27
29 : API::AlgorithmDialog(parent), m_form() {}
30
37 m_form.cbColumnX->clear();
38 m_form.cbColumnY->clear();
39 m_form.cbColumnE->clear();
40 std::string wsName = qWSName.toStdString();
41 if (wsName.empty())
42 return;
43 Mantid::API::ITableWorkspace_sptr tws = std::dynamic_pointer_cast<Mantid::API::ITableWorkspace>(
45 if (!tws)
46 return; // just in case
47 m_form.cbColumnE->insertItem(-1, ""); // the default value
48 std::vector<std::string> columns = tws->getColumnNames();
49 if (columns.empty())
50 return;
51 QString defaultXColumn;
52 QString defaultYColumn;
53 QString defaultEColumn;
54 for (std::vector<std::string>::const_iterator column = columns.begin(); column != columns.end(); ++column) {
55 QString qName = QString::fromStdString(*column);
56 m_form.cbColumnX->addItem(qName);
57 m_form.cbColumnY->addItem(qName);
58 m_form.cbColumnE->addItem(qName);
59 Mantid::API::Column_sptr col = tws->getColumn(*column);
60 if (col->getPlotType() == 1 && defaultXColumn.isEmpty()) // type X
61 {
62 defaultXColumn = qName;
63 }
64 if (col->getPlotType() == 2 && defaultYColumn.isEmpty()) // type Y
65 {
66 defaultYColumn = qName;
67 }
68 if (col->getPlotType() == 5 && defaultEColumn.isEmpty()) // type yErr
69 {
70 defaultEColumn = qName;
71 }
72 }
73 // set initial guesses for column names
74 if (!defaultXColumn.isEmpty()) {
75 int i = m_form.cbColumnX->findText(defaultXColumn);
76 if (i >= 0) {
77 m_form.cbColumnX->setCurrentIndex(i);
78 }
79 }
80 if (!defaultYColumn.isEmpty()) {
81 int i = m_form.cbColumnY->findText(defaultYColumn);
82 if (i >= 0) {
83 m_form.cbColumnY->setCurrentIndex(i);
84 }
85 }
86 if (!defaultEColumn.isEmpty()) {
87 int i = m_form.cbColumnE->findText(defaultEColumn);
88 if (i >= 0) {
89 m_form.cbColumnE->setCurrentIndex(i);
90 }
91 }
92}
93
94//--------------------------------------------------------------------------
95// Private methods (non-slot)
96//---------------------------------------------------------------------------
97
100 m_form.setupUi(this);
101
102 static_cast<QVBoxLayout *>(this->layout())->addLayout(createDefaultButtonLayout());
103 tie(m_form.cbInputWorkspace, "InputWorkspace", m_form.gridLayout);
104 tie(m_form.leOutputWorkspace, "OutputWorkspace", m_form.gridLayout);
105 tie(m_form.cbColumnX, "ColumnX", m_form.gridLayout);
106 tie(m_form.cbColumnY, "ColumnY", m_form.gridLayout);
107 tie(m_form.cbColumnE, "ColumnE", m_form.gridLayout);
108
109 QString presetInputWorkspace = this->getInputValue("InputWorkspace");
110 fillAndSetComboBox("InputWorkspace", m_form.cbInputWorkspace);
111 if (!presetInputWorkspace.isEmpty()) {
112 int i = m_form.cbInputWorkspace->findText(presetInputWorkspace);
113 if (i >= 0) {
114 m_form.cbInputWorkspace->setCurrentIndex(i);
115 }
116 }
117 connect(m_form.cbInputWorkspace, SIGNAL(currentIndexChanged(const QString &)), this,
118 SLOT(fillColumnNames(const QString &)));
119 fillColumnNames(m_form.cbInputWorkspace->currentText());
120}
121} // 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.
void fillColumnNames(const QString &)
Update the column name widgets.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< Column > Column_sptr
Definition: Column.h:228
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace