Salome HOME
Merge from V6_main 01/04/2013
[modules/jobmanager.git] / src / genericgui / BL_Summary.cxx
1 // Copyright (C) 2009-2013  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.
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 BL::Summary::Summary(QWidget *parent, BL::JobsManager_QT * jobs_manager) : QWidget(parent)
24 {
25   DEBTRACE("Creating BL::Summary");
26   BL_ASSERT(parent);
27   BL_ASSERT(jobs_manager);
28   _parent = parent;
29   _jobs_manager = jobs_manager;
30   _model = NULL;
31
32   
33   QLabel * summary_jobs = new QLabel("Jobs Summary:");
34   QLabel * total_label = new QLabel("Number of jobs:");
35   _total_line = new QLabel;
36   _total_line->setText("0");
37
38   QLabel * created_label = new QLabel("Number of created jobs:");
39   _created_line = new QLabel;
40   _created_line->setText("0");
41
42   QLabel * queued_label = new QLabel("Number of queued jobs:");
43   _queued_line = new QLabel;
44   _queued_line->setText("0");
45
46   QLabel * running_label = new QLabel("Number of running jobs:");
47   _running_line = new QLabel;
48   _running_line->setText("0");
49
50   QLabel * finished_label = new QLabel("Number of finished jobs:");
51   _finished_line = new QLabel;
52   _finished_line->setText("0");
53
54   QFormLayout *mainLayout = new QFormLayout;
55   mainLayout->insertRow(0, summary_jobs);
56   mainLayout->insertRow(1, total_label, _total_line);
57   mainLayout->insertRow(2, created_label, _created_line);
58   mainLayout->insertRow(3, queued_label, _queued_line);
59   mainLayout->insertRow(4, running_label, _running_line);
60   mainLayout->insertRow(5, finished_label, _finished_line);
61   setLayout(mainLayout);
62 }
63
64 BL::Summary::~Summary()
65 {
66   DEBTRACE("Destroying BL::Summary");
67 }
68
69 void
70 BL::Summary::setModel(QStandardItemModel * model)
71 {
72   DEBTRACE("Call setModel BL::Summary");
73   BL_ASSERT(model);
74
75   _model = model;
76 }
77
78 void 
79 BL::Summary::rowsInserted(const QModelIndex & parent, int start, int end)
80 {
81   DEBTRACE("BL::Summary::rowsInserted slot");
82   updateJobs();
83 }
84
85 void 
86 BL::Summary::rowsRemoved(const QModelIndex & parent, int start, int end)
87 {
88   DEBTRACE("BL::Summary::rowsRemoved slot");
89   updateJobs();
90 }
91
92 void 
93 BL::Summary::itemChanged(QStandardItem * item)
94 {
95   updateJobs();
96 }
97
98 void
99 BL::Summary::updateJobs()
100 {
101   // Total
102   QVariant row_number = _model->rowCount();
103   _total_line->setText(row_number.toString());
104
105   // New count...
106   _created_line->setText("0");
107   _queued_line->setText("0");
108   _running_line->setText("0");
109   _finished_line->setText("0");
110
111   int created_jobs = 0;
112   int queued_jobs = 0;
113   int running_jobs = 0;
114   int finished_jobs = 0;
115   std::map<std::string, BL::Job *> jobs = _jobs_manager->getJobs();
116   std::map<std::string, BL::Job *>::iterator jobs_it;
117   jobs_it = jobs.begin();
118   for(; jobs_it != jobs.end(); jobs_it++)
119   {
120     BL::Job * job = jobs_it->second;
121     BL::Job::State job_state = job->getState();
122     if (job_state == BL::Job::CREATED)
123       created_jobs++;
124     if (job_state == BL::Job::QUEUED)
125       queued_jobs++;
126     if (job_state == BL::Job::RUNNING)
127       running_jobs++;
128     if (job_state == BL::Job::FINISHED)
129       finished_jobs++;
130   }
131
132   // End
133   _created_line->setText(QVariant(created_jobs).toString());
134   _queued_line->setText(QVariant(queued_jobs).toString());
135   _running_line->setText(QVariant(running_jobs).toString());
136   _finished_line->setText(QVariant(finished_jobs).toString());
137 }