Vespucci  1.0.0
dataviewer.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 "GUI/Display/dataviewer.h"
21 #include "ui_dataviewer.h"
22 #include "GUI/Display/datawidget.h"
23 #include "Global/global.h"
29 DataViewer::DataViewer(MainWindow *parent, QSharedPointer<VespucciWorkspace> ws)
30  :QDockWidget(parent),
31  ui(new Ui::DataViewer)
32 {
33  ui->setupUi(this);
34  workspace_ = ws;
35  connect(ui->tabWidget, &QTabWidget::tabCloseRequested,
36  this, &DataViewer::RemoveTab);
37 }
38 
40 {
41  delete ui;
42 }
43 
44 void DataViewer::RemoveTab(int index)
45 {
46  //if we wanted to warn the user about closing a tab, we'd put it here
47  //but we don't have to because they can always get it back as long as the
48  //matrix exists
49  ui->tabWidget->removeTab(index);
50 }
51 
60 {
61  //iterate backwards through widgets and remove any widgets that represent
62  //matrices coming from the dataset about to be removed.
63  int i = ui->tabWidget->count();
64  while (i--){
65  DataWidget *widget = qobject_cast<DataWidget *>(ui->tabWidget->widget(i));
66  if (widget->GetTableModel()->data_keys().first() == name)
67  ui->tabWidget->removeTab(i);
68  }
69 }
70 
76 void DataViewer::MatrixToBeRemoved(QStringList keys)
77 {
78  int i = ui->tabWidget->count();
79  while (i--){
80  DataWidget *widget = qobject_cast<DataWidget *>(ui->tabWidget->widget(i));
81  QStringList data_keys = widget->GetTableModel()->data_keys();
82  if (Vespucci::KeysAreEqual(data_keys, keys))
83  ui->tabWidget->removeTab(i);
84  }
85 }
86 
87 void DataViewer::AddTab(QStringList keys)
88 {
89  VespucciTableModel *new_model = new VespucciTableModel(this,
90  workspace_->GetMatrix(keys),
91  keys);
92  DataWidget *widget = new DataWidget(this, new_model);
93  ui->tabWidget->addTab(widget, keys.last());
94  ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1);
95 }
96 
97 void DataViewer::closeEvent(QCloseEvent *ev)
98 {
99  QDockWidget::closeEvent(ev);
100  emit SetActionChecked(false);
101 }
102 
The VespucciTableModel class The QAbstractTableModel that handles armadillo objects for the DataViewe...
Definition: ahcadialog.h:26
DataViewer(MainWindow *parent, QSharedPointer< VespucciWorkspace > ws)
DataViewer::DataViewer.
Definition: dataviewer.cpp:29
VespucciTableModel * GetTableModel()
Definition: datawidget.cpp:49
void DatasetToBeRemoved(QString name)
DataViewer::DatasetRemoved.
Definition: dataviewer.cpp:59
The DataViewer class Window that displays dataset elements in a QTableView widget inside a QTabWidget...
Definition: dataviewer.h:41
bool KeysAreEqual(QStringList &keys1, QStringList &keys2)
Definition: global.cpp:168
void MatrixToBeRemoved(QStringList keys)
DataViewer::MatrixToBeRemoved.
Definition: dataviewer.cpp:76
void AddTab(QStringList keys)
Definition: dataviewer.cpp:87
void closeEvent(QCloseEvent *ev)
Definition: dataviewer.cpp:97
void RemoveTab(int index)
Definition: dataviewer.cpp:44
void SetActionChecked(bool checked)
The MainWindow class The main window of the program, this is where the user performs most operations...
Definition: mainwindow.h:58