CCIMXDesktop
 
Loading...
Searching...
No Matches
BoundProgressBarFactory.hpp
1#ifndef BOUNDPROGRESSBARFACTORY_H
2#define BOUNDPROGRESSBARFACTORY_H
3
4#include "library/limited_value/ValueLimiter.hpp"
5#include <QObject>
6#include <QSlider>
7
20template <ValueLimitType default_value, ValueLimitType min = 0, ValueLimitType max = 100>
21class BoundSliderFactory : public QObject {
22 static_assert(ValueLimitUtils::inBound(default_value, { min, max }),
23 "Default Value is MisMatch");
24
25public:
31 explicit BoundSliderFactory(QSlider* barWidget, QObject* parent = nullptr)
32 : QObject(parent)
33 , monitoring_bar(barWidget) {
34 monitoring_bar->setMaximum(max);
35 monitoring_bar->setMinimum(min);
37 connect(monitoring_bar, &QSlider::valueChanged, this, [this](int value) {
38 _plain_set_value(value);
39 });
40 }
41
46 inline int queryValue() const { return current_value; }
47
52 void inline setValue(int value) {
53 _plain_set_value(value);
55 }
56
57protected:
67
68 int current_value { default_value };
69 QSlider* monitoring_bar;
70};
71
72#endif // BOUNDPROGRESSBARFACTORY_H
Factory class for creating bounded QSlider widgets.
Definition BoundProgressBarFactory.hpp:21
BoundSliderFactory(QSlider *barWidget, QObject *parent=nullptr)
Constructs a BoundSliderFactory instance.
Definition BoundProgressBarFactory.hpp:31
QSlider * monitoring_bar
Definition BoundProgressBarFactory.hpp:69
int queryValue() const
Gets the current slider value.
Definition BoundProgressBarFactory.hpp:46
void setValue(int value)
Sets the slider value (with bounds enforcement)
Definition BoundProgressBarFactory.hpp:52
int current_value
Definition BoundProgressBarFactory.hpp:68
virtual void _plain_set_value(int value)
Internal method for setting values with bounds checking.
Definition BoundProgressBarFactory.hpp:64
static constexpr ValueLimitType boundValue(ValueLimitType value)
Clamps a value to the static bounds.
Definition ValueLimiter.hpp:78
constexpr bool inBound(ValueLimitType value, ValueLimitSimplePair p)
Checks if a value is within bounds.
Definition ValueLimiter.hpp:40