Vespucci  1.0.0
maplistmodel.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 *******************************************************************************/
21 
22 MapListModel::MapListModel(QObject *parent, VespucciDataset *dataset) :
23  QAbstractListModel(parent)
24 {
25  dataset_ = dataset;
26 }
27 
28 int MapListModel::rowCount(const QModelIndex &parent) const
29 {
30  return maps_.size();
31 }
32 
39 QVariant MapListModel::data(const QModelIndex &index, int role) const
40 {
41  if (!index.isValid() || index.row() >= maps_.size())
42  return QVariant();
43  else if (role == Qt::DisplayRole)
44  return QVariant(maps_.at(index.row())->name());
45  else
46  return QVariant();
47 }
48 
49 bool MapListModel::removeRow(int row, const QModelIndex &parent)
50 {
51  beginRemoveRows(parent, row, row);
52  maps_.removeAt(row);
53  endRemoveRows();
54  emit dataChanged(parent, parent);
55  return true;
56 }
57 
58 bool MapListModel::AddMap(QSharedPointer<MapData> map)
59 {
60  int row = maps_.size();
61  QModelIndex index = createIndex(row, 0);
62  beginInsertRows(index, row, row);
63  maps_.append(map);
64  endInsertRows();
65  emit dataChanged(index, index);
66  return true;
67 }
68 
69 QSharedPointer<MapData> MapListModel::MapAt(int row)
70 {
71  return maps_.at(row);
72 }
73 
78 {
79  maps_.clear();
80 }
bool AddMap(QSharedPointer< MapData > map)
The VespucciDataset class This is the main class for dealing with hyperspectral data. This handles the import and export of spectra, and the creation of maps. Images are handled by the MapData class. This class is intended to be allocated on the heap inside of a smart pointer, there is no copy constructor.
void ClearMaps()
MapListModel::ClearMaps Clears the map container. Used when closing the program.
bool removeRow(int row, const QModelIndex &parent)
QVariant data(const QModelIndex &index, int role) const
MapListModel::data.
int rowCount(const QModelIndex &parent) const
QSharedPointer< MapData > MapAt(int row)