Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spinboxes now correct when rounding. #6748

Conversation

jjjoness
Copy link
Contributor

@jjjoness jjjoness commented Jan 7, 2022

Signed-off-by: John Jones-Steele 82226755+jjjoness@users.noreply.github.com
Fixes #5298
spinbox

Signed-off-by: John Jones-Steele <82226755+jjjoness@users.noreply.github.com>
@jjjoness jjjoness requested review from hultonha and a team January 7, 2022 15:26
Copy link
Contributor

@AMZN-daimini AMZN-daimini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this also be used on sliders to ensure the input and the tooltip display the same value?

@jjjoness
Copy link
Contributor Author

jjjoness commented Jan 7, 2022

@AMZN-daimini I'll have a look and see. I'll create a PR if it can.

Copy link
Contributor

@hultonha hultonha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good I just have a small number of questions/comments. I can approve after that as nothing is super blocking but might be worth doing another pass to simplify things if possible.

QString retValue = locale.toString(value, 'f', (numDecimals > 0) ? numToStringDecimals : 0);
// If we want to truncate, not round, we add extra decimal places to the formatting
// so we can remove the last values otherwise we allow rounding
QString retValue = locale.toString(value, 'f', (numDecimals > 0) ? (truncate ? numToStringDecimals : numDecimals) : 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Could we replace the nested ternary statement here with an if statement (or immediately invoked lambda) It just gets pretty hard to parse as it is right now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legend, thanks 🙂

@@ -1460,7 +1460,7 @@ QString DoubleSpinBox::stringValue(double value, bool truncated) const
numDecimals = 0;
}

return toString(value, numDecimals, locale(), isGroupSeparatorShown());
return toString(value, numDecimals, locale(), isGroupSeparatorShown(), false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: This is likely intended it just seems odd on first glance that we don't pass the truncated parameter on line 1450 through to this call here. Are they different kind of truncation? Could the logic here be simplified if we just pass the bool through to toString?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are different. The value passed in means to either truncate to the number of decimals of to the numberofDisplayDecimals. I've reworked the logic so the term to pass is the round bool.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay nice one, and thanks for the explanation 👍

@@ -39,15 +39,15 @@ namespace AzQtComponents
return AZ::Color(static_cast<float>(rgb.redF()), static_cast<float>(rgb.greenF()), static_cast<float>(rgb.blueF()), static_cast<float>(rgb.alphaF()));
}

QString toString(double value, int numDecimals, const QLocale& locale, bool showGroupSeparator)
QString toString(double value, int numDecimals, const QLocale& locale, bool showGroupSeparator, bool truncate)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: It might be useful to have a couple of quick sanity tests for this function to ensure we get the expected value. They could be really simple functions with no fixture, there should hopefully be a place for them in AzQtComponents I'd have thought. Could be a separate PR but would be great to capture the expected behavior of this function given various inputs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done😀

Signed-off-by: John Jones-Steele <82226755+jjjoness@users.noreply.github.com>
@jjjoness jjjoness requested a review from hultonha January 7, 2022 16:39
…igits-o3de#5298

Signed-off-by: John Jones-Steele <82226755+jjjoness@users.noreply.github.com>
Copy link
Contributor

@hultonha hultonha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 😄 Thanks for making the various updates, much appreciated 👍

Comment on lines +40 to +52
TEST(AzQtComponents, ToStringReturnsTruncatedString)
{
double testVal = 1.2399999;
QString result = AzQtComponents::toString(testVal, 3, QLocale(), false, false);
EXPECT_TRUE(result == "1.239");
}

TEST(AzQtComponents, ToStringReturnsRoundedString)
{
double testVal = 1.2399999;
QString result = AzQtComponents::toString(testVal, 3, QLocale(), false, true);
EXPECT_TRUE(result == "1.24");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! 😄 Thanks for adding these 🙂

Signed-off-by: John Jones-Steele <82226755+jjjoness@users.noreply.github.com>
@jjjoness jjjoness merged commit 7c88f20 into o3de:development Jan 10, 2022
@jjjoness jjjoness deleted the GridSnappingAndAngleSnappingNotExactDigits-#5298 branch January 10, 2022 11:49
burelc-amzn pushed a commit to aws-lumberyard-dev/o3de that referenced this pull request Jan 13, 2022
* Spinboxes now correct when rounding.

Signed-off-by: John Jones-Steele <82226755+jjjoness@users.noreply.github.com>

* Changes from PR

Signed-off-by: John Jones-Steele <82226755+jjjoness@users.noreply.github.com>

* Fixed tests after change to rounding in spinbox

Signed-off-by: John Jones-Steele <82226755+jjjoness@users.noreply.github.com>
Signed-off-by: Chris Burel <burelc@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[GNU/LINUX] Grid snapping and angle snapping not exact digits
3 participants