src/utilities/plot/ProgressBar.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #include "ProgressBar.hpp" | ||
| 7 | |||
| 8 | #include <cmath> | ||
| 9 | #include <nano/nano_signal_slot.hpp> | ||
| 10 | |||
| 11 | namespace openstudio { | ||
| 12 | |||
| 13 | /// constructor | ||
| 14 | ✗ | ProgressBar::ProgressBar() : m_percentage(0.0) {} | |
| 15 | |||
| 16 | /// virtual destructor | ||
| 17 | |||
| 18 | /// virtual method called every time progressUpdated fires | ||
| 19 | ✗ | void ProgressBar::onPercentageUpdated(double percentage) {} | |
| 20 | |||
| 21 | ✗ | void ProgressBar::updatePercentage() { | |
| 22 | ✗ | double value = this->value(); | |
| 23 | ✗ | double max = this->maximum(); | |
| 24 | ✗ | double min = this->minimum(); | |
| 25 | ✗ | double range = max - min; | |
| 26 | |||
| 27 | ✗ | double newPercentage = 0.0; | |
| 28 | ✗ | if (range > 0.0) { | |
| 29 | ✗ | newPercentage = 100.0 * (value - min) / range; | |
| 30 | } | ||
| 31 | |||
| 32 | ✗ | if (std::fabs(newPercentage - m_percentage) >= 1.0) { | |
| 33 | ✗ | m_percentage = newPercentage; | |
| 34 | ✗ | this->percentageUpdated.nano_emit(m_percentage); | |
| 35 | ✗ | onPercentageUpdated(m_percentage); | |
| 36 | } | ||
| 37 | ✗ | } | |
| 38 | |||
| 39 | } // namespace openstudio | ||
| 40 |