[TechDraw] Improve DimensionFormatter.cpp typing
Make type safe by using const keywords when appropriate and improve memory handling by using references when appropriate.
This commit is contained in:
committed by
WandererFan
parent
bef32983b0
commit
09f1c2ded7
@@ -51,14 +51,15 @@ bool DimensionFormatter::isMultiValueSchema() const
|
||||
return false;
|
||||
}
|
||||
|
||||
// Todo: make this enum
|
||||
//partial = 0 return the unaltered user string from the Units subsystem
|
||||
//partial = 1 return value formatted according to the format spec and preferences for
|
||||
// useAltDecimals and showUnits
|
||||
//partial = 2 return only the unit of measure
|
||||
std::string DimensionFormatter::formatValue(qreal value,
|
||||
QString qFormatSpec,
|
||||
int partial,
|
||||
bool isDim)
|
||||
std::string DimensionFormatter::formatValue(const qreal value,
|
||||
const QString& qFormatSpec,
|
||||
const int partial,
|
||||
const bool isDim) const
|
||||
{
|
||||
// Base::Console().Message("DF::formatValue() - %s isRestoring: %d\n",
|
||||
// m_dimension->getNameInDocument(), m_dimension->isRestoring());
|
||||
@@ -190,7 +191,7 @@ std::string DimensionFormatter::formatValue(qreal value,
|
||||
return formattedValueString;
|
||||
}
|
||||
|
||||
std::string DimensionFormatter::getFormattedToleranceValue(int partial)
|
||||
std::string DimensionFormatter::getFormattedToleranceValue(const int partial) const
|
||||
{
|
||||
QString FormatSpec = QString::fromUtf8(m_dimension->FormatSpecOverTolerance.getStrValue().data());
|
||||
QString ToleranceString;
|
||||
@@ -207,7 +208,7 @@ std::string DimensionFormatter::getFormattedToleranceValue(int partial)
|
||||
}
|
||||
|
||||
//get over and under tolerances
|
||||
std::pair<std::string, std::string> DimensionFormatter::getFormattedToleranceValues(int partial)
|
||||
std::pair<std::string, std::string> DimensionFormatter::getFormattedToleranceValues(const int partial) const
|
||||
{
|
||||
QString underFormatSpec = QString::fromUtf8(m_dimension->FormatSpecUnderTolerance.getStrValue().data());
|
||||
QString overFormatSpec = QString::fromUtf8(m_dimension->FormatSpecOverTolerance.getStrValue().data());
|
||||
@@ -251,7 +252,7 @@ std::pair<std::string, std::string> DimensionFormatter::getFormattedToleranceVal
|
||||
}
|
||||
|
||||
//partial = 2 unit only
|
||||
std::string DimensionFormatter::getFormattedDimensionValue(int partial)
|
||||
std::string DimensionFormatter::getFormattedDimensionValue(const int partial) const
|
||||
{
|
||||
QString qFormatSpec = QString::fromUtf8(m_dimension->FormatSpec.getStrValue().data());
|
||||
|
||||
@@ -308,7 +309,7 @@ std::string DimensionFormatter::getFormattedDimensionValue(int partial)
|
||||
|
||||
// format the value using the formatSpec. Also, handle the non-standard format-
|
||||
// specifier '%w', which has the following rules: works as %f, but no trailing zeros
|
||||
QString DimensionFormatter::formatValueToSpec(double value, QString formatSpecifier)
|
||||
QString DimensionFormatter::formatValueToSpec(const double value, const QString& formatSpecifier) const
|
||||
{
|
||||
QString formattedValue;
|
||||
if (formatSpecifier.contains(QRegularExpression(QStringLiteral("%.*[wW]")))) {
|
||||
@@ -329,7 +330,7 @@ QString DimensionFormatter::formatValueToSpec(double value, QString formatSpecif
|
||||
return formattedValue;
|
||||
}
|
||||
|
||||
bool DimensionFormatter::isNumericFormat(QString formatSpecifier)
|
||||
bool DimensionFormatter::isNumericFormat(const QString& formatSpecifier) const
|
||||
{
|
||||
QRegularExpression rxFormat(QStringLiteral("%[+-]?[0-9]*\\.*[0-9]*[aefgwAEFGW]")); //printf double format spec
|
||||
QRegularExpressionMatch rxMatch;
|
||||
@@ -341,7 +342,7 @@ bool DimensionFormatter::isNumericFormat(QString formatSpecifier)
|
||||
}
|
||||
|
||||
//TODO: similar code here and above
|
||||
QStringList DimensionFormatter::getPrefixSuffixSpec(QString fSpec)
|
||||
QStringList DimensionFormatter::getPrefixSuffixSpec(const QString& fSpec) const
|
||||
{
|
||||
QStringList result;
|
||||
//find the %x.y tag in FormatSpec
|
||||
@@ -404,7 +405,7 @@ std::string DimensionFormatter::getDefaultFormatSpec(bool isToleranceFormat) con
|
||||
}
|
||||
|
||||
//true if value is too small to display using formatSpec
|
||||
bool DimensionFormatter::isTooSmall(double value, QString formatSpec)
|
||||
bool DimensionFormatter::isTooSmall(const double value, const QString& formatSpec) const
|
||||
{
|
||||
if (TechDraw::DrawUtil::fpCompare(value, 0.0)) {
|
||||
//zero values always fit, so it isn't too small
|
||||
|
||||
@@ -38,18 +38,18 @@ public:
|
||||
|
||||
void setDimension(DrawViewDimension* dim) { m_dimension = dim; }
|
||||
bool isMultiValueSchema() const;
|
||||
std::string formatValue(qreal value,
|
||||
QString qFormatSpec,
|
||||
int partial,
|
||||
bool isDim);
|
||||
std::string getFormattedToleranceValue(int partial);
|
||||
std::pair<std::string, std::string> getFormattedToleranceValues(int partial);
|
||||
std::string getFormattedDimensionValue(int partial);
|
||||
QStringList getPrefixSuffixSpec(QString fSpec);
|
||||
std::string formatValue(const qreal value,
|
||||
const QString& qFormatSpec,
|
||||
const int partial,
|
||||
const bool isDim) const;
|
||||
std::string getFormattedToleranceValue(const int partial) const;
|
||||
std::pair<std::string, std::string> getFormattedToleranceValues(const int partial) const;
|
||||
std::string getFormattedDimensionValue(const int partial) const;
|
||||
QStringList getPrefixSuffixSpec(const QString& fSpec) const;
|
||||
std::string getDefaultFormatSpec(bool isToleranceFormat) const;
|
||||
bool isTooSmall(double value, QString formatSpec);
|
||||
QString formatValueToSpec(double value, QString formatSpecifier);
|
||||
bool isNumericFormat(QString formatSpecifier);
|
||||
bool isTooSmall(const double value, const QString& formatSpec) const;
|
||||
QString formatValueToSpec(const double value, const QString& formatSpecifier) const;
|
||||
bool isNumericFormat(const QString& formatSpecifier) const;
|
||||
|
||||
private:
|
||||
DrawViewDimension* m_dimension;
|
||||
|
||||
Reference in New Issue
Block a user