Developer Documentation

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 #include "processManagerWidget.hh"
44
45 void ProcessManagerWidget::updateStatus(QString _id, int _status) {
46
47 QHash<QString, JobContainer>::iterator it = processMap_.find(_id);
48
49 // No such item has been found -> returning
50 if(it == processMap_.end()) return;
51
52 // Set new status
53 it.value().progress->setValue(_status);
54 }
55
56 void ProcessManagerWidget::setJobName(QString _id, QString _name) {
57
58 QHash<QString, JobContainer>::iterator it = processMap_.find(_id);
59
60 // No such item has been found -> returning
61 if(it == processMap_.end()) return;
62
63 it.value().id->setText(_name);
64 }
65
66 void ProcessManagerWidget::setJobDescription(QString _id, QString _desc) {
67
68 QHash<QString, JobContainer>::iterator it = processMap_.find(_id);
69
70 // No such item has been found -> returning
71 if(it == processMap_.end()) return;
72
73 // Set new description
74 it.value().description->setText(_desc);
75 }
76
77 void ProcessManagerWidget::addJob(QString _id, QString _description,
78 int _minSteps, int _maxSteps) {
79
80 // Item with the same id has already been added
81 if(processMap_.contains(_id)) return;
82
83 QTableWidgetItem* name = new QTableWidgetItem(_id);
84 QTableWidgetItem* desc = new QTableWidgetItem(_description);
85 JobCancelButton* button = new JobCancelButton("Cancel", _id, this->processList);
86 QProgressBar* progressBar = new QProgressBar(this->processList);
87 progressBar->setMaximum(_maxSteps);
88 progressBar->setMinimum(_minSteps);
89 progressBar->setValue(0);
90 progressBar->setTextVisible(true);
91
92 // Connect cancel button to event handler
93 connect(button, SIGNAL(pressed()), this, SLOT(cancelButtonPressed()));
94
95 int newRow = this->processList->rowCount();
96
97 this->processList->insertRow(newRow);
98
99 this->processList->setItem(newRow, 0, name);
100 this->processList->setItem(newRow, 1, desc);
101 this->processList->setCellWidget(newRow, 2, progressBar);
102 this->processList->setCellWidget(newRow, 3, button);
103
104 // Insert job into local map
105 JobContainer job;
106 job.id = name;
107 job.description = desc;
108 job.progress = progressBar;
109 job.button = button;
110
111 processMap_.insert(_id, job);
112 }
113
114 void ProcessManagerWidget::cancelButtonPressed() {
115
116 // Get pushed button
117 JobCancelButton* button = 0;
118 button = dynamic_cast<JobCancelButton*>(QObject::sender());
119
120 // Some error has occurred
121 if(button == 0) return;
122
123 // Emit signal to cancel job
124 emit cancelJobRequested(button->jobId());
125 }
126
127 void ProcessManagerWidget::removeJob(QString _id) {
128
129 QHash<QString, JobContainer>::iterator it = processMap_.find(_id);
130
131 // No such item has been found -> returning
132 if(it == processMap_.end()) return;
133
134 processList->removeRow(processList->row(it.value().id));
135
136 // Remove from local map
137 processMap_.erase(it);
138 }
JobCancelButton
Definition: processManagerWidget.hh:53