Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
bd7e9ae6
Commit
bd7e9ae6
authored
6 months ago
by
Mikhail Svechnikov
Browse files
Options
Downloads
Patches
Plain Diff
add fixed step and rework adaptive step
parent
3047b058
No related branches found
No related tags found
1 merge request
!2728
Rework adaptive step in spinboxes (#875)
Pipeline
#163317
passed
6 months ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GUI/View/Numeric/DSpinBox.cpp
+24
-21
24 additions, 21 deletions
GUI/View/Numeric/DSpinBox.cpp
GUI/View/Numeric/DSpinBox.h
+0
-2
0 additions, 2 deletions
GUI/View/Numeric/DSpinBox.h
with
24 additions
and
23 deletions
GUI/View/Numeric/DSpinBox.cpp
+
24
−
21
View file @
bd7e9ae6
...
...
@@ -40,21 +40,25 @@ QString toString(double val, int decimal_points = 6)
"
\\
3
\\
5
\\
7"
);
}
int
orderOfMagnitude
(
double
x
)
{
if
(
x
==
0
)
return
0
;
return
std
::
floor
(
std
::
log10
(
std
::
abs
(
x
)));
}
}
// namespace
DSpinBox
::
DSpinBox
(
DoubleProperty
*
d
)
:
m_step
(
::
step0
)
{
replaceProperty
(
d
);
connect
(
this
,
&
QAbstractSpinBox
::
editingFinished
,
[
this
]
{
ASSERT
(
m_property
);
setValue
(
fromDisplay
());
m_old_dir
=
0
;
m_step
=
::
step0
;
});
// setSingleStep(m_property->step());
}
void
DSpinBox
::
replaceProperty
(
DoubleProperty
*
d
)
...
...
@@ -68,7 +72,6 @@ void DSpinBox::replaceProperty(DoubleProperty* d)
setSizePolicy
(
QSizePolicy
::
Minimum
,
QSizePolicy
::
Fixed
);
lineEdit
()
->
setText
(
toString
(
m_property
->
dVal
()));
connect
(
d
,
&
DoubleProperty
::
setAndNotifyCalled
,
this
,
&
DSpinBox
::
updateValue
);
// [this] { updateValue(); });
}
setReadOnly
(
!
m_property
);
updateValue
();
...
...
@@ -118,22 +121,22 @@ void DSpinBox::wheelEvent(QWheelEvent* event)
void
DSpinBox
::
stepBy
(
int
steps
)
{
ASSERT
(
m_property
);
const
double
val
=
m_property
->
dVal
();
const
int
new_dir
=
steps
>
0
?
+
1
:
-
1
;
if
(
m_old_dir
==
new_dir
)
m_step
=
std
::
min
(
m_step
*
(
std
::
abs
(
steps
)
==
1
?
1.2
:
2.
)
*
(
1
+
m_step
),
9.
);
else
if
(
m_old_dir
==
-
new_dir
)
m_step
=
std
::
abs
(
steps
)
==
1
?
std
::
max
(
m_step
/
9
,
1e-6
)
:
m_step
;
const
double
fac
=
(
steps
>
0
)
^
(
m_property
->
dVal
()
<
0
)
?
1
+
m_step
:
1
/
(
1
+
m_step
);
const
int
decimals
=
std
::
min
(
6
,
std
::
max
(
2
,
(
int
)(
2
-
std
::
log10
(
m_step
))));
// std::cout << "DEBUG steps=" << steps << " m_s=" << m_step << " fac=" << fac
// << " dec=" << decimals << " old=" << m_property->dVal()
// << " new=" << m_property->dVal() * fac
// << " rnd=" << Numeric::round_decimal(m_property->dVal() * fac, decimals)
// << std::endl;
setValue
(
Numeric
::
round_decimal
(
m_property
->
dVal
()
*
fac
,
decimals
));
if
(
m_property
->
limits
().
isLimited
())
{
setValue
(
val
+
m_property
->
step
()
*
steps
);
return
;
}
m_old_dir
=
new_dir
;
// "step digit" is the orger of magnitude of the step.
// If it is "1", then we increment/decrement the first digit of the value.
// If it is "2", then we increment/decrement the second digit of the value and so on.
const
int
step_digit
=
2
;
const
int
order_of_mag
=
::
orderOfMagnitude
(
val
);
// special cases: if the current value is 100 and step digit is 2, then the diminished value
// should be not 90, but 99.
const
int
correction
=
(
val
==
std
::
pow
(
10
,
order_of_mag
)
&&
steps
<
0
)
?
1
:
0
;
const
double
adaptive_step
=
std
::
pow
(
10
,
order_of_mag
-
step_digit
-
correction
+
1
);
const
double
step
=
(
val
==
0
)
?
::
step0
:
adaptive_step
;
setValue
(
val
+
step
*
steps
);
}
This diff is collapsed.
Click to expand it.
GUI/View/Numeric/DSpinBox.h
+
0
−
2
View file @
bd7e9ae6
...
...
@@ -50,8 +50,6 @@ private:
void
stepBy
(
int
steps
)
override
;
DoubleProperty
*
m_property
;
int
m_old_dir
=
0
;
double
m_step
;
};
#endif // BORNAGAIN_GUI_VIEW_NUMERIC_DSPINBOX_H
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment