Vespucci  1.0.0
univariateconcatenationdialog.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (C) 2014-2016 Wright State University - All Rights Reserved
3  Daniel P. Foose - Maintainer/Lead Developer
4 
5  This file is part of Vespucci.
6 
7  Vespucci is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Vespucci is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Vespucci. If not, see <http://www.gnu.org/licenses/>.
19 *******************************************************************************/
21 #include "ui_univariateconcatenationdialog.h"
22 
23 
24 UnivariateConcatenationDialog::UnivariateConcatenationDialog(QWidget *parent, QSharedPointer<VespucciWorkspace> ws, const QString &dataset_key) :
25  QDialog(parent),
27 {
28  ui->setupUi(this);
29  workspace_ = ws;
30  dataset_ = workspace_->GetDataset(dataset_key);
31  QStringList results_keys = dataset_->AnalysisResultsKeys();
32  QStringList univariate_keys;
33  //Check type, if can't be cast, ignore
34  for (auto results_key: results_keys){
35  QSharedPointer<AnalysisResults> results = dataset_->GetAnalysisResult(results_key);
36  if (results->type() == "Univariate Analysis Results")
37  univariate_keys << results_key;
38  }
39  univariate_keys.sort();
40  ui->resultsListWidget->addItems(univariate_keys);
41 }
42 
44 {
45  delete ui;
46 }
47 
48 void UnivariateConcatenationDialog::on_buttonBox_accepted()
49 {
50  QStringList selected_keys;
51  QList<QListWidgetItem*> items = ui->resultsListWidget->selectedItems();
52  for (auto item: items) selected_keys << item->text();
53  selected_keys.sort();
54  QSharedPointer<AnalysisResults> first_results = dataset_->GetAnalysisResult(selected_keys.first());
55  QSharedPointer<AnalysisResults> new_results = first_results->Replicate();
56  new_results->SetName(ui->nameLineEdit->text());
57  selected_keys.removeFirst();
58  for (auto key: selected_keys){
59  bool ok = new_results->Concatenate(dataset_->GetAnalysisResult(key));
60  if (!ok){
61  QMessageBox::warning(this, "Error", "Could not concatenate results");
62  return;
63  }
64  }
65  //for every dataset the first result is a member of, add the new result and
66  //requisite subsets.
67  QStringList subkeys({ "Peak Centers",
68  "Peak Intensities",
69  "Adjusted Peak Intensities",
70  "Total Area",
71  "Adjusted Area",
72  "Area Between Inflection Points",
73  "Adjusted Area Between Inflection Points",
74  "Empirical Full-Width at Half-Maximum"});
75  QMap<QString, uvec> parent_rows = first_results->parent_rows();
76  for (auto key: parent_rows.keys()){
77  QSharedPointer<VespucciDataset> current_dataset = workspace_->GetDataset(key);
78  if (!current_dataset.isNull()){
79  current_dataset->AddAnalysisResult(new_results,
80  parent_rows.value(key)(0),
81  parent_rows.value(key)(1));
82  try{
83  current_dataset->AddAnalysisResult(new_results->Subset(subkeys,
84  parent_rows.value(key)(0),
85  parent_rows.value(key)(1)));
86  }catch (...){
87  //the subset does not appear if it is not valid
88  }
89  }
90  }
91  close();
92 }
93 
94 void UnivariateConcatenationDialog::on_buttonBox_rejected()
95 {
96  close();
97 }
UnivariateConcatenationDialog(QWidget *parent, QSharedPointer< VespucciWorkspace > ws, const QString &dataset_key)
Definition: ahcadialog.h:26