/
LoadRawDialog.cpp
199 lines (167 loc) · 5.92 KB
/
LoadRawDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include "MantidQtCustomDialogs/LoadRawDialog.h"
#include "MantidQtAPI/AlgorithmInputHistory.h"
#include "MantidKernel/Property.h"
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QGridLayout>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QGroupBox>
#include <QComboBox>
#include <QFontMetrics>
#include <QFileInfo>
#include <QDir>
#include <QCheckBox>
//Add this class to the list of specialized dialogs in this namespace
namespace MantidQt
{
namespace CustomDialogs
{
DECLARE_DIALOG(LoadRawDialog)
}
}
// Just to save writing this everywhere
using namespace MantidQt::CustomDialogs;
//---------------------------------------
// Public member functions
//---------------------------------------
/**
* Constructor
*/
LoadRawDialog::LoadRawDialog(QWidget *parent) : AlgorithmDialog(parent),
m_pathBox(NULL), m_wsBox(NULL)
{
}
/**
*Destructor
*/
LoadRawDialog::~LoadRawDialog()
{
}
//---------------------------------------
// Private member functions
//---------------------------------------
/**
* Reimplemented virtual function to set up the dialog
*/
void LoadRawDialog::initLayout()
{
QVBoxLayout *main_layout = new QVBoxLayout(this);
// Add the helpful summary message
if( isMessageAvailable() )
this->addOptionalMessage(main_layout);
//------------- Filename property ---------------------
QHBoxLayout *prop_line = new QHBoxLayout;
prop_line->addWidget(new QLabel("Select a file to load:"));
m_pathBox = new QLineEdit;
m_pathBox->setMinimumWidth(m_pathBox->fontMetrics().maxWidth()*13);
prop_line->addWidget(m_pathBox);
tie(m_pathBox, "Filename", prop_line);
QPushButton *browseBtn = new QPushButton("Browse");
connect(browseBtn, SIGNAL(clicked()), this, SLOT(browseClicked()));
browseBtn->setEnabled(isWidgetEnabled("Filename"));
prop_line->addWidget(browseBtn);
main_layout->addLayout(prop_line);
//------------- OutputWorkspace property ---------------------
m_wsBox = new QLineEdit;
prop_line = new QHBoxLayout;
prop_line->addWidget(new QLabel("Enter name for workspace:"));
prop_line->addWidget(m_wsBox);
tie(m_wsBox, "OutputWorkspace", prop_line);
prop_line->addStretch();
main_layout->addLayout(prop_line);
//------------- Spectra properties ---------------------
QGroupBox *groupbox = new QGroupBox("Spectra Options");
prop_line = new QHBoxLayout;
QLineEdit *text_field = new QLineEdit;
text_field->setMaximumWidth(m_wsBox->fontMetrics().width("888888"));
prop_line->addWidget(new QLabel("Start:"));
prop_line->addWidget(text_field);
tie(text_field, "SpectrumMin", prop_line);
text_field = new QLineEdit;
text_field->setMaximumWidth(m_wsBox->fontMetrics().width("888888"));
prop_line->addWidget(new QLabel("End:"));
prop_line->addWidget(text_field);
tie(text_field, "SpectrumMax", prop_line);
text_field = new QLineEdit;
prop_line->addWidget(new QLabel("List:"));
prop_line->addWidget(text_field);
tie(text_field, "SpectrumList", prop_line);
prop_line->addStretch();
groupbox->setLayout(prop_line);
main_layout->addWidget(groupbox);
//------------- Period properties ---------------------
prop_line = new QHBoxLayout;
text_field = new QLineEdit;
prop_line->addWidget(new QLabel("Periods:"));
prop_line->addWidget(text_field);
prop_line->addStretch();
tie(text_field, "PeriodList", prop_line);
main_layout->addLayout(prop_line);
//------------- Cache option , log files options and Monitors Options ---------------------
Mantid::Kernel::Property* cacheProp= getAlgorithmProperty("Cache");
if(cacheProp)
{
QComboBox *cacheBox = new QComboBox;
std::vector<std::string> items =cacheProp->allowedValues();
std::vector<std::string>::const_iterator vend = items.end();
for(std::vector<std::string>::const_iterator vitr = items.begin(); vitr != vend;
++vitr)
{
cacheBox->addItem(QString::fromStdString(*vitr));
}
prop_line = new QHBoxLayout;
prop_line->addWidget(new QLabel("Cache file locally:"), 0, Qt::AlignRight);
prop_line->addWidget(cacheBox, 0, Qt::AlignLeft);
tie(cacheBox, "Cache", prop_line);
}
prop_line->addStretch();
//If the algorithm version supports the LoadLog property add a check box for it
Mantid::Kernel::Property *loadlogs = getAlgorithmProperty("LoadLogFiles");
if( loadlogs )
{
QCheckBox *checkbox = new QCheckBox ("Load Log Files",this);
prop_line->addWidget(checkbox);
tie(checkbox, "LoadLogFiles", prop_line);
}
prop_line->addStretch();
//------------- If the algorithm version supports the LoadMonitors property add a check box for it ----
Mantid::Kernel::Property* loadMonitors=getAlgorithmProperty("LoadMonitors");
if(loadMonitors)
{
QComboBox *monitorsBox =new QComboBox;
std::vector<std::string> monitoritems =loadMonitors->allowedValues();
std::vector<std::string>::const_iterator mend = monitoritems.end();
for(std::vector<std::string>::const_iterator mitr = monitoritems.begin(); mitr != mend;
++mitr)
{
monitorsBox->addItem(QString::fromStdString(*mitr));
}
prop_line->addWidget(new QLabel("LoadMonitors:"), 0, Qt::AlignRight);
prop_line->addWidget(monitorsBox);
tie(monitorsBox, "LoadMonitors", prop_line);
}
if(prop_line)main_layout->addLayout(prop_line);
//Buttons
main_layout->addLayout(createDefaultButtonLayout("?", "Load", "Cancel"));
}
/**
* A slot for the browse button "clicked" signal
*/
void LoadRawDialog::browseClicked()
{
if( !m_pathBox->text().isEmpty() )
{
MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(QFileInfo(m_pathBox->text()).absoluteDir().path());
}
QString filepath = this->openFileDialog("Filename");
if( !filepath.isEmpty() )
{
m_pathBox->clear();
m_pathBox->setText(filepath.trimmed());
}
//Add a suggestion for workspace name
if( m_wsBox->isEnabled() && !filepath.isEmpty() ) m_wsBox->setText(QFileInfo(filepath).baseName());
}