00001
00002
00003
00004
00005
00006
00007 #include "DocumentModelGeneral.h"
00008 #include "EngaugeAssert.h"
00009 #include "FormatCoordsUnitsStrategyNonPolarTheta.h"
00010 #include "FormatDateTime.h"
00011 #include "FormatDegreesMinutesSecondsNonPolarTheta.h"
00012 #include "Logger.h"
00013 #include <QLocale>
00014 #include "Transformation.h"
00015
00016 FormatCoordsUnitsStrategyNonPolarTheta::FormatCoordsUnitsStrategyNonPolarTheta ()
00017 {
00018 }
00019
00020 double FormatCoordsUnitsStrategyNonPolarTheta::formattedToUnformatted (const QString &string,
00021 const QLocale &locale,
00022 CoordUnitsNonPolarTheta coordUnits,
00023 CoordUnitsDate coordUnitsDate,
00024 CoordUnitsTime coordUnitsTime) const
00025 {
00026 LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyNonPolarTheta::formattedToUnformatted";
00027
00028 double value;
00029
00030 switch (coordUnits) {
00031 case COORD_UNITS_NON_POLAR_THETA_DATE_TIME:
00032 {
00033 FormatDateTime format;
00034 ENGAUGE_ASSERT (format.parseInput (coordUnitsDate,
00035 coordUnitsTime,
00036 string,
00037 value) == QValidator::Acceptable);
00038 }
00039 break;
00040
00041 case COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS:
00042 case COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
00043 {
00044 FormatDegreesMinutesSecondsNonPolarTheta format;
00045 ENGAUGE_ASSERT (format.parseInput (string,
00046 value) == QValidator::Acceptable);
00047 }
00048 break;
00049
00050 case COORD_UNITS_NON_POLAR_THETA_NUMBER:
00051 value = locale.toDouble (string);
00052 break;
00053
00054 default:
00055 LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyNonPolarTheta::formattedToFormatted";
00056 ENGAUGE_ASSERT (false);
00057 break;
00058 }
00059
00060 return value;
00061 }
00062
00063 QString FormatCoordsUnitsStrategyNonPolarTheta::unformattedToFormatted (double valueUnformatted,
00064 const QLocale &locale,
00065 CoordUnitsNonPolarTheta coordUnits,
00066 CoordUnitsDate coordUnitsDate,
00067 CoordUnitsTime coordUnitsTime,
00068 bool isXTheta,
00069 const DocumentModelGeneral &modelGeneral,
00070 const Transformation &transformation,
00071 double valueUnformattedOther) const
00072 {
00073 LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyNonPolarTheta::unformattedToFormatted";
00074
00075 const char FORMAT ('g');
00076
00077 QString valueFormatted;
00078
00079 switch (coordUnits) {
00080 case COORD_UNITS_NON_POLAR_THETA_DATE_TIME:
00081 {
00082 FormatDateTime format;
00083 valueFormatted = format.formatOutput (coordUnitsDate,
00084 coordUnitsTime,
00085 valueUnformatted);
00086 }
00087 break;
00088
00089 case COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS:
00090 case COORD_UNITS_NON_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
00091 {
00092 FormatDegreesMinutesSecondsNonPolarTheta format;
00093 valueFormatted = format.formatOutput (coordUnits,
00094 valueUnformatted,
00095 isXTheta);
00096 }
00097 break;
00098
00099 case COORD_UNITS_NON_POLAR_THETA_NUMBER:
00100 valueFormatted = locale.toString (valueUnformatted,
00101 FORMAT,
00102 precisionDigitsForRawNumber (valueUnformatted,
00103 valueUnformattedOther,
00104 isXTheta,
00105 modelGeneral,
00106 transformation));
00107 break;
00108
00109 default:
00110 LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyNonPolarTheta::unformattedToFormatted";
00111 ENGAUGE_ASSERT (false);
00112 break;
00113 }
00114
00115 return valueFormatted;
00116 }