Vespucci  1.0.0
multiimportdialog.cpp
Go to the documentation of this file.
2 #include "ui_multiimportdialog.h"
4 
5 MultiImportDialog::MultiImportDialog(QWidget *parent, QSharedPointer<VespucciWorkspace> ws) :
6  QDialog(parent),
7  ui(new Ui::MultiImportDialog)
8 {
9  ui->setupUi(this);
10  workspace_ = ws;
11  ws->dataset_loading_count();
12  ui->nameLineEdit->setText("Dataset" + QString::number(ws->dataset_loading_count()));
13 
14  ui->filenameTableWidget->setRowCount(1);
15  ui->filenameTableWidget->setColumnCount(1);
16 }
17 
19 {
20  delete ui;
21 }
22 
23 void MultiImportDialog::on_rowSpinBox_valueChanged(int arg1)
24 {
25  ui->filenameTableWidget->setRowCount(arg1);
26  ui->countLabel->setText(QString::number(arg1 * ui->filenameTableWidget->columnCount()));
27 }
28 
29 void MultiImportDialog::on_colSpinBox_valueChanged(int arg1)
30 {
31  ui->filenameTableWidget->setColumnCount(arg1);
32  ui->countLabel->setText(QString::number(arg1 * ui->filenameTableWidget->rowCount()));
33 }
34 
35 void MultiImportDialog::on_addFilesPushButton_clicked()
36 {
37  QStringList filenames = QFileDialog::getOpenFileNames(this, "Select Files", workspace_->directory(), "Text Files (*.txt *.csv *.dat);;"
38  "All Files");
39  QStringList filenames_cpy = filenames;
40  filenames_cpy.sort();
41  QString path = filenames_cpy.first();
42  QFileInfo file_info(path);
43  QString new_directory = file_info.absoluteDir().absolutePath();
44  workspace_->set_directory(new_directory);
45 
46  QStringList::Iterator it = filenames_cpy.begin();
47  int current_row = ui->filenameTableWidget->currentRow();
48  int current_col = ui->filenameTableWidget->currentColumn();
49  int col_count = ui->filenameTableWidget->columnCount();
50  int row_count = ui->filenameTableWidget->rowCount();
51  //add selected file names to the table in alphabetical order starting with
52  //the currently highlighted cell
53  while (current_row < row_count){
54  //iterate over columns in this row
55  while (current_col < col_count && it != filenames_cpy.end()){
56  //add approprate widget item containing the filename to the
57  QTableWidgetItem *current_item = new QTableWidgetItem;
58  current_item->setText(*it);
59  ui->filenameTableWidget->setItem(current_row, current_col, current_item);
60  ++it;
61  ++current_col;
62  }
63  ++current_row;
64  current_col = 0;
65  }
66  if (it != filenames_cpy.end()){
67  QMessageBox::warning(this,
68  "Too many files selected.",
69  "The number of files selected exceeds the number of"
70  "cells in the table. Not all filenames have been "
71  "added to the table.");
72  }
73 
74 
75 }
76 
77 
78 
79 void MultiImportDialog::on_buttonBox_accepted()
80 {
81  int cols = ui->filenameTableWidget->columnCount();
82  int rows = ui->filenameTableWidget->rowCount();
83  QString name = ui->nameLineEdit->text();
84  QString x_axis_description = ui->abscissaLineEdit->text();
85  QString y_axis_description = ui->ordinateLineEdit->text();
86 
87  map<pair<int,int>, string> filename_map;
88 
89  for (int row = 0; row < rows; ++row){
90  for (int col = 0; col < cols; ++col){
91  QTableWidgetItem *item = ui->filenameTableWidget->takeItem(row, col);
92  string value = item->text().toStdString();
93  pair<int, int> key(row, col);
94  filename_map[key] = value;
95  }
96  }
97 
98 
99  arma::mat spectra;
100  arma::vec x, y, abscissa;
101  bool ok = TextImport::ImportMultiplePoints(filename_map,
102  rows, cols,
103  spectra,
104  abscissa,
105  x, y);
106  if (!ok)
107  QMessageBox::warning(this, "Import Failure", "Import of at least one file failed, or no abscissa present in any file.");
108 
109  else{
110  QSharedPointer<VespucciDataset> dataset(new VespucciDataset(filename_map,
111  workspace_->main_window(),
112  workspace_->directory_ptr(),
113  name,
114  x_axis_description,
115  y_axis_description,
116  rows, cols));
117  workspace_->AddDataset(dataset);
118  }
119 
120 }
121 
122 void MultiImportDialog::on_buttonBox_rejected()
123 {
124  close();
125 }
MultiImportDialog(QWidget *parent, QSharedPointer< VespucciWorkspace > ws)
Definition: ahcadialog.h:26
The VespucciDataset class This is the main class for dealing with hyperspectral data. This handles the import and export of spectra, and the creation of maps. Images are handled by the MapData class. This class is intended to be allocated on the heap inside of a smart pointer, there is no copy constructor.
VESPUCCI_EXPORT bool ImportMultiplePoints(std::map< std::pair< int, int >, std::string > filenames, int rows, int cols, arma::mat &spectra, arma::vec &abscissa, arma::vec &x, arma::vec &y)
TextImport::ImportMultiplePoints.
Definition: textimport.cpp:152