Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
processManagerWidget.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 /*
52  * processManagerWidget.cc
53  *
54  * Created on: Apr 7, 2009
55  * Author: kremer
56  */
57 
58 #include "processManagerWidget.hh"
59 
60 void ProcessManagerWidget::updateStatus(QString _id, int _status) {
61 
62  QHash<QString, JobContainer>::iterator it = processMap_.find(_id);
63 
64  // No such item has been found -> returning
65  if(it == processMap_.end()) return;
66 
67  // Set new status
68  it.value().progress->setValue(_status);
69 }
70 
71 void ProcessManagerWidget::setJobName(QString _id, QString _name) {
72 
73  QHash<QString, JobContainer>::iterator it = processMap_.find(_id);
74 
75  // No such item has been found -> returning
76  if(it == processMap_.end()) return;
77 
78  it.value().id->setText(_name);
79 }
80 
81 void ProcessManagerWidget::setJobDescription(QString _id, QString _desc) {
82 
83  QHash<QString, JobContainer>::iterator it = processMap_.find(_id);
84 
85  // No such item has been found -> returning
86  if(it == processMap_.end()) return;
87 
88  // Set new description
89  it.value().description->setText(_desc);
90 }
91 
92 void ProcessManagerWidget::addJob(QString _id, QString _description,
93  int _minSteps, int _maxSteps) {
94 
95  // Item with the same id has already been added
96  if(processMap_.contains(_id)) return;
97 
98  QTableWidgetItem* name = new QTableWidgetItem(_id);
99  QTableWidgetItem* desc = new QTableWidgetItem(_description);
100  JobCancelButton* button = new JobCancelButton("Cancel", _id, this->processList);
101  QProgressBar* progressBar = new QProgressBar(this->processList);
102  progressBar->setMaximum(_maxSteps);
103  progressBar->setMinimum(_minSteps);
104  progressBar->setValue(0);
105  progressBar->setTextVisible(true);
106 
107  // Connect cancel button to event handler
108  connect(button, SIGNAL(pressed()), this, SLOT(cancelButtonPressed()));
109 
110  int newRow = this->processList->rowCount();
111 
112  this->processList->insertRow(newRow);
113 
114  this->processList->setItem(newRow, 0, name);
115  this->processList->setItem(newRow, 1, desc);
116  this->processList->setCellWidget(newRow, 2, progressBar);
117  this->processList->setCellWidget(newRow, 3, button);
118 
119  // Insert job into local map
120  JobContainer job;
121  job.id = name;
122  job.description = desc;
123  job.progress = progressBar;
124  job.button = button;
125 
126  processMap_.insert(_id, job);
127 }
128 
129 void ProcessManagerWidget::cancelButtonPressed() {
130 
131  // Get pushed button
132  JobCancelButton* button = 0;
133  button = dynamic_cast<JobCancelButton*>(QObject::sender());
134 
135  // Some error has occurred
136  if(button == 0) return;
137 
138  // Emit signal to cancel job
139  emit cancelJobRequested(button->jobId());
140 }
141 
142 void ProcessManagerWidget::removeJob(QString _id) {
143 
144  QHash<QString, JobContainer>::iterator it = processMap_.find(_id);
145 
146  // No such item has been found -> returning
147  if(it == processMap_.end()) return;
148 
149  processList->removeRow(processList->row(it.value().id));
150 
151  // Remove from local map
152  processMap_.erase(it);
153 }