Salome HOME
Copyright update: 2016
[modules/jobmanager.git] / src / genericgui / BL_Summary.cxx
1 // Copyright (C) 2009-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "BL_Summary.hxx"
21 #include "BL_Traces.hxx"
22
23 #include <QFormLayout>
24 #include <QLabel>
25 #include <QStandardItemModel>
26
27 BL::Summary::Summary(QWidget *parent, BL::JobsManager_QT * jobs_manager) : QWidget(parent)
28 {
29   DEBTRACE("Creating BL::Summary");
30   BL_ASSERT(parent);
31   BL_ASSERT(jobs_manager);
32   _parent = parent;
33   _jobs_manager = jobs_manager;
34   _model = NULL;
35
36   
37   QLabel * summary_jobs = new QLabel("Jobs Summary:");
38   QLabel * total_label = new QLabel("Number of jobs:");
39   _total_line = new QLabel;
40   _total_line->setText("0");
41
42   QLabel * created_label = new QLabel("Number of created jobs:");
43   _created_line = new QLabel;
44   _created_line->setText("0");
45
46   QLabel * queued_label = new QLabel("Number of queued jobs:");
47   _queued_line = new QLabel;
48   _queued_line->setText("0");
49
50   QLabel * running_label = new QLabel("Number of running jobs:");
51   _running_line = new QLabel;
52   _running_line->setText("0");
53
54   QLabel * finished_label = new QLabel("Number of finished jobs:");
55   _finished_line = new QLabel;
56   _finished_line->setText("0");
57
58   QFormLayout *mainLayout = new QFormLayout;
59   mainLayout->insertRow(0, summary_jobs);
60   mainLayout->insertRow(1, total_label, _total_line);
61   mainLayout->insertRow(2, created_label, _created_line);
62   mainLayout->insertRow(3, queued_label, _queued_line);
63   mainLayout->insertRow(4, running_label, _running_line);
64   mainLayout->insertRow(5, finished_label, _finished_line);
65   setLayout(mainLayout);
66 }
67
68 BL::Summary::~Summary()
69 {
70   DEBTRACE("Destroying BL::Summary");
71 }
72
73 void
74 BL::Summary::setModel(QStandardItemModel * model)
75 {
76   DEBTRACE("Call setModel BL::Summary");
77   BL_ASSERT(model);
78
79   _model = model;
80 }
81
82 void 
83 BL::Summary::rowsInserted(const QModelIndex & parent, int start, int end)
84 {
85   DEBTRACE("BL::Summary::rowsInserted slot");
86   updateJobs();
87 }
88
89 void 
90 BL::Summary::rowsRemoved(const QModelIndex & parent, int start, int end)
91 {
92   DEBTRACE("BL::Summary::rowsRemoved slot");
93   updateJobs();
94 }
95
96 void 
97 BL::Summary::itemChanged(QStandardItem * item)
98 {
99   updateJobs();
100 }
101
102 void
103 BL::Summary::updateJobs()
104 {
105   // Total
106   QVariant row_number = _model->rowCount();
107   _total_line->setText(row_number.toString());
108
109   // New count...
110   _created_line->setText("0");
111   _queued_line->setText("0");
112   _running_line->setText("0");
113   _finished_line->setText("0");
114
115   int created_jobs = 0;
116   int queued_jobs = 0;
117   int running_jobs = 0;
118   int finished_jobs = 0;
119   std::map<std::string, BL::Job *> jobs = _jobs_manager->getJobs();
120   std::map<std::string, BL::Job *>::iterator jobs_it;
121   jobs_it = jobs.begin();
122   for(; jobs_it != jobs.end(); jobs_it++)
123   {
124     BL::Job * job = jobs_it->second;
125     BL::Job::State job_state = job->getState();
126     if (job_state == BL::Job::CREATED)
127       created_jobs++;
128     if (job_state == BL::Job::QUEUED)
129       queued_jobs++;
130     if (job_state == BL::Job::RUNNING)
131       running_jobs++;
132     if (job_state == BL::Job::FINISHED)
133       finished_jobs++;
134   }
135
136   // End
137   _created_line->setText(QVariant(created_jobs).toString());
138   _queued_line->setText(QVariant(queued_jobs).toString());
139   _running_line->setText(QVariant(running_jobs).toString());
140   _finished_line->setText(QVariant(finished_jobs).toString());
141 }