Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenFlipper-Free
OpenFlipper
Commits
11ab0c00
Commit
11ab0c00
authored
Jan 06, 2017
by
Max Lyon
Browse files
add LessAnnoyingDoubleSpinBox
parent
7837c901
Changes
1
Hide whitespace changes
Inline
Side-by-side
widgets/spinBox/LessAnnoyingDoubleSpinBox.hh
0 → 100644
View file @
11ab0c00
//=============================================================================
//
// CLASS LessAnnoyingQDoubleSpinBox
//
//=============================================================================
#ifndef LESSANNOYINGDOUBLESPINBOX_HH
#define LESSANNOYINGDOUBLESPINBOX_HH
#include
<QDoubleSpinBox>
#include
<QWidget>
class
LessAnnoyingDoubleSpinBox
:
public
QDoubleSpinBox
{
public:
LessAnnoyingDoubleSpinBox
(
QWidget
*
_qwidget
=
Q_NULLPTR
)
:
QDoubleSpinBox
(
_qwidget
)
{
}
virtual
QValidator
::
State
validate
(
QString
&
text
,
int
&
)
const
override
{
QString
copy
=
strip_prefix_suffix
(
text
)
+
"0"
;
bool
ok
;
copy
.
toDouble
(
&
ok
);
if
(
ok
)
return
QValidator
::
Acceptable
;
else
return
QValidator
::
Invalid
;
}
virtual
double
valueFromText
(
const
QString
&
text
)
const
override
{
QString
copy
=
strip_prefix_suffix
(
text
);
bool
ok
;
double
value
=
copy
.
toDouble
(
&
ok
);
double
factor
=
pow
(
10.0
,
decimals
()
);
value
=
double
(
long
(
value
*
double
(
factor
)
+
0.5
)
)
/
factor
;
if
(
!
ok
)
return
0
;
return
value
;
}
private:
QString
strip_prefix_suffix
(
const
QString
&
text
)
const
{
int
lenpre
=
prefix
().
length
();
int
lensuf
=
suffix
().
length
();
return
text
.
mid
(
lenpre
,
text
.
length
()
-
lenpre
-
lensuf
).
simplified
();
}
};
//=============================================================================
#endif // LESSANNOYINGDOUBLESPINBOX_HH defined
//=============================================================================
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment