Use stringstream (general format) to format graph settings min/max

This commit is contained in:
Matt Cooley 2021-11-15 10:31:12 -08:00
commit 7d0a4de391
2 changed files with 37 additions and 66 deletions

View file

@ -3,11 +3,9 @@
#include "pch.h"
#include "GraphingSettingsViewModel.h"
#include <CalcManager\NumberFormattingUtils.h>
using namespace CalculatorApp::ViewModel;
using namespace CalculatorApp::ViewModel::Common;
using namespace CalcManager::NumberFormattingUtils;
using namespace GraphControl;
using namespace std;
using namespace Platform;
@ -55,21 +53,22 @@ void GraphingSettingsViewModel::InitRanges()
m_XMaxValue = xMax;
m_YMinValue = yMin;
m_YMaxValue = yMax;
auto valueStr = to_wstring(m_XMinValue);
TrimTrailingZeros(valueStr);
XMin = ref new String(valueStr.c_str());
valueStr = to_wstring(m_XMaxValue);
TrimTrailingZeros(valueStr);
XMax = ref new String(valueStr.c_str());
std::wostringstream xMinStr;
xMinStr << m_XMinValue;
XMin = ref new String(xMinStr.str().c_str());
valueStr = to_wstring(m_YMinValue);
TrimTrailingZeros(valueStr);
YMin = ref new String(valueStr.c_str());
std::wostringstream xMaxStr;
xMaxStr << m_XMaxValue;
XMax = ref new String(xMaxStr.str().c_str());
valueStr = to_wstring(m_YMaxValue);
TrimTrailingZeros(valueStr);
YMax = ref new String(valueStr.c_str());
std::wostringstream yMinStr;
yMinStr << m_YMinValue;
YMin = ref new String(yMinStr.str().c_str());
std::wostringstream yMaxStr;
yMaxStr << m_YMaxValue;
YMax = ref new String(yMaxStr.str().c_str());
m_dontUpdateDisplayRange = false;
}

View file

@ -51,21 +51,14 @@ namespace CalculatorApp::ViewModel
m_XIsMinLastChanged = true;
if (m_Graph != nullptr)
{
try
std::wistringstream input(value->Data());
double number;
if (input >> number)
{
size_t sz;
auto number = std::stod(value->Data(), &sz);
if (value->Length() == sz)
{
m_Graph->XAxisMin = m_XMinValue = number;
XMinError = false;
}
else
{
XMinError = true;
}
m_Graph->XAxisMin = m_XMinValue = number;
XMinError = false;
}
catch (...)
else
{
XMinError = true;
}
@ -92,21 +85,14 @@ namespace CalculatorApp::ViewModel
m_XIsMinLastChanged = false;
if (m_Graph != nullptr)
{
try
std::wistringstream input(value->Data());
double number;
if (input >> number)
{
size_t sz;
auto number = std::stod(value->Data(), &sz);
if (value->Length() == sz)
{
m_Graph->XAxisMax = m_XMaxValue = number;
XMaxError = false;
}
else
{
XMaxError = true;
}
m_Graph->XAxisMax = m_XMaxValue = number;
XMaxError = false;
}
catch (...)
else
{
XMaxError = true;
}
@ -133,21 +119,14 @@ namespace CalculatorApp::ViewModel
m_YIsMinLastChanged = true;
if (m_Graph != nullptr)
{
try
std::wistringstream input(value->Data());
double number;
if (input >> number)
{
size_t sz;
auto number = std::stod(value->Data(), &sz);
if (value->Length() == sz)
{
m_Graph->YAxisMin = m_YMinValue = number;
YMinError = false;
}
else
{
YMinError = true;
}
m_Graph->YAxisMin = m_YMinValue = number;
YMinError = false;
}
catch (...)
else
{
YMinError = true;
}
@ -174,21 +153,14 @@ namespace CalculatorApp::ViewModel
m_YIsMinLastChanged = false;
if (m_Graph != nullptr)
{
try
std::wistringstream input(value->Data());
double number;
if (input >> number)
{
size_t sz;
auto number = std::stod(value->Data(), &sz);
if (value->Length() == sz)
{
m_Graph->YAxisMax = m_YMaxValue = number;
YMaxError = false;
}
else
{
YMaxError = true;
}
m_Graph->YAxisMax = m_YMaxValue = number;
YMaxError = false;
}
catch (...)
else
{
YMaxError = true;
}