Vespucci  1.0.0
plotmakerdialog.cpp
Go to the documentation of this file.
2 #include "ui_plotmakerdialog.h"
4 
5 PlotMakerDialog::PlotMakerDialog(MainWindow *parent, PlotViewer *plot_viewer, QSharedPointer<VespucciWorkspace> ws, QStringList data_keys) :
6  QDialog(parent),
7  ui(new Ui::PlotMakerDialog),
8  workspace_(ws),
9  data_keys_(data_keys)
10 {
11  ui->setupUi(this);
12  parent_ = parent;
13  plot_viewer_ = plot_viewer;
14 
15  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(data_keys.first());
16  if (dataset.isNull()){
17  QMessageBox::warning(this, "Dataset Does not Exist",
18  "An error has occurred: dataset does not exist with specified name");
19  close();
20  }
21 
22  if (!workspace_->GetMatrix(data_keys).n_elem){
23  QMessageBox::warning(this, "Matrix Does Not Exist",
24  "An error has occurred: matrix does not exist with specified keys");
25  close();
26  }
27 
28 
29  if (workspace_->GetMatrix(data_keys).n_rows == dataset->abscissa_ref().n_rows)
30  ui->abscissaComboBox->addItem("Spectral Abscissa");
31  ui->abscissaComboBox->addItem("Column");
32 
33  ui->xSpinBox->setMaximum(workspace_->GetMatrix(data_keys_).n_cols);
34  ui->ySpinBox->setMaximum(workspace_->GetMatrix(data_keys_).n_cols);
35  ui->xSpinBox->setMinimum(1);
36  ui->ySpinBox->setMinimum(1);
37 
38  if (ui->abscissaComboBox->currentText() == "Spectral Abscissa")
39  ui->ySpinBox->setValue(1);
40  else
41  ui->ySpinBox->setValue(2);
42 }
43 
45 {
46  delete ui;
47 }
48 
49 void PlotMakerDialog::on_buttonBox_accepted()
50 {
51 
52  QString abscissa_type = ui->abscissaComboBox->currentText();
53  QString dimension_type = ui->dimensionComboBox->currentText();
54  uword x_ind = ui->xSpinBox->value() - 1;
55  uword y_ind = ui->ySpinBox->value() - 1;
56  vec x, y;
57 
58 
59 
60  QString plot_title = data_keys_.last()
61  + " " + QString::number(y_ind + 1);
62  if (abscissa_type == "Row" || abscissa_type == "Column"){
63  plot_title = plot_title
64  + " vs. "
65  + abscissa_type
66  + " " + QString::number(x_ind + 1);
67  }
68 
69  if (dimension_type == "Column")
70  y = workspace_->GetMatrix(data_keys_).col(y_ind);
71 
72  if (dimension_type == "Row")
73  y = workspace_->GetMatrix(data_keys_).row(y_ind).t();
74 
75  if (abscissa_type == "Spectral Abscissa")
76  x = workspace_->GetDataset(data_keys_.first())->abscissa();
77 
78  if (abscissa_type == "Column")
79  x = workspace_->GetMatrix(data_keys_).col(x_ind);
80 
81  if (abscissa_type == "Row")
82  x = workspace_->GetMatrix(data_keys_).row(x_ind).t();
83 
84  if (y.n_elem && (x.n_rows == y.n_rows)){
85  if (ui->typeComboBox->currentText() == "Scatter")
86  plot_viewer_->AddScatterPlot(x, y, plot_title);
87  else plot_viewer_->AddPlot(x, y, plot_title);
88  }
89  else{
90  QMessageBox::warning(this, "Dimension Mismatch", "Matrix dimensions do not match");
91  }
92  close();
93 }
94 
95 
96 void PlotMakerDialog::on_dimensionComboBox_currentTextChanged(const QString &arg1)
97 {
98  if (arg1 == "Row"){
99  ui->abscissaComboBox->clear();
100  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(data_keys_.first());
101  if (workspace_->GetMatrix(data_keys_).n_cols == dataset->spectra_ref().n_rows)
102  ui->abscissaComboBox->addItem("Spectral Abscissa");
103  ui->abscissaComboBox->addItem("Row");
104  ui->xSpinBox->setMaximum(workspace_->GetMatrix(data_keys_).n_rows);
105  ui->ySpinBox->setMaximum(workspace_->GetMatrix(data_keys_).n_rows);
106  }
107 
108  if (arg1 == "Column"){
109  ui->abscissaComboBox->clear();
110  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(data_keys_.first());
111  if (workspace_->GetMatrix(data_keys_).n_rows == dataset->abscissa_ref().n_rows)
112  ui->abscissaComboBox->addItem("Spectral Abscissa");
113  ui->abscissaComboBox->addItem("Column");
114  ui->xSpinBox->setMaximum(workspace_->GetMatrix(data_keys_).n_cols);
115  ui->ySpinBox->setMaximum(workspace_->GetMatrix(data_keys_).n_cols);
116  }
117 }
Definition: ahcadialog.h:26
PlotMakerDialog(MainWindow *parent, PlotViewer *plot_viewer, QSharedPointer< VespucciWorkspace > ws, QStringList data_keys)
void AddPlot(const mat &paired_data, const QString &tab_title)
Definition: plotviewer.cpp:19
void AddScatterPlot(const mat &paired_data, const QString &tab_title)
Definition: plotviewer.cpp:75
The MainWindow class The main window of the program, this is where the user performs most operations...
Definition: mainwindow.h:58