1 // Copyright (C) 2009 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "BL_QModelManager.hxx"
22 BL::QModelManager::QModelManager(QObject * parent, BL::JobsManager_QT * jobs_manager) : QObject(parent)
24 DEBTRACE("Creating BL::QModelManager");
25 BL_ASSERT(jobs_manager);
26 _jobs_manager = jobs_manager;
28 _model = new QStandardItemModel(this);
30 headers << "Job Name" << "Type" << "State" << "Machine";
31 _model->setHorizontalHeaderLabels(headers);
34 BL::QModelManager::~QModelManager()
36 DEBTRACE("Destroying BL::QModelManager");
40 BL::QModelManager::getModel()
42 DEBTRACE("getModel BL::QModelManager called");
48 BL::QModelManager::new_job_added(const QString & name)
50 BL::Job * job = _jobs_manager->getJob(name.toStdString());
51 QStandardItem * new_job_name = new QStandardItem(name);
53 QStandardItem * new_job_type;
54 if (job->getType() == BL::Job::YACS_SCHEMA)
55 new_job_type = new QStandardItem("YACS_Schema");
57 new_job_type = new QStandardItem("Command");
59 QStandardItem * new_job_state;
60 if (job->getState() == BL::Job::CREATED)
61 new_job_state = new QStandardItem("Created");
62 else if (job->getState() == BL::Job::QUEUED)
63 new_job_state = new QStandardItem("Queued");
64 else if (job->getState() == BL::Job::RUNNING)
65 new_job_state = new QStandardItem("Running");
66 else if (job->getState() == BL::Job::PAUSED)
67 new_job_state = new QStandardItem("Paused");
68 else if (job->getState() == BL::Job::ERROR)
69 new_job_state = new QStandardItem("Error");
71 new_job_state = new QStandardItem("Finished");
73 QStandardItem * new_job_machine = new QStandardItem(job->getMachine().c_str());
75 int row = _model->rowCount();
76 _model->setItem(row, 0, new_job_name);
77 _model->setItem(row, 1, new_job_type);
78 _model->setItem(row, 2, new_job_state);
79 _model->setItem(row, 3, new_job_machine);
83 BL::QModelManager::job_state_changed(const QString & name)
85 DEBTRACE("BL::QModelManager::job_state_changed received");
87 BL::Job * job = _jobs_manager->getJob(name.toStdString());
88 QList<QStandardItem *> item_list = _model->findItems(name);
89 QStandardItem * job_state_item = _model->item(item_list.at(0)->row(), 2);
91 if (job->getState() == BL::Job::CREATED)
92 job_state_item->setText("Created");
93 else if (job->getState() == BL::Job::QUEUED)
94 job_state_item->setText("Queued");
95 else if (job->getState() == BL::Job::RUNNING)
96 job_state_item->setText("Running");
97 else if (job->getState() == BL::Job::PAUSED)
98 job_state_item->setText("Paused");
99 else if (job->getState() == BL::Job::ERROR)
100 job_state_item->setText("Error");
102 job_state_item->setText("Finished");
106 BL::QModelManager::deleteJob(int row)
108 _model->removeRow(row);
112 BL::QModelManager::job_selected(const QModelIndex & index)
114 DEBTRACE("BL::QModelManager::job_selected slot");
115 QStandardItem * item = _model->itemFromIndex(index);
116 int row = item->row();
118 // Algo un peu bourrin....
119 for (int i = 0; i < _model->rowCount(); i++)
120 for (int j = 0; j < _model->columnCount(); j++)
122 _model->item(i,j)->setBackground(QBrush(Qt::white));
123 _model->item(i,j)->setForeground(QBrush(Qt::black));
126 for (int j = 0; j < _model->columnCount(); j++)
128 _model->item(row,j)->setBackground(QBrush(Qt::darkBlue));
129 _model->item(row,j)->setForeground(QBrush(Qt::white));