Vespucci  1.0.0
abscissatransformdialog.cpp
Go to the documentation of this file.
2 #include "ui_abscissatransformdialog.h"
3 #include <mlpack/core.hpp>
4 
5 AbscissaTransformDialog::AbscissaTransformDialog(QWidget *parent, QSharedPointer<VespucciWorkspace> ws, const QString &dataset_key) :
6  QDialog(parent),
8 {
9  ui->setupUi(this);
10  workspace_ = ws;
11  dataset_ = workspace_->GetDataset(dataset_key);
12  ui->descriptionLineEdit->setText(dataset_->x_axis_description());
13 }
14 
16 {
17  delete ui;
18 
19 }
20 
21 void AbscissaTransformDialog::on_buttonBox_accepted()
22 {
23  double out_factor = ParseInput(ui->outFactorLineEdit->text());
24  double in_factor = ParseInput(ui->inFactorLineEdit->text());
25  QString out_units = ui->outUnitsComboBox->currentText();
26  QString in_units = ui->inUnitsComboBox->currentText();
27  QString description = ui->descriptionLineEdit->text();
28  if (in_factor * out_factor){
29  dataset_->TransformAbscissa(in_units, in_factor, out_units, out_factor, description);
30  }
31 }
32 
33 double AbscissaTransformDialog::ParseInput(QString text) const
34 {
35  //split text into segments based on the asterix:
36  text.remove(" "); //remove whitespace
37  QStringList segments = text.split("*", QString::SkipEmptyParts);
38  double factor = 1.0;
39  for (auto segment: segments){
40  factor *= TextToDouble(segment);
41  }
42  return factor;
43 }
44 
45 double AbscissaTransformDialog::TextToDouble(QString text) const
46 {
47  double val;
48  bool ok;
49  if (text == "eV"){val = arma::datum::eV; ok = true;}
50  else{val = text.toDouble(&ok);}
51  return (ok ? val : 0);
52 }
AbscissaTransformDialog(QWidget *parent, QSharedPointer< VespucciWorkspace > ws, const QString &dataset_key)
Definition: ahcadialog.h:26