Vespucci  1.0.0
spectratablemodel.cpp
Go to the documentation of this file.
2 
3 SpectraTableModel::SpectraTableModel(QObject *parent, QSharedPointer<VespucciDataset> dataset) :
4  QAbstractTableModel(parent)
5 {
6  dataset_ = dataset;
7 }
8 
10  : QAbstractTableModel(parent)
11 {
12  dataset_ = QSharedPointer<VespucciDataset>(0);
13 }
14 
15 int SpectraTableModel::rowCount(const QModelIndex &parent) const
16 {
17  if (dataset_.data()) return dataset_->spectra_ref().n_cols;
18  return 0;
19 }
20 
21 int SpectraTableModel::columnCount(const QModelIndex &parent) const
22 {
23  return 3;
24 }
25 
26 QVariant SpectraTableModel::data(const QModelIndex &index, int role) const
27 {
28  if (role != Qt::DisplayRole) return QVariant();
29 
30  if (!dataset_.data()) return QVariant();
31 
32  switch (index.column()){
33  case 0: return QString::number(index.row());
34  case 1: return QString::number(dataset_->x_ptr()->at(index.row()));
35  case 2: return QString::number(dataset_->y_ptr()->at(index.row()));
36  default: return QVariant();
37  }
38 }
39 
41 {
42  if (dataset_.data()) dataset_->ShedSpectrum(row);
43 }
44 
45 QVariant SpectraTableModel::headerData(int section, Qt::Orientation orientation, int role) const
46 {
47  if (role != Qt::DisplayRole) return QVariant();
48  if (orientation != Qt::Orientation::Horizontal) return QVariant();
49  if (section > 2) return QVariant();
50  if (section == 0) return QVariant("ind");
51  if (section == 1) return QVariant("x");
52  if (section == 2) return QVariant("y");
53  return QVariant();
54 }
55 
int columnCount(const QModelIndex &parent) const
QVariant data(const QModelIndex &index, int role) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const
SpectraTableModel(QObject *parent, QSharedPointer< VespucciDataset > dataset)
int rowCount(const QModelIndex &parent) const