19QString makeNumber(
double d) {
return QString::number(d,
'g', 16); }
20const int valueColumn = 0;
21const int roleColumn = 1;
38 const QStringList &datasetNames,
39 const QStringList &datasetDomainNames,
const QList<double> &values,
41 const QStringList &constraints)
42 :
MantidDialog(parent), m_parName(parName), m_values(values), m_fixes(fixes), m_ties(
std::move(ties)),
43 m_constraints(
std::move(constraints)) {
44 assert(values.size() == datasetDomainNames.size());
45 assert(fixes.size() == datasetDomainNames.size());
46 assert(ties.size() == datasetDomainNames.size());
47 assert(constraints.size() == datasetDomainNames.size());
49 setAttribute(Qt::WA_DeleteOnClose);
50 doSetup(parName, datasetNames, datasetDomainNames);
62 const QStringList &datasetDomainNames) {
63 m_logFinder = std::make_unique<LogValueFinder>(datasetNames);
65 auto *logCombo =
m_uiForm.logValueSelector->getLogComboBox();
66 for (
const auto &logName :
m_logFinder->getLogNames()) {
67 logCombo->addItem(QString::fromStdString(logName));
70 m_uiForm.logValueSelector->setCheckboxShown(
true);
72 QHeaderView *header =
m_uiForm.tableWidget->horizontalHeader();
73 header->setSectionResizeMode(QHeaderView::Stretch);
74 connect(
m_uiForm.tableWidget, SIGNAL(cellChanged(
int,
int)),
this, SLOT(
valueChanged(
int,
int)));
75 m_uiForm.lblParameterName->setText(
"Parameter: " + parName);
77 for (
int i = 0; i < datasetDomainNames.size(); i++) {
79 auto cell =
new QTableWidgetItem(makeNumber(
m_values[i]));
80 m_uiForm.tableWidget->setItem(i, valueColumn, cell);
81 auto headerItem =
new QTableWidgetItem(datasetDomainNames[i]);
82 m_uiForm.tableWidget->setVerticalHeaderItem(i, headerItem);
83 cell =
new QTableWidgetItem(
"");
84 auto flags = cell->flags();
85 flags ^= Qt::ItemIsEditable;
86 flags ^= Qt::ItemIsSelectable;
87 flags ^= Qt::ItemIsEnabled;
88 cell->setFlags(flags);
89 m_uiForm.tableWidget->setItem(i, roleColumn, cell);
93 m_uiForm.tableWidget->setItemDelegateForColumn(valueColumn, deleg);
97 connect(deleg, SIGNAL(
setTie(
int, QString)),
this, SLOT(
setTie(
int, QString)));
104 m_uiForm.tableWidget->installEventFilter(
this);
111 if (col == valueColumn) {
112 QString text =
m_uiForm.tableWidget->item(row, col)->text();
115 double value = text.toDouble(&ok);
121 }
catch (std::exception &) {
132 for (
int i = 0; i <
n; ++i) {
134 m_uiForm.tableWidget->item(i, valueColumn)->setText(makeNumber(
value));
172 for (
int i = 0; i <
m_ties.size(); ++i) {
198 for (
int i = 0; i <
m_fixes.size(); ++i) {
208 if (
obj ==
m_uiForm.tableWidget && ev->type() == QEvent::ContextMenu) {
211 return QDialog::eventFilter(
obj, ev);
216 auto selection =
m_uiForm.tableWidget->selectionModel()->selectedColumns();
218 bool hasSelection =
false;
220 for (
auto &
index : selection) {
221 if (
index.column() == valueColumn)
228 QMenu *menu =
new QMenu(
this);
230 QAction *action =
new QAction(
"Copy",
this);
231 action->setToolTip(
"Copy data to clipboard.");
232 connect(action, SIGNAL(triggered()),
this, SLOT(
copy()));
233 menu->addAction(action);
236 QAction *action =
new QAction(
"Paste",
this);
237 action->setToolTip(
"Paste data from clipboard.");
238 connect(action, SIGNAL(triggered()),
this, SLOT(
paste()));
239 auto text = QApplication::clipboard()->text();
240 action->setEnabled(!text.isEmpty());
241 menu->addAction(action);
244 menu->exec(QCursor::pos());
252 for (
int i = 0; i <
n; ++i) {
255 QApplication::clipboard()->setText(text.join(
"\n"));
260 auto text = QApplication::clipboard()->text();
261 auto vec = text.split(QRegExp(
"\\s|,"), Qt::SkipEmptyParts);
262 auto n = qMin(vec.size(),
m_uiForm.tableWidget->rowCount());
267 for (
int i = 0; i <
n; ++i) {
273 m_uiForm.tableWidget->item(i, valueColumn)->setText(str);
279 for (
int i = 0; i <
m_values.size(); ++i) {
281 auto text = makeNumber(
m_values[i]);
282 m_uiForm.tableWidget->item(i, valueColumn)->setText(text +
" ");
283 m_uiForm.tableWidget->item(i, valueColumn)->setText(text);
293 cell->setForeground(QBrush(Qt::red));
296 cell->setForeground(QBrush(Qt::blue));
299 cell->setForeground(QBrush(Qt::darkGreen));
309 for (
int j = 0; j <
m_fixes.size(); ++j) {
318 for (
int j = 0; j <
m_fixes.size(); ++j) {
327 for (
int j = 0; j <
m_fixes.size(); ++j) {
328 if (j != i && !
m_ties[j].isEmpty())
339 const auto &logName =
m_uiForm.logValueSelector->getLog();
340 const auto &function =
m_uiForm.logValueSelector->getFunction();
342 double value = std::numeric_limits<double>::quiet_NaN();
345 }
catch (
const std::invalid_argument &err) {
346 const auto &message = QString(
"Failed to get log value:\n\n %1").arg(err.what());
347 QMessageBox::critical(
this,
"Mantid - Error", message);
350 m_uiForm.tableWidget->item(i, valueColumn)->setText(makeNumber(
value));
356 const int nValues =
m_values.size();
357 for (
int i = 0; i < nValues; ++i) {
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
double obj
the value of the quadratic function