All Classes Namespaces Functions Variables Enumerations Properties Pages
predefinedsetmodel.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 // PredefinedSetModel.cpp
18 #include "predefinedsetmodel.h"
19 
20 PredefinedSetModel::PredefinedSetModel(QObject *parent, const PredefinedKeySet& mKeySet)
21  :QAbstractTableModel(parent), mKeySet(mKeySet)
22 {
23 }
24 
25 int PredefinedSetModel::rowCount(const QModelIndex & /*parent*/) const
26 {
27  return mKeySet.size();
28 }
29 
30 int PredefinedSetModel::columnCount(const QModelIndex & /*parent*/) const
31 {
32  return 2;
33 }
34 
35 QVariant PredefinedSetModel::headerData(int section, Qt::Orientation orientation, int role) const
36 {
37  if (role == Qt::DisplayRole)
38  {
39  if (orientation == Qt::Horizontal) {
40  return mKeySet.type(section);
41  }
42  }
43  return QVariant();
44 }
45 
46 QVariant PredefinedSetModel::data(const QModelIndex &index, int role) const
47 {
48  if (role == Qt::DisplayRole)
49  {
50  const int row = index.row();
51  const int column = index.column();
52 
53  if (column == PredefinedKeySet::ColumnType::FILES)
54  {
55  return mKeySet.filePathAt(row);
56  }
57  else if (column == PredefinedKeySet::ColumnType::KEYFRAMEPOS)
58  {
59  return QString::number(mKeySet.keyFrameIndexAt(row));
60  }
61  }
62  return QVariant();
63 }
QString number(int n, int base)
DisplayRole
int row() const const
int column() const const
Orientation