fix(partition): add tolerance to add button enable condition#210
Conversation
There was a problem hiding this comment.
Sorry @GongHeng2017, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Add floating-point tolerance when comparing input value with remaining space to prevent disabling the add button due to precision error. 比较输入值与剩余空间时增加浮点容差,避免因精度误差错误禁用添加按钮。 Log: 修复添加按钮在边界值被错误禁用 PMS: BUG-364667 Influence: 修复后用户输入等于剩余空间时添加按钮可正常启用,提升分区创建交互体验。
dbecd46 to
03a5097
Compare
deepin pr auto review★ 总体评分:92分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 第16行:添加epsilon选值注释
constexpr double kFloatCompareEpsilon = 0.01; // 分区大小单位为GB,0.01GB容差覆盖浮点累积误差
// 第932-937行:修复后的onSetSliderValue关键逻辑
void PartitionWidget::onSetSliderValue()
{
// ...
m_block = 1;
// 缓存剩余空间,避免重复调用sumValue()并防止除零
const double remainingSpace = m_total - (sumValue() / 1024);
// 防止除零:剩余空间为0或负值时滑块置0
if (remainingSpace > kFloatCompareEpsilon) {
m_slider->setValue(static_cast<int>((value / remainingSpace) * 100));
} else {
m_slider->setValue(0);
}
m_currentEditSize = QString::number(value * 1024, 'f', 4);
// 统一使用epsilon进行浮点比较
if (value <= kFloatCompareEpsilon || value > remainingSpace + kFloatCompareEpsilon) {
qDebug() << "Value is 0 or exceeds remaining space, disabling addButton";
m_addButton->setEnabled(false);
} else {
// ...
}
} |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GongHeng2017, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
Add floating-point tolerance when comparing input value with remaining space to prevent disabling the add button due to precision error.
比较输入值与剩余空间时增加浮点容差,避免因精度误差错误禁用添加按钮。
Log: 修复添加按钮在边界值被错误禁用
PMS: BUG-364667
Influence: 修复后用户输入等于剩余空间时添加按钮可正常启用,提升分区创建交互体验。