22#include <Poco/ActiveResult.h>
25#include <QInputDialog>
30using API::MantidDesktopServices;
36namespace MantidWidgets {
45 connect(
ui.btnAddFile, SIGNAL(clicked()),
this, SLOT(
addFile()));
46 connect(
ui.btnAddWorkspace, SIGNAL(clicked()),
this, SLOT(
addWorkspace()));
47 connect(
ui.btnDelete, SIGNAL(clicked()),
this, SLOT(
removeItem()));
49 connect(
ui.btnFit, SIGNAL(clicked()),
this, SLOT(
accept()));
50 connect(
ui.btnCancel, SIGNAL(clicked()),
this, SLOT(reject()));
51 connect(
ui.btnHelp, SIGNAL(clicked()),
this, SLOT(
helpClicked()));
52 connect(
ui.ckbLogPlot, SIGNAL(toggled(
bool)),
this, SLOT(
plotAgainstLog(
bool)));
53 connect(
ui.ckCreateOutput, SIGNAL(toggled(
bool)),
ui.ckOutputCompMembers, SLOT(setEnabled(
bool)));
54 connect(
ui.ckCreateOutput, SIGNAL(toggled(
bool)),
ui.ckConvolveMembers, SLOT(setEnabled(
bool)));
56 ui.cbLogValue->setEditable(
true);
57 ui.ckbLogPlot->setChecked(
true);
58 ui.sbPeriod->setValue(1);
67 connect(
ui.tWorkspaces, SIGNAL(cellChanged(
int,
int)),
this, SLOT(
spectraChanged(
int,
int)));
68 connect(
ui.tWorkspaces, SIGNAL(itemSelectionChanged()),
this, SLOT(
selectionChanged()));
74 if (dlg->exec() == QDialog::Accepted) {
80 if (wsNames.isEmpty())
82 int row =
ui.tWorkspaces->rowCount();
83 ui.tWorkspaces->model()->insertRows(row, wsNames.size());
85 QAbstractItemModel *model =
ui.tWorkspaces->model();
86 foreach (QString
name, wsNames) {
87 model->setData(model->index(row, 0, QModelIndex()),
name);
94 model->setData(model->index(row, 1, QModelIndex()),
"");
95 QTableWidgetItem *item =
ui.tWorkspaces->item(row, 1);
97 item->setBackground(QColor(Qt::lightGray));
98 item->setFlags(Qt::NoItemFlags);
101 if (
ui.ckbLogPlot->isChecked()) {
108 if (
y->isSpectra()) {
109 spec =
y->spectraNo(wi);
115 ui.sbSpectrum->setValue(spec);
124 ui.tWorkspaces->resizeRowsToContents();
125 ui.tWorkspaces->resizeColumnsToContents();
130 QFileDialog dlg(
this);
131 dlg.setFileMode(QFileDialog::ExistingFiles);
134 if (searchDirs.empty()) {
137 dir = QString::fromStdString(searchDirs.front());
139 dlg.setDirectory(dir);
141 QStringList fileNames;
142 fileNames = dlg.selectedFiles();
143 if (fileNames.isEmpty())
147 int row =
ui.tWorkspaces->rowCount();
148 ui.tWorkspaces->model()->insertRows(row, fileNames.size());
150 QAbstractItemModel *model =
ui.tWorkspaces->model();
151 foreach (QString
name, fileNames) {
152 model->setData(model->index(row, 0, QModelIndex()),
name);
153 model->setData(model->index(row, 1, QModelIndex()),
154 ui.sbPeriod->value());
155 model->setData(model->index(row, 2, QModelIndex()),
156 ui.sbSpectrum->value());
157 model->setData(model->index(row, 3, QModelIndex()),
"");
158 QTableWidgetItem *item =
ui.tWorkspaces->item(row, 3);
160 item->setBackground(QColor(Qt::lightGray));
161 item->setFlags(Qt::NoItemFlags);
165 ui.tWorkspaces->resizeRowsToContents();
166 ui.tWorkspaces->resizeColumnsToContents();
172 while (!ranges.empty()) {
173 ui.tWorkspaces->model()->removeRows(ranges[0].topRow(), ranges[0].
rowCount());
174 ranges =
ui.tWorkspaces->selectedRanges();
182 const std::vector<Mantid::Kernel::Property *> logs = ws->run().getLogData();
183 QStringList logNames;
185 logNames <<
"SourceName";
186 for (
auto log : logs) {
190 logNames << QString::fromStdString(log->name());
192 int n =
ui.cbLogValue->count();
194 if (logNames.empty()) {
199 ui.cbLogValue->insertItems(0, logNames);
202 QStringList namesToRemove;
203 for (
int i = 0; i <
n; ++i) {
204 QString
name =
ui.cbLogValue->itemText(i);
205 if (!logNames.contains(
name)) {
206 namesToRemove <<
name;
209 foreach (QString
name, namesToRemove) {
210 int i =
ui.cbLogValue->findText(
name);
212 ui.cbLogValue->removeItem(i);
215 if (
ui.cbLogValue->count() == 0) {
216 QMessageBox::warning(
m_fitBrowser,
"MantidPlot - Warning",
217 "The list of the log names is empty:\n"
218 "The selected workspaces do not have common logs");
227 QTableWidgetItem *item =
ui.tWorkspaces->item(row, 3);
228 return !item || item->flags().testFlag(Qt::ItemIsEnabled) ==
false;
238 QString spectrum =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 2)).toString();
239 QString wsIndex =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 3)).toString();
240 QString range =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 4)).toString();
245 if (!range.isEmpty()) {
248 index =
"sp" + spectrum;
257 if (
rowCount() == 1 && range.isEmpty()) {
258 index = QString(
"v%1:%2").arg((*
y)(0)).arg((*
y)(
y->length() - 1));
260 if (!range.isEmpty()) {
263 index =
"i" + wsIndex;
272 QStringList inputStr;
273 for (
int i = 0; i <
ui.tWorkspaces->rowCount(); ++i) {
274 QString
name =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(i, 0)).toString();
277 parStr += QString(
",") +
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(i, 1)).toString();
295 alg->setPropertyValue(
"Input", inputStr.join(
";").toStdString());
304 alg->setProperty(
"StartX", std::vector<double>(nInputs, startX));
305 alg->setProperty(
"EndX", std::vector<double>(nInputs, endX));
307 alg->setPropertyValue(
"Function", funStr);
308 alg->setProperty(
"CreateOutput",
ui.ckCreateOutput->isChecked());
309 alg->setProperty(
"OutputCompositeMembers",
ui.ckOutputCompMembers->isChecked());
310 alg->setProperty(
"ConvolveMembers",
ui.ckConvolveMembers->isChecked());
311 if (
ui.ckbLogPlot->isChecked()) {
312 std::string logName =
ui.cbLogValue->currentText().toStdString();
313 alg->setPropertyValue(
"LogValue", logName);
315 }
else if (nInputs > 1) {
316 alg->setPropertyValue(
"LogValue",
"SourceName");
323 if (
ui.rbIndividual->isChecked()) {
324 alg->setPropertyValue(
"FitType",
"Individual");
327 alg->setProperty(
"EvaluationType",
"Histogram");
330 bool passWSIndexToFunction =
ui.ckbPassWS->isChecked();
331 alg->setProperty(
"PassWSIndexToFunction", passWSIndexToFunction);
342 ui.cbParameter->clear();
343 ui.cbParameter->insertItems(0, names);
368 auto columnNames = ws->getColumnNames();
371 if (
rowCount() > 1 && columnNames[0] ==
"SourceName") {
375 auto firstColumn = ws->getColumn(0);
376 for (
size_t i = 0; i < ws->rowCount(); ++i) {
394 for (
size_t col = 1; col < columnNames.size() - 1; col += 2) {
397 auto name = columnNames[col];
400 name.insert(0,
"f0.");
425 if (!
ui.ckbLogPlot->isChecked())
427 QTableWidgetItem *item =
ui.tWorkspaces->item(row, 3);
430 if ((col == 2 || col == 3) && item->flags().testFlag(Qt::ItemIsEnabled) ==
true) {
431 QString
name =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 0)).toString();
434 ws = std::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
441 int wi =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 3)).toInt();
442 int spec =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 2)).toInt();
444 if (wi >= 0 && wi <
static_cast<int>(ws->getNumberHistograms())) {
446 if (!
y->isSpectra() ||
y->spectraNo(wi) == spec)
455 spec =
y->spectraNo(wi);
465 for (
int i = 0; i < static_cast<int>(
y->length()); ++i) {
466 if ((*
y)(i) == spec) {
482 ui.tWorkspaces->model()->setData(
ui.tWorkspaces->model()->index(row, 2), spec);
486 ui.tWorkspaces->model()->setData(
ui.tWorkspaces->model()->index(row, 3), wi);
494 return ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 0)).toString();
498 QString range = QString::number(from) +
":" + QString::number(to);
499 ui.tWorkspaces->model()->setData(
ui.tWorkspaces->model()->index(row, 3), range);
506 ui.lblLogValue->setVisible(yes);
507 ui.cbLogValue->setVisible(yes);
508 ui.lblPeriod->setVisible(yes);
509 ui.sbPeriod->setVisible(yes);
510 ui.lblSpectrum->setVisible(yes);
511 ui.sbSpectrum->setVisible(yes);
542 ui.btnDelete->setEnabled(
ui.tWorkspaces->selectionModel()->hasSelection());
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
static bool openUrl(const QUrl &url)
Opens a url in the appropriate web browser.
void observeFinish(const IAlgorithm_const_sptr &alg)
Connect to algorithm alg and observe its finish notification.
Class to represent the axis of a workspace.
IAlgorithm is the interface implemented by the Algorithm base class.
TableRow represents a row in a TableWorkspace.
double & Double(size_t col)
Returns a reference to the element in position col if its type is double.
The Logger class is in charge of the publishing messages from the framework through various channels.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
A specialised Property class for holding a series of time-value pairs.
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class