50 #include <QProgressDialog> 86 Progress(
double maxProgress = 1.0) : parent(0), maxProgress(maxProgress), currentProgress(0.0), dialog_padding(0)
89 if (parent) parent->childGoesBye(
this);
92 void setMaxProgress(
double value) {
94 if (currentProgress != 0.0) progressChanged();
98 void connectToDialog(QProgressDialog *dlg) {
100 dialog->setMaximum(100000);
109 return getProgress() / maxProgress;
112 double getProgress()
const {
113 double result = currentProgress;
118 for (std::set<ChildRecord>::const_iterator it = children.begin(); it != children.end(); ++it) {
119 result += it->child->getNormalizedProgress() * it->contribution;
122 return std::min(maxProgress, result);
129 progress->parent =
this;
134 children.insert(
ChildRecord(progress, contribution));
137 void increment(
double amount) {
138 currentProgress += amount;
147 inline void progressChanged() {
148 if (parent) parent->onChildProgress(
this);
152 inline void updateDialog() {
159 inline void childGoesBye(
Progress *child) {
163 std::set<ChildRecord>::iterator it = children.find(
ChildRecord(child, 0));
164 currentProgress += it->contribution;
174 ChildRecord(
Progress *child,
double contribution) : child(child), contribution(contribution) {}
176 bool operator==(
const ChildRecord &rhs)
const {
return child == rhs.child; }
177 bool operator<(
const ChildRecord &rhs)
const {
return child < rhs.child; }
182 std::set<ChildRecord> children;
184 double maxProgress, currentProgress;
188 QProgressDialog *dialog;
194 void *dialog_padding;
Namespace providing different geometric functions concerning angles.
double getNormalizedProgress() const
void addSubProgress(Progress *progress, double contribution)