-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathprogressdialog.cpp
127 lines (105 loc) · 3.75 KB
/
progressdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**********************************************************************
Copyright 2014-2016 The RIVET Developers. See the COPYRIGHT file at
the top-level directory of this distribution.
This file is part of RIVET.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************/
#include "progressdialog.h"
#include "ui_progressdialog.h"
#include <QCloseEvent>
#include <QDebug>
#include <QMessageBox>
#include <QtWidgets>
ProgressDialog::ProgressDialog(QWidget* parent)
: QDialog(parent)
, ui(new Ui::ProgressDialog)
, current_stage(1)
, stage_maximum(100)
, computation_finished(false)
{
ui->setupUi(this);
this->setWindowFlags(Qt::Window | Qt::WindowStaysOnTopHint);
stage_progress.push_back(0);
stage_progress.push_back(5); //we'll say that when the file is read we are 5% done,
stage_progress.push_back(15); // and when the bifiltration is built we are 15% done,
stage_progress.push_back(65); // and when the Betti numbers are computed we are 65% done
stage_progress.push_back(80); // and when the line arrangement is built we are 80% done
stage_progress.push_back(100); // and when the barcode templates are computed we are 100% done
}
ProgressDialog::~ProgressDialog()
{
delete ui;
}
void ProgressDialog::advanceToNextStage()
{
QLabel* prevLabel = getLabel(current_stage);
QFont font = prevLabel->font();
font.setBold(false);
prevLabel->setFont(font);
current_stage++;
//TODO: Why is this here? --Mike.
//stage_maximum = 100;
QLabel* nextLabel = getLabel(current_stage);
font.setBold(true);
nextLabel->setFont(font);
nextLabel->setEnabled(true);
ui->progressBar->setValue(stage_progress[current_stage - 1]);
}
void ProgressDialog::setStageMaximum(unsigned max)
{
stage_maximum = max;
}
void ProgressDialog::updateProgress(unsigned current)
{
double stage_percent = ((double)current) / stage_maximum;
int value = (int)(stage_percent * (stage_progress[current_stage] - stage_progress[current_stage - 1]) + stage_progress[current_stage - 1]);
ui->progressBar->setValue(value);
}
void ProgressDialog::setComputationFinished()
{
computation_finished = true;
close();
}
void ProgressDialog::closeEvent(QCloseEvent* event)
{
if (!computation_finished)
event->ignore();
else {
event->accept();
QWidget::closeEvent(event);
}
}
QLabel* ProgressDialog::getLabel(unsigned i)
{
if (i == 1)
return ui->step1description;
else if (i == 2)
return ui->step2description;
else if (i == 3)
return ui->step3description;
else if (i == 4)
return ui->step4description;
else
return ui->step5description;
}
void ProgressDialog::on_stopButton_clicked()
{
QMessageBox::StandardButton reallyStop;
reallyStop = QMessageBox::question(this, "Stop computation?", "Are you sure you want to stop the computation?", QMessageBox::Yes | QMessageBox::No);
if (reallyStop == QMessageBox::Yes) {
emit stopComputation();
computation_finished = true;
close();
qDebug() << "COMPUTATION INTERRUPTED BY USER";
qobject_cast<QWidget*>(this->parent())->close();
}
}