2 #include "ui_spectrumeditor.h" 5 QDockWidget(main_window),
9 main_window_ = main_window;
10 workspace_ = workspace;
12 dataset_ = QSharedPointer<VespucciDataset>(0);
19 if (table_model_)
delete table_model_;
24 QDockWidget::closeEvent(ev);
30 QModelIndex current_index = ui->tableView->currentIndex();
31 if (event->key() == Qt::Key_Enter ||
event->key() == Qt::Key_Return)
32 RequestSpectrumPlot(current_index);
37 dataset_ = workspace_->GetDataset(dataset_key);
38 if (dataset_.isNull())
return;
39 if (table_model_)
delete table_model_;
41 ui->tableView->setModel(table_model_);
42 ui->tableView->resizeColumnsToContents();
43 ui->tableView->resizeRowsToContents();
50 if (!dataset_.isNull() && dataset_->name() == key){
51 if (table_model_)
delete table_model_;
53 ui->tableView->setModel(table_model_);
54 ui->tableView->resizeColumnsToContents();
55 ui->tableView->resizeRowsToContents();
60 void SpectrumEditor::on_tableView_clicked(
const QModelIndex &index)
62 RequestSpectrumPlot(index);
65 void SpectrumEditor::SpectrumRemoved(
int row)
67 if (dataset_.isNull())
return;
70 if (uword(row) >= dataset_->spectra_ptr()->n_cols)
71 row = dataset_->spectra_ptr()->n_cols - 1;
74 uvec indices = {uword(row)};
75 if (ui->holdCheckBox->isChecked())
76 plot_viewer_->
AddPlot(dataset_->abscissa(),
77 dataset_->spectra(indices),
82 dataset_->spectra(indices),
87 catch(std::exception e){
92 void SpectrumEditor::on_deletePushButton_clicked()
94 if (dataset_.isNull())
return;
96 int row = ui->tableView->currentIndex().row();
98 int response = QMessageBox::question(
this,
"Delete Spectrum?",
99 "Are you sure you want to delete the spectrum at index " + QString::number(row) +
"?",
100 QMessageBox::Yes, QMessageBox::No);
101 cout << (response == QMessageBox::Yes ?
"QMessageBox::Yes" :
"!QMessageBox::Yes") <<
"\n";
103 if (response == QMessageBox::Yes){
105 cout <<
"call ShedRow\n";
107 dataset_->ShedSpectrum(row);
109 catch(std::exception e){
115 void SpectrumEditor::on_exportPushButton_clicked()
117 if (dataset_.isNull())
return;
119 QModelIndexList model_indices = ui->tableView->selectionModel()->selectedIndexes();
120 mat data = dataset_->abscissa();
121 uvec indices(model_indices.size());
122 for (uword i = 0; i < indices.n_rows; ++i) indices(i) = model_indices[i].row();
123 data = join_horiz(data, dataset_->spectra(indices));
125 QFileDialog::getSaveFileName(
this,
"Save Spectrum",
126 workspace_->directory(),
127 "Comma-separated variables (*.csv);; " 128 "Tab-delimited text (*.txt);; " 129 "Raw binary (*.bin)");
130 QFileInfo file_info(filename);
131 QString extension = file_info.suffix();
135 if (extension.toLower() ==
"bin")
137 else if (extension.toLower() ==
"txt")
142 success = data.save(filename.toStdString(), type);
144 QMessageBox::information(main_window_,
"File Saved", filename +
" saved successfully");
146 QMessageBox::warning(main_window_,
"File not saved",
"File not saved successfully");
149 void SpectrumEditor::RequestSpectrumPlot(
const QModelIndex &index)
151 if (!dataset_.isNull() && index.isValid() && table_model_->
rowCount(index)){
152 QSharedPointer<mat> data(
new mat(join_horiz(dataset_->abscissa(),
153 dataset_->spectra_ptr()->col(index.row()))));
154 if (ui->holdCheckBox->isChecked())
155 plot_viewer_->
AddPlot(*data, dataset_->name());
161 void SpectrumEditor::on_zeroPushButton_clicked()
163 if (dataset_.isNull())
return;
165 int row = ui->tableView->currentIndex().row();
167 int response = QMessageBox::question(
this,
"Zero Spectrum?",
168 "Are you sure you want to zero the spectrum at index " + QString::number(row) +
"?",
169 QMessageBox::Yes, QMessageBox::No);
170 cout << (response == QMessageBox::Yes ?
"QMessageBox::Yes" :
"!QMessageBox::Yes") <<
"\n";
172 if (response == QMessageBox::Yes){
175 dataset_->ShedSpectrum(row);
177 catch(std::exception e){
void closeEvent(QCloseEvent *ev)
void DatasetSelectionChanged(QString dataset_key)
void DisplayExceptionWarning(std::exception e)
MainWindow::DisplayExceptionWarning.
PlotViewer * plot_viewer()
void keyPressEvent(QKeyEvent *event)
void DatasetToBeRemoved(QString key)
void AddPlot(const mat &paired_data, const QString &tab_title)
int rowCount(const QModelIndex &parent) const
The MainWindow class The main window of the program, this is where the user performs most operations...
void AddTransientPlot(const vec &abscissa, const vec &data, const QString &tab_title)
void SetActionChecked(bool checked)
SpectrumEditor(MainWindow *main_window, QSharedPointer< VespucciWorkspace > workspace)