Icemon  3.3
icecc-monitor is a monitoring application for icecc (a distributed compiler)
joblistmodel.h
1 /*
2  This file is part of Icecream.
3 
4  Copyright (c) 2012 Kevin Funk <kfunk@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
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  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef JOBLISTMODEL_H
22 #define JOBLISTMODEL_H
23 
24 #include "job.h"
25 
26 #include <QAbstractItemModel>
27 #include <QSortFilterProxyModel>
28 #include <QPointer>
29 #include <QVector>
30 
31 class Monitor;
32 class QTimer;
33 
35  : public QAbstractListModel
36 {
37  Q_OBJECT
38 
39 public:
40  enum Column
41  {
42  JobColumnID,
43  JobColumnFilename,
44  JobColumnClient,
45  JobColumnServer,
46  JobColumnState,
47  JobColumnReal,
48  JobColumnUser,
49  JobColumnFaults,
50  JobColumnSizeIn,
51  JobColumnSizeOut,
52  _JobColumnCount
53  };
54 
55  enum JobType
56  {
57  AllJobs,
58  LocalJobs,
59  RemoteJobs
60  };
61 
62  explicit JobListModel(QObject *parent = nullptr);
63 
64  Monitor *monitor() const;
65  void setMonitor(Monitor *monitor);
66 
67  int expireDuration() const {
68  return m_expireDuration;
69  }
70 
71  void setExpireDuration(int duration) {
72  m_expireDuration = duration;
73  }
74 
75  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
76  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
77  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
78  QModelIndex parent(const QModelIndex &child) const override;
79  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
80 
81  Job jobForIndex(const QModelIndex &index) const;
82  QModelIndex indexForJob(const Job &job, int column);
83 
84  void setHostId(unsigned int hostId);
85  unsigned int hostId() const { return m_hostId; }
86  void setJobType(JobType type) { m_jobType = type; }
87  JobType jobType() const { return m_jobType; }
88 
89 private Q_SLOTS:
90  void slotExpireFinishedJobs();
91 
92  void updateJob(const Job &job);
93  void clear();
94 
95 private:
96  QVector<Job> m_jobs;
97 
98  void expireItem(const Job &job);
99  void removeItem(const Job &job);
100  void removeItemById(unsigned int jobId);
101 
102  QPointer<Monitor> m_monitor;
103 
112  int m_numberOfFilePathParts;
113 
121  int m_expireDuration;
122 
123  struct FinishedJob
124  {
125  explicit FinishedJob(uint _time = 0, uint _jobId = 0)
126  : time(_time)
127  , jobId(_jobId) {}
128  uint time;
129  uint jobId;
130  };
131  using FinishedJobs = QVector<JobListModel::FinishedJob>;
132 
134  FinishedJobs m_finishedJobs;
135 
136  QTimer *m_expireTimer;
137  JobType m_jobType;
138  unsigned int m_hostId;
139 };
140 
142  : public QSortFilterProxyModel
143 {
144  Q_OBJECT
145 public:
146  explicit JobListSortFilterProxyModel(QObject *parent = nullptr);
147 
148 protected:
149  bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
150 };
151 
152 #endif
Definition: job.h:30
Definition: joblistmodel.h:34
Definition: monitor.h:36
Definition: joblistmodel.h:141