Vespucci  1.0.0
vespuccitablemodel.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 *******************************************************************************/
26 VespucciTableModel::VespucciTableModel(QObject *parent, const mat & input_data, const QStringList &data_keys) :
27  QAbstractTableModel(parent),
28  data_(input_data),
29  data_keys_(data_keys)
30 {
31  start_column_ = 0;
32 }
33 
34 
35 VespucciTableModel::VespucciTableModel(QObject *parent, const mat & input_data, const uword &start_column, const QStringList &data_keys)
36  : QAbstractTableModel(parent),
37  data_(input_data),
38  data_keys_(data_keys)
39 {
40  start_column_ = start_column;
41 }
42 
49 QVariant VespucciTableModel::data(const QModelIndex &index, int role) const
50 {
51  if (role != Qt::DisplayRole){
52  return QVariant();
53  }
54  int row = index.row();
55  int column = index.column() + start_column_;
56  return QString::number(data_.at(row, column));
57 }
58 
64 int VespucciTableModel::columnCount(const QModelIndex &parent) const
65 {
66  //we don't need to use the model index here (our model only uses one object)
67 
68  //for objects with many columns, we only display the first 16 columns
69  //otherwise we take up too much memory
70  //if user wants to view that many columns, she can save the object
71  return (data_.n_cols <= 15 ? data_.n_cols : 15);
72 }
73 
79 int VespucciTableModel::rowCount(const QModelIndex &parent) const
80 {
81  //we don't need to use the model index here (our model only uses one object)
82  return data_.n_rows;
83 }
84 
89 const mat & VespucciTableModel::GetMatrix() const
90 {
91  return data_;
92 }
93 
94 bool VespucciTableModel::SaveMatrix(const QString &filename, const QString &extension) const
95 {
96  if (extension == "bin")
97  return data_.save(filename.toStdString(), raw_binary);
98  else if (extension == "csv")
99  return data_.save(filename.toStdString(), csv_ascii);
100  else if (extension == "txt")
101  return data_.save(filename.toStdString(), raw_ascii);
102  else
103  return false;
104 }
105 
111 {
112  return data_.n_cols;
113 }
114 
116 {
117  return data_keys_;
118 }
uword MatrixColumns()
VespucciTableModel::MatrixColumns.
int columnCount(const QModelIndex &parent) const
VespucciTableModel::columnCount.
VespucciTableModel(QObject *parent, const mat &input_data, const QStringList &data_keys)
VespucciTableModel::VespucciTableModel.
bool SaveMatrix(const QString &filename, const QString &extension) const
const mat & GetMatrix() const
VespucciTableModel::GetMatrix.
QVariant data(const QModelIndex &index, int role) const
VespucciTableModel::data.
int rowCount(const QModelIndex &parent) const
VespucciTableModel::rowCount.