Vespucci  1.0.0
datawidget.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 "datawidget.h"
21 #include "ui_datawidget.h"
22 
23 DataWidget::DataWidget(QWidget *parent, VespucciTableModel *table_model) :
24  QWidget(parent),
25  ui(new Ui::DataWidget)
26 {
27  ui->setupUi(this);
28  table_model_ = table_model;
29  ui->tableView->setModel(table_model);
30  ui->tableView->resizeColumnsToContents();
31  matrix_columns_=table_model->MatrixColumns();
32  subviews_ = std::ceil(matrix_columns_/15);
33  current_start_column_ = 1; //user sees indexing start at 1
34 
35  ui->backPushButton->setEnabled(false);
36  ui->forwardPushButton->setEnabled(subviews_ > 1);
37  uint last_column = (matrix_columns_ > 15 ? 15 : matrix_columns_);
38  QString label = "Showing columns 1–" + QString::number(last_column);
39  ui->columnLabel->setText(label);
40 }
41 
43 {
44  ui->tableView->setModel(table_model);
45  table_model_ = table_model;
46  ui->tableView->resizeColumnsToContents();
47 }
48 
50 {
51  return table_model_;
52 }
53 
55 {
56  delete ui;
57 }
58 
59 void DataWidget::on_forwardPushButton_clicked()
60 {
61  //user sees indexing start at one, table model indexing starts at 0
62  uint next_start_column = current_start_column_ + 15;
63  uint next_end_column = next_start_column + 15;
64  next_end_column = (next_end_column < matrix_columns_ ? next_end_column : matrix_columns_);
65  ui->backPushButton->setEnabled(true);
66  ui->forwardPushButton->setEnabled(next_end_column - 1 < matrix_columns_);
67  current_start_column_ = next_start_column;
68  table_model_ = new VespucciTableModel(ui->tableView,
69  table_model_->GetMatrix(),
70  next_start_column - 1,
71  table_model_->data_keys());
72  ui->tableView->setModel(table_model_);
73  QString label = "Showing columns " + QString::number(current_start_column_)
74  + "–" + QString::number(next_end_column);
75  ui->columnLabel->setText(label);
76  ui->tableView->resizeColumnsToContents();
77 }
78 
79 void DataWidget::on_backPushButton_clicked()
80 {
81  uint next_start_column = current_start_column_ - 15;
82  //since it's unsigned, next_start_column evaluates false if current_start_column_
83  //is less than or equal to 15, which means we're at the first view, which
84  //means we aren't able to go back any more views
85  ui->backPushButton->setEnabled(next_start_column);
86  ui->forwardPushButton->setEnabled(true);//we can always move forward from the
87  //previous page, because in order for the back button to even be active,
88  //a viewable next page must be availible
89  current_start_column_ = next_start_column;
90  uint next_end_column = current_start_column_ - 15;
91  table_model_ = new VespucciTableModel(ui->tableView,
92  table_model_->GetMatrix(),
93  next_start_column-1,
94  table_model_->data_keys());
95  ui->tableView->setModel(table_model_);
96  QString label = "Showing columns " + QString::number(current_start_column_)
97  + "–" + QString::number(next_end_column);
98  ui->columnLabel->setText(label);
99  ui->tableView->resizeColumnsToContents();
100 }
The VespucciTableModel class The QAbstractTableModel that handles armadillo objects for the DataViewe...
Definition: ahcadialog.h:26
uword MatrixColumns()
VespucciTableModel::MatrixColumns.
DataWidget(QWidget *parent, VespucciTableModel *table_model)
Definition: datawidget.cpp:23
VespucciTableModel * GetTableModel()
Definition: datawidget.cpp:49
const mat & GetMatrix() const
VespucciTableModel::GetMatrix.
void SetTableModel(VespucciTableModel *table_model)
Definition: datawidget.cpp:42