Debian Codegraph @

src/views/ganttstatusview.h

raw
1 /*
2 This file is part of Icecream.
3
4 Copyright (c) 2003 Frerich Raabe <[email protected]>
5 Copyright (c) 2003,2004 Cornelius Schumacher <[email protected]>
6
7 This program 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 2 of the License, or
10 (at your option) any later version.
11
12 This program 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 along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21 #ifndef GANTTSTATUSVIEW_H
22 #define GANTTSTATUSVIEW_H
23
24 #include "job.h"
25 #include "statusview.h"
26
27 #include <qdialog.h>
28 #include <qmap.h>
29 #include <qpixmap.h>
30 #include <QScrollArea>
31 #include <qlist.h>
32
33 class QCheckBox;
34 class QGridLayout;
35 class QTimer;
36 class QVBoxLayout;
37
38 class GanttConfigDialog
39 : public QDialog
40 {
41 Q_OBJECT
42 public:
43 explicit GanttConfigDialog(QWidget *parent);
44
45 bool isTimeScaleVisible();
46
47 signals:
48 void configChanged();
49
50 private:
51 QCheckBox *mTimeScaleVisibleCheck;
52 };
53
54 class GanttTimeScaleWidget
55 : public QWidget
56 {
57 Q_OBJECT
58 public:
59 explicit GanttTimeScaleWidget(QWidget *parent);
60
61 void setPixelsPerSecond(int);
62
63 protected:
64 void paintEvent(QPaintEvent *e) override;
65
66 private:
67 int mPixelsPerSecond{40};
68 };
69
70 class GanttProgress
71 : public QWidget
72 {
73 Q_OBJECT
74 public:
75 GanttProgress(StatusView *statusView,
76 QWidget *parent);
77
78 bool isFree() const { return mIsFree; }
79 bool fullyIdle() const { return m_jobs.count() == 1 && isFree(); }
80
81 public slots:
82 void progress();
83 void update(const Job &job);
84
85 protected:
86 void paintEvent(QPaintEvent *e) override;
87 void resizeEvent(QResizeEvent *e) override;
88
89 private:
90 void adjustGraph();
91 void drawGraph(QPainter &p);
92 QColor colorForStatus(const Job &job) const;
93
94 struct JobData
95 {
96 JobData(Job j, int c)
97 : job(std::move(j))
98 , clock(c)
99 , next_text_width(0) {}
100 JobData() {} // stupid QValueList
101
102 bool operator==(const JobData &d)
103 {
104 return job == d.job && clock == d.clock;
105 }
106
107 Job job;
108 int clock;
109 mutable int next_text_width;
110 mutable QPixmap text_cache;
111 };
112
113 StatusView *mStatusView;
114
115 QList<JobData> m_jobs;
116
117 int mClock{0};
118
119 bool mIsFree{true};
120 };
121
122 class GanttStatusView
123 : public StatusView
124 {
125 Q_OBJECT
126 public:
127 explicit GanttStatusView(QObject *parent = nullptr);
128 ~GanttStatusView() override {}
129
130 QString id() const override { return QStringLiteral("gantt"); }
131
132 void removeNode(unsigned int hostid) override;
133 void checkNode(unsigned int hostid) override;
134
135 void start() override;
136 void stop() override;
137
138 void configureView() override;
139 bool isPausable() override { return true; }
140 bool isConfigurable() override { return true; }
141
142 QWidget *widget() const override;
143
144 public slots:
145 void update(const Job &job) override;
146
147 private slots:
148 void slotConfigChanged();
149 void updateGraphs();
150 void checkAge();
151
152 private:
153 GanttProgress *registerNode(unsigned int hostid);
154 void removeSlot(unsigned int hostid, GanttProgress *slot);
155 void unregisterNode(unsigned int hostid);
156
157 GanttConfigDialog *mConfigDialog;
158
159 QScopedPointer<QScrollArea> m_widget;
160 QWidget *mTopWidget;
161 QGridLayout *m_topLayout;
162
163 GanttTimeScaleWidget *mTimeScale;
164
165 using SlotList = QList<GanttProgress *>;
166 using NodeMap = QMap<unsigned int, SlotList>;
167 NodeMap mNodeMap;
168 using AgeMap = QMap<unsigned int, int>;
169 AgeMap mAgeMap;
170 using JobMap = QMap<unsigned int, GanttProgress *>;
171 JobMap mJobMap;
172 using NodeLayoutMap = QMap<unsigned int, QVBoxLayout *>;
173 NodeLayoutMap mNodeLayouts;
174 using NodeRowMap = QMap<unsigned int, int>;
175 NodeRowMap mNodeRows;
176 using NodeLabelMap = QMap<unsigned int, QWidget *>;
177 NodeLabelMap mNodeLabels;
178 QTimer *m_progressTimer;
179 QTimer *m_ageTimer;
180
181 bool mRunning;
182
183 int mUpdateInterval;
184
185 int mMinimumProgressHeight;
186 };
187
188 #endif
189 // vim:ts=4:sw=4:noet