-
Notifications
You must be signed in to change notification settings - Fork 122
/
LoadAsciiDialog.cpp
142 lines (119 loc) · 4.38 KB
/
LoadAsciiDialog.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
//----------------------
// Includes
//----------------------
#include "MantidQtCustomDialogs/LoadAsciiDialog.h"
#include "MantidQtAPI/AlgorithmInputHistory.h"
#include <QValidator>
#include <QtGui>
#include <QFileInfo>
namespace MantidQt
{
namespace CustomDialogs
{
DECLARE_DIALOG(LoadAsciiDialog)
LoadAsciiDialog::LoadAsciiDialog(QWidget *parent)
: MantidQt::API::AlgorithmDialog(parent)
{
}
LoadAsciiDialog::~LoadAsciiDialog()
{
}
void LoadAsciiDialog::initLayout()
{
QGridLayout *paramsLayout = new QGridLayout;
QLabel *label = new QLabel(tr("Filename"));
m_lineFilename = new QLineEdit;
label->setBuddy(m_lineFilename);
paramsLayout->addWidget(label,0,0);
paramsLayout->addWidget(m_lineFilename,0,1);
tie(m_lineFilename, "Filename", paramsLayout);
connect(m_lineFilename,SIGNAL(editingFinished()),this,SLOT(checkFileExtension()));
QPushButton *browseBtn = new QPushButton("Browse");
connect(browseBtn, SIGNAL(clicked()), this, SLOT(browseClicked()));
browseBtn->setEnabled(isWidgetEnabled("Filename"));
paramsLayout->addWidget(browseBtn,0,3);
label = new QLabel(tr("Workspace"));
m_lineOutputWorkspace = new QLineEdit;
label->setBuddy(m_lineOutputWorkspace);
paramsLayout->addWidget(label,1,0);
paramsLayout->addWidget(m_lineOutputWorkspace,1,1);
tie(m_lineOutputWorkspace, "OutputWorkspace", paramsLayout);
m_separatorBox = new QComboBox;
fillAndSetComboBox("Separator",m_separatorBox);
paramsLayout->addWidget(new QLabel("Separator"),2,0);
paramsLayout->addWidget(m_separatorBox,2,1);
tie(m_separatorBox,"Separator",paramsLayout);
if (getAlgorithm()->version() == 2)
{
label = new QLabel(tr("CustomSeparator"));
m_lineCustomSeparator = new QLineEdit;
label->setBuddy(m_lineCustomSeparator);
paramsLayout->addWidget(label,3,0);
paramsLayout->addWidget(m_lineCustomSeparator,3,1);
tie(m_lineCustomSeparator, "CustomSeparator", paramsLayout);
label = new QLabel(tr("CommentIndicator"));
m_lineCommentIndicator = new QLineEdit;
label->setBuddy(m_lineCommentIndicator);
paramsLayout->addWidget(label,4,0);
paramsLayout->addWidget(m_lineCommentIndicator,4,1);
tie(m_lineCommentIndicator, "CommentIndicator", paramsLayout);
QComboBox *unitBox = new QComboBox;
fillAndSetComboBox("Unit",unitBox );
paramsLayout->addWidget(new QLabel("Unit"),5,0);
paramsLayout->addWidget(unitBox ,5,1);
tie(unitBox ,"Unit",paramsLayout);
}
else
{
QComboBox *unitBox = new QComboBox;
fillAndSetComboBox("Unit",unitBox );
paramsLayout->addWidget(new QLabel("Unit"),3,0);
paramsLayout->addWidget(unitBox ,3,1);
tie(unitBox ,"Unit",paramsLayout);
}
QVBoxLayout *mainLayout = new QVBoxLayout;
//Adds the yellow optional message
if( isMessageAvailable() )
{
this->addOptionalMessage(mainLayout);
}
mainLayout->addLayout(paramsLayout);
mainLayout->addLayout(createDefaultButtonLayout("?", "Load", "Cancel"));
setLayout(mainLayout);
setFixedHeight(sizeHint().height());
checkFileExtension();
}
/**
* A slot for the browse button "clicked" signal
*/
void LoadAsciiDialog::browseClicked()
{
if( !m_lineFilename->text().isEmpty() )
{
MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(QFileInfo(m_lineFilename->text()).absoluteDir().path());
}
QString filepath = this->openFileDialog("Filename");
if( !filepath.isEmpty() )
{
m_lineFilename->clear();
m_lineFilename->setText(filepath.trimmed());
}
//Add a suggestion for workspace name
if( m_lineOutputWorkspace->isEnabled() && !filepath.isEmpty() ) m_lineOutputWorkspace->setText(QFileInfo(filepath).baseName());
checkFileExtension();
}
/**
* Check for consistency between the file extension and the separator
*/
void LoadAsciiDialog::checkFileExtension()
{
QString fileName = m_lineFilename->text();
if (fileName.isEmpty()) return;
QFileInfo file(fileName);
if (file.suffix().toLower() == "csv")
{
m_separatorBox->setCurrentIndex(m_separatorBox->findText("CSV"));
}
}
}
}