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

UnitConverter: Automatically flip units when users set one to the same type than the other #375

Closed
wants to merge 3 commits into from

Conversation

rudyhuyn
Copy link
Contributor

Fixes #266

Description of the changes:

  • replace OBSERVABLE_PROPERTY_RW for Unit1 and Unit2 by custom code.
  • verify if the new value of Unit1 is equals to the current value of Unit2, if it's the case, set Unit2 to the former value of Unit1.
  • add unit tests (and adapt existing ones)
  • [NIT optimization] replace Unit1 and Unit2 by m_Unit1 and m_Unit2 when possible

How changes were validated:

  • Manually tested + unit tests

@microsoft microsoft locked and limited conversation to collaborators Mar 25, 2019
@HowardWolosky
Copy link
Member

Locking the PR since the associated Issue isn't approved yet. That way conversation on the problem being addressed is discussed in the Issue, so that future PR discussion can be limited to the implementation of the fix.

joseartrivera
joseartrivera previously approved these changes Sep 26, 2019
Copy link
Contributor

@joseartrivera joseartrivera left a comment

Choose a reason for hiding this comment

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

Thanks Rudy! Code works great, sorry for not getting to this earlier. Merge conflicts were not too bad, I can help work them out if needed. Overall looks good, left a few nit comments.

@rudyhuyn
Copy link
Contributor Author

rebase done

@rudyhuyn rudyhuyn reopened this Sep 26, 2019
Copy link
Contributor

@joseartrivera joseartrivera left a comment

Choose a reason for hiding this comment

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

Minor comments after the merge.

src/CalcViewModel/UnitConverterViewModel.h Outdated Show resolved Hide resolved
src/CalcViewModel/UnitConverterViewModel.cpp Show resolved Hide resolved
@ghost ghost added the no recent activity label Oct 4, 2019
@ghost
Copy link

ghost commented Oct 4, 2019

This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. Thank you for your contributions to Windows Calculator!

@HowardWolosky HowardWolosky removed their assignment Dec 3, 2019
@ghost ghost removed the no recent activity label Dec 3, 2019
@ghost ghost added the no recent activity label Dec 10, 2019
@ghost
Copy link

ghost commented Dec 10, 2019

This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. Thank you for your contributions to Windows Calculator!

if ((m_valueFromUnlocalized != m_lastAnnouncedFrom
|| m_valueToUnlocalized != m_lastAnnouncedTo)
&& m_Unit1 != nullptr
&& m_Unit2 != nullptr)
Copy link
Contributor

Choose a reason for hiding this comment

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

the method header mentions a validation against zero as well, does zero need to be added as a conditional to the if?

{
m_lastAnnouncedFrom = m_valueFromUnlocalized;
m_lastAnnouncedTo = m_valueToUnlocalized;

Unit ^ unitFrom = Value1Active ? Unit1 : Unit2;
Unit ^ unitTo = (unitFrom == Unit1) ? Unit2 : Unit1;
Unit^ unitFrom = Value1Active ? m_Unit1 : m_Unit2;
Copy link
Contributor

@quentin987 quentin987 May 7, 2020

Choose a reason for hiding this comment

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

nit: Could be out of scope but m_Unit1 and m_Unit2 don't feel like very descriptive variable names. New to the codebase so could be wrong though. Feel like something that better describes the unit may be better suited versus just numbering them.

{
auto formerValue = m_Unit1;
m_Unit1 = value;
//Be sure m_Unit1 is set before setting Unit2
Copy link
Contributor

@quentin987 quentin987 May 7, 2020

Choose a reason for hiding this comment

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

Why is this validation the case? Is there some sequential logic that fires with setting these in a certain order? An extra comment line giving more context might be helpful.

{
auto formerValue = m_Unit2;
m_Unit2 = value;
//Be sure m_Unit2 is set before setting Unit1
Copy link
Contributor

Choose a reason for hiding this comment

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

similar thought here

{
m_lastAnnouncedFrom = m_valueFromUnlocalized;
m_lastAnnouncedTo = m_valueToUnlocalized;

Unit ^ unitFrom = Value1Active ? Unit1 : Unit2;
Unit ^ unitTo = (unitFrom == Unit1) ? Unit2 : Unit1;
Unit^ unitFrom = Value1Active ? m_Unit1 : m_Unit2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Very cool that you can do null coalescing in cpp!!

@@ -284,6 +284,8 @@ for (unsigned int k = 0; k < categoryList->Size; k++)
wstring unit1Name = vm->Unit1->Name->Data();
for (unsigned int j = 0; j < unitList->Size; j++)
{
if (i == j)
Copy link
Contributor

Choose a reason for hiding this comment

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

a comment might help with understanding why i == j is a skip condition in this loop

Copy link
Contributor

@quentin987 quentin987 left a comment

Choose a reason for hiding this comment

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

Good stuff! Added some comments.

@sanderl
Copy link
Contributor

sanderl commented Jul 1, 2021

We're converting Calculator to C# with a PR for the conversion coming in the next few days, so we're going to close this PR. If you want to revisit the issue, please open a new PR after the conversion has completed.

@sanderl sanderl closed this Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Converter doesn't automatically flip from & to fields during conversion
6 participants