Radium Engine  1.5.20
Loading...
Searching...
No Matches
ConstrainedNumericSpinBox.hpp
1#pragma once
2#include <Gui/RaGui.hpp>
3
4#include <QWidget>
5
6#include <Gui/Widgets/QtTypeWrapper.hpp>
7
8namespace Ra {
9namespace Gui {
10namespace Widgets {
11
17template <typename T>
18class ConstrainedNumericSpinBox : public QtSpinBox::getType<T>::Type
19{
20 public:
21 using BaseWidget = typename QtSpinBox::getType<T>::Type;
22 using Predicate = std::function<bool( T )>;
23 using BaseWidget::BaseWidget;
24 QValidator::State validate( QString& input, int& ) const override;
25
27 inline void setPredicate( Predicate p ) { m_p = p; }
33 inline bool isValid( T s ) const { return m_p( s ); }
34
35 private:
36 Predicate m_p = []( T ) { return true; };
37};
38
39template <typename T>
40QValidator::State ConstrainedNumericSpinBox<T>::validate( QString& input, int& ) const {
41 auto valid = this->isValid( this->valueFromText( input ) );
42 auto& spin = const_cast<ConstrainedNumericSpinBox&>( *this );
43 spin.blockSignals( !valid );
44 if ( valid ) { spin.setStyleSheet( "" ); }
45 else { spin.setStyleSheet( "background-color: #FF8080" ); }
46 return valid ? QValidator::Acceptable : QValidator::Invalid;
47}
48
49} // namespace Widgets
50} // namespace Gui
51} // namespace Ra
Constrained input spin box. The constraint to apply to any input value is verified using the user-def...
void setPredicate(Predicate p)
Set the predicate to evaluate.
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3