Vespucci  1.0.0
mapdialog.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 *******************************************************************************/
20 #include "mapdialog.h"
21 #include "ui_mapdialog.h"
22 
23 MapDialog::MapDialog(MainWindow *parent, QStringList data_keys, QSharedPointer<VespucciWorkspace> ws) :
24  QDialog(parent),
25  ui(new Ui::MapDialog)
26 {
27  ui->setupUi(this);
28  workspace_ = ws;
29  data_keys_ = data_keys;
30  main_window_ = parent;
31 
32  if (data_keys_.size() > 3 || data_keys_.size() < 2 || !workspace_->Mappable(data_keys)){
33  QMessageBox::warning(this, "Cannot map this object", "Object is not mappable");
34  hide();
35  close();
36  return;
37  }
38 
39  uword col_count;
40  try{
41  col_count = workspace_->GetMatrix(data_keys_).n_cols;
42  }catch(exception e){
43  main_window_->DisplayExceptionWarning("MapDialog constructor, VespucciWorkspace::GetMatrix", e);
44  close();
45  }
46 
47  try{
48  dataset_ = workspace_->data_model()->GetDataset(data_keys_[0]);
49  }catch(exception e){
50  main_window_->DisplayExceptionWarning("MapDialog constructor, DataModel::GetDataset", e);
51  close();
52  }
53 
54  ui->columnSpinBox->setRange(1, col_count);
55  ui->nameLineEdit->setText(data_keys_.last());
56  uword unique_ct = vec(unique(workspace_->GetMatrix(data_keys_).col(0))).n_elem;
57  QStringList color_list = workspace_->GradientNames(unique_ct < 10);
58  ui->gradientComboBox->addItems(color_list);
59 }
60 
62 {
63  delete ui;
64 }
65 
66 void MapDialog::on_buttonBox_accepted()
67 {
68  uword unique_ct = vec(unique(workspace_->GetMatrix(data_keys_).col(0))).n_elem;
69  uint column_index = ui->columnSpinBox->value() - 1;
70  QString map_name = ui->nameLineEdit->text();
71  vec data;
72  bool ok = true;
73  try{
74  data = workspace_->data_model()->GetMatrix(data_keys_).col(column_index);
75  }catch(exception e){
76  main_window_->DisplayExceptionWarning("DataModel::GetMatrix or mat::col", e);
77  ok = false;
78  }
79 
80  if (ok){
81  QCPColorGradient gradient = workspace_->GetGradient(ui->gradientComboBox->currentText(), unique_ct);
82 
83  try{
84  if (data_keys_.size() == 2)
85  dataset_->CreateMap(map_name,
86  data_keys_[1],
87  column_index,
88  gradient);
89  else
90  dataset_->CreateMap(map_name,
91  data_keys_[1],
92  data_keys_[2],
93  column_index,
94  gradient);
95  }catch(exception e){
96  main_window_->DisplayExceptionWarning("VespucciDataset::CreateMap()", e);
97  }
98  }
99  close();
100 }
101 
102 void MapDialog::on_columnSpinBox_valueChanged(int arg1)
103 {
104  mat data;
105  bool ok = true;
106  try{
107  data = workspace_->data_model()->GetMatrix(data_keys_).col(arg1-1);
108  }catch(exception e){
109  main_window_->DisplayExceptionWarning("DataModel::GetMatrix or mat::col", e);
110  ok = false;
111  close();
112  }
113  if (ok){
114  vec unique_values = unique(data);
115  QStringList color_list = workspace_->GradientNames(unique_values.n_rows < 10);
116  ui->gradientComboBox->clear();
117  ui->gradientComboBox->addItems(color_list);
118  }
119 }
MapDialog(MainWindow *parent, QStringList data_keys, QSharedPointer< VespucciWorkspace > ws)
Definition: mapdialog.cpp:23
Definition: ahcadialog.h:26
void DisplayExceptionWarning(std::exception e)
MainWindow::DisplayExceptionWarning.
Definition: mainwindow.cpp:845
Defines a color gradient for use with e.g. QCPColorMap.
Definition: qcustomplot.h:1905
The MainWindow class The main window of the program, this is where the user performs most operations...
Definition: mainwindow.h:58