Change 'FormatDistance' declaration - return bool as is and string as reference.

This commit is contained in:
vng 2011-10-26 12:15:32 +03:00 committed by Alex Zolotarev
parent b552c8f95d
commit efd7129030
3 changed files with 17 additions and 16 deletions

View file

@ -6,24 +6,25 @@
namespace MeasurementUtils
{
string FormatDistanceImpl(double m, bool & drawDir,
bool FormatDistanceImpl(double m, string & res,
char const * high, char const * low, double highF, double lowF)
{
double const lowV = m / lowF;
drawDir = true;
if (lowV < 1.0)
{
drawDir = false;
return string("0") + low;
res = string("0") + low;
return false;
}
if (m >= highF)
return strings::to_string(m / highF) + high;
res = strings::to_string(m / highF) + high;
else
return strings::to_string(lowV) + low;
res = strings::to_string(lowV) + low;
return true;
}
string FormatDistance(double m, bool & drawDir)
bool FormatDistance(double m, string & res)
{
using namespace Settings;
Units u = Metric;
@ -31,9 +32,9 @@ string FormatDistance(double m, bool & drawDir)
switch (u)
{
case Yard: return FormatDistanceImpl(m, drawDir, " mi", " yd", 1609.344, 0.9144);
case Foot: return FormatDistanceImpl(m, drawDir, " mi", " ft", 1609.344, 0.3048);
default: return FormatDistanceImpl(m, drawDir, " km", " m", 1000.0, 1.0);
case Yard: return FormatDistanceImpl(m, res, " mi", " yd", 1609.344, 0.9144);
case Foot: return FormatDistanceImpl(m, res, " mi", " ft", 1609.344, 0.3048);
default: return FormatDistanceImpl(m, res, " km", " m", 1000.0, 1.0);
}
}

View file

@ -16,8 +16,8 @@ inline double YardToMiles(double yd) { return yd * 1760; }
/// Takes into an account user settings [metric, imperial]
/// @param[in] m meters
/// @param[out] drawDir should be direction arrow drawed? false if distance is < 1.0
/// @return formatted string for search
string FormatDistance(double m, bool & drawDir);
/// @param[out] res formatted string for search
/// @return should be direction arrow drawed? false if distance is to small (< 1.0)
bool FormatDistance(double m, string & res);
}

View file

@ -136,9 +136,9 @@ void SearchPanel::OnSearchResult(ResultT * res, int queryId)
m_pTable->setItem(rowCount, 0,
create_item(QString::fromUtf8(res->GetFetureTypeAsString().c_str())));
bool drawDir;
m_pTable->setItem(rowCount, 2,
create_item(MeasurementUtils::FormatDistance(res->GetDistanceFromCenter(), drawDir).c_str()));
string strDist;
bool const drawDir = MeasurementUtils::FormatDistance(res->GetDistanceFromCenter(), strDist);
m_pTable->setItem(rowCount, 2, create_item(strDist.c_str()));
if (drawDir)
{