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

View file

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