diff --git a/src/blackmisc/pq/measurementunit.h b/src/blackmisc/pq/measurementunit.h index 11008eb00..73b8ed593 100644 --- a/src/blackmisc/pq/measurementunit.h +++ b/src/blackmisc/pq/measurementunit.h @@ -341,10 +341,9 @@ namespace BlackMisc template static U unitFromSymbol(const QString &symbol, bool strict = true) { if (symbol.isEmpty()) return U::defaultUnit(); - const QList &units = U::allUnits(); - for (int i = 0; i < units.size(); ++i) + for (const auto unit : U::allUnits()) { - if (units.at(i).getSymbol() == symbol) return units.at(i); + if (unit.getSymbol() == symbol) { return unit; } } if (strict) qFatal("Illegal unit name"); return U::defaultUnit(); @@ -358,11 +357,9 @@ namespace BlackMisc template static bool isValidUnitSymbol(const QString &symbol, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive) { if (symbol.isEmpty()) return false; - const QList &units = U::allUnits(); - for (int i = 0; i < units.size(); ++i) + for (const auto unit : U::allUnits()) { - if (caseSensitivity == Qt::CaseSensitive && units.at(i).getSymbol() == symbol) return true; - if (units.at(i).getSymbol().compare(symbol, Qt::CaseInsensitive) == 0) return 0; + if (QString::compare(unit.getSymbol(), symbol, caseSensitivity) == 0) { return true; } } return false; } diff --git a/src/blackmisc/pq/physicalquantity.cpp b/src/blackmisc/pq/physicalquantity.cpp index b30a06180..aebeb2adb 100644 --- a/src/blackmisc/pq/physicalquantity.cpp +++ b/src/blackmisc/pq/physicalquantity.cpp @@ -57,7 +57,7 @@ namespace BlackMisc QString CPhysicalQuantity::getUnitSymbol() const { return this->m_unit.getSymbol(true); } template - CPhysicalQuantity::CPhysicalQuantity(double value, const MU &unit) : + CPhysicalQuantity::CPhysicalQuantity(double value, MU unit) : m_value(unit.isNull() ? 0.0 : value), m_unit(unit) { } @@ -240,7 +240,7 @@ namespace BlackMisc } template - PQ &CPhysicalQuantity::switchUnit(const MU &newUnit) + PQ &CPhysicalQuantity::switchUnit(MU newUnit) { if (this->m_unit != newUnit) { @@ -286,7 +286,7 @@ namespace BlackMisc } template - QString CPhysicalQuantity::valueRoundedWithUnit(const MU &unit, int digits, bool i18n) const + QString CPhysicalQuantity::valueRoundedWithUnit(MU unit, int digits, bool i18n) const { Q_ASSERT_X(!unit.isNull(), Q_FUNC_INFO, "Cannot convert to null"); if (this->isNull()) { return this->convertToQString(i18n); } @@ -301,14 +301,14 @@ namespace BlackMisc } template - double CPhysicalQuantity::valueRounded(const MU &unit, int digits) const + double CPhysicalQuantity::valueRounded(MU unit, int digits) const { Q_ASSERT_X(!unit.isNull(), Q_FUNC_INFO, "Cannot convert to null"); return unit.roundValue(this->value(unit), digits); } template - int CPhysicalQuantity::valueInteger(const MU &unit) const + int CPhysicalQuantity::valueInteger(MU unit) const { Q_ASSERT_X(!unit.isNull(), Q_FUNC_INFO, "Cannot convert to null"); double v = unit.roundValue(this->value(unit), 0); @@ -322,7 +322,7 @@ namespace BlackMisc } template - double CPhysicalQuantity::value(const MU &unit) const + double CPhysicalQuantity::value(MU unit) const { Q_ASSERT_X(!unit.isNull(), Q_FUNC_INFO, "Cannot convert to null"); return unit.convertFrom(this->m_value, this->m_unit); diff --git a/src/blackmisc/pq/physicalquantity.h b/src/blackmisc/pq/physicalquantity.h index 5418ed6ce..d2f7e1518 100644 --- a/src/blackmisc/pq/physicalquantity.h +++ b/src/blackmisc/pq/physicalquantity.h @@ -74,7 +74,7 @@ namespace BlackMisc //! Simply set unit, do no calclulate conversion //! \sa switchUnit - void setUnit(const MU &unit) { this->m_unit = unit; } + void setUnit(MU unit) { this->m_unit = unit; } //! Set unit by string void setUnitBySymbol(const QString &unitName); @@ -83,7 +83,7 @@ namespace BlackMisc QString getUnitSymbol() const; //! Change unit, and convert value to maintain the same quantity - PQ &switchUnit(const MU &newUnit); + PQ &switchUnit(MU newUnit); //! Is quantity null? bool isNull() const; @@ -92,7 +92,7 @@ namespace BlackMisc void setNull(); //! Value in given unit - double value(const MU &unit) const; + double value(MU unit) const; //! Value in current unit double value() const; @@ -101,16 +101,16 @@ namespace BlackMisc void setCurrentUnitValue(double value); //! Rounded value in given unit - double valueRounded(const MU &unit, int digits = -1) const; + double valueRounded(MU unit, int digits = -1) const; //! As integer value - int valueInteger(const MU &unit) const; + int valueInteger(MU unit) const; //! Rounded value in current unit double valueRounded(int digits = -1) const; //! Value to QString with the given unit, e.g. "5.00m" - QString valueRoundedWithUnit(const MU &unit, int digits = -1, bool i18n = false) const; + QString valueRoundedWithUnit(MU unit, int digits = -1, bool i18n = false) const; //! Value to QString with the current unit, e.g. "5.00m" QString valueRoundedWithUnit(int digits = -1, bool i18n = false) const; @@ -222,7 +222,7 @@ namespace BlackMisc protected: //! Constructor with double - CPhysicalQuantity(double value, const MU &unit); + CPhysicalQuantity(double value, MU unit); //! Constructor by parsed string, e.g. 10m CPhysicalQuantity(const QString &unitString);