mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
Rename variables and add comments around why checking if units alredy have values.
This commit is contained in:
parent
f049b4a3ee
commit
9a7defdd06
1 changed files with 7 additions and 5 deletions
|
@ -922,10 +922,12 @@ void UnitConverter::InitializeSelectedUnits()
|
||||||
vector<Unit> curUnits = itr->second;
|
vector<Unit> curUnits = itr->second;
|
||||||
if (!curUnits.empty())
|
if (!curUnits.empty())
|
||||||
{
|
{
|
||||||
bool isFromRestored = find(curUnits.begin(), curUnits.end(), m_fromType) != curUnits.end();
|
// Units may already have been initialized through UnitConverter::RestoreUserPreferences().
|
||||||
bool isToRestored = find(curUnits.begin(), curUnits.end(), m_toType) != curUnits.end();
|
// Check if they have been, and if so, do not override restored units.
|
||||||
|
bool isFromUnitValid = find(curUnits.begin(), curUnits.end(), m_fromType) != curUnits.end();
|
||||||
|
bool isToUnitValid = find(curUnits.begin(), curUnits.end(), m_toType) != curUnits.end();
|
||||||
|
|
||||||
if (isFromRestored && isToRestored)
|
if (isFromUnitValid && isToUnitValid)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -934,13 +936,13 @@ void UnitConverter::InitializeSelectedUnits()
|
||||||
bool conversionTargetSet = false;
|
bool conversionTargetSet = false;
|
||||||
for (const Unit& cur : curUnits)
|
for (const Unit& cur : curUnits)
|
||||||
{
|
{
|
||||||
if (!conversionSourceSet && cur.isConversionSource && !isFromRestored)
|
if (!conversionSourceSet && cur.isConversionSource && !isFromUnitValid)
|
||||||
{
|
{
|
||||||
m_fromType = cur;
|
m_fromType = cur;
|
||||||
conversionSourceSet = true;
|
conversionSourceSet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!conversionTargetSet && cur.isConversionTarget && !isToRestored)
|
if (!conversionTargetSet && cur.isConversionTarget && !isToUnitValid)
|
||||||
{
|
{
|
||||||
m_toType = cur;
|
m_toType = cur;
|
||||||
conversionTargetSet = true;
|
conversionTargetSet = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue