1 /*
2    Bacula(R) - The Network Backup Solution
3 
4    Copyright (C) 2000-2020 Kern Sibbald
5 
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8 
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13 
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16 
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 #include "jobsmodel.h"
20 
JobsModel(const QList<row_struct> & t,QObject * parent)21 JobsModel::JobsModel(const QList<row_struct>& t, QObject *parent)
22     : QAbstractTableModel(parent)
23     , table(t)
24 {
25 }
26 
headerData(int section,Qt::Orientation orientation,int role) const27 QVariant JobsModel::headerData(int section, Qt::Orientation orientation, int role) const
28 {
29     if (role != Qt::DisplayRole)
30         return QVariant();
31 
32     if (orientation == Qt::Horizontal) {
33         switch (section) {
34         case ID_COLUMN:
35             return tr("Id");
36         case TDATE_COLUMN:
37             return tr("Date");
38         case HASCACHE_COLUMN:
39             return tr("Cache");
40         case NAME_COLUMN:
41             return tr("Name");
42         default:
43             return QVariant();
44         }
45     }
46     return QVariant();
47 
48 
49     return QVariant();
50 }
51 
rowCount(const QModelIndex & parent) const52 int JobsModel::rowCount(const QModelIndex &parent) const
53 {
54     if (parent.isValid())
55         return 0;
56 
57     return table.size();
58 }
59 
columnCount(const QModelIndex & parent) const60 int JobsModel::columnCount(const QModelIndex &parent) const
61 {
62     if (parent.isValid())
63         return 0;
64 
65     return NUM_COLUMN;
66 }
67 
data(const QModelIndex & index,int role) const68 QVariant JobsModel::data(const QModelIndex &index, int role) const
69 {
70     if (!index.isValid())
71         return QVariant();
72 
73     if (index.row() >= table.size() || index.row() < 0)
74         return QVariant();
75 
76     if (index.column() >= NUM_COLUMN || index.column() < 0)
77         return QVariant();
78 
79     if (role == Qt::DisplayRole) {
80         row_struct row = table.at(index.row());
81         switch(index.column())
82         {
83         case 0:
84             return quint64(row.id);
85             break;
86         case 1:
87             return row.tdate;
88             break;
89         case 2:
90             return row.hasCache;
91             break;
92         case 3:
93             return row.name;
94             break;
95         }
96     }
97     return QVariant();
98 }
99