Skip to content
Snippets Groups Projects
Commit 09172ae1 authored by inso's avatar inso
Browse files

Issue #188

parent f105b245
No related branches found
No related tags found
No related merge requests found
......@@ -36,32 +36,54 @@ class Quantitative():
def differential(self):
return self.value()
def _to_si(self, value):
prefixes = ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'z', 'y']
scientific_value = value
prefix_index = 0
prefix = ""
while scientific_value > 1000:
prefix_index += 1
scientific_value /= 1000
if prefix_index < len(prefixes):
prefix = prefixes[prefix_index]
localized_value = QLocale().toString(float(scientific_value), 'f', 3)
else:
localized_value = QLocale().toString(float(value), 'f', 0)
return localized_value, prefix
def localized(self, units=False, international_system=False):
value = self.value()
prefix = ""
if international_system:
pass
localized_value, prefix = self._to_si(value)
else:
localized_value = QLocale().toString(float(value), 'f', 0)
if units:
if units or international_system:
return QCoreApplication.translate("Quantitative",
Quantitative._REF_STR_) \
.format(localized_value,
prefix,
self.community.short_currency if units else "")
else:
return localized_value
def diff_localized(self, units=False, international_system=False):
value = self.differential()
prefix = ""
if international_system:
pass
localized_value, prefix = self._to_si(value)
else:
localized_value = QLocale().toString(float(value), 'f', 0)
if units:
if units or international_system:
return QCoreApplication.translate("Quantitative",
Quantitative._REF_STR_) \
.format(localized_value,
prefix,
self.community.short_currency if units else "")
else:
return localized_value
......@@ -3,7 +3,7 @@ from PyQt5.QtCore import QObject, QCoreApplication, QT_TRANSLATE_NOOP, QLocale
class Relative():
_NAME_STR_ = QT_TRANSLATE_NOOP('Relative', 'UD')
_REF_STR_ = QT_TRANSLATE_NOOP('Relative', "{0} UD {1}")
_REF_STR_ = QT_TRANSLATE_NOOP('Relative', "{0} {1}UD {2}")
_UNITS_STR_ = QT_TRANSLATE_NOOP('Relative', "UD {0}")
def __init__(self, amount, community, app):
......@@ -39,30 +39,55 @@ class Relative():
def differential(self):
return self.value()
def _to_si(self, value):
prefixes = ['', 'd', 'c', 'm', 'µ', 'n', 'p', 'f', 'a', 'z', 'y']
scientific_value = value
prefix_index = 0
prefix = ""
while int(scientific_value) == 0:
if prefix_index > 3:
scientific_value *= 1000
else:
scientific_value *= 10
prefix_index += 1
if prefix_index < len(prefixes):
prefix = prefixes[prefix_index]
localized_value = QLocale().toString(float(scientific_value), 'f', self.app.preferences['digits_after_comma'])
else:
localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
return localized_value, prefix
def localized(self, units=False, international_system=False):
value = self.value()
prefix = ""
if international_system:
pass
localized_value, prefix = self._to_si(value)
else:
localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
if units:
if units or international_system:
return QCoreApplication.translate("Relative", Relative._REF_STR_) \
.format(localized_value,
prefix,
self.community.short_currency if units else "")
else:
return localized_value
def diff_localized(self, units=False, international_system=False):
value = self.differential()
if international_system:
pass
prefix = ""
if international_system and value != 0:
localized_value, prefix = self._to_si(value)
else:
localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
if units:
if units or international_system:
return QCoreApplication.translate("Relative", Relative._REF_STR_)\
.format(localized_value,
prefix,
self.community.short_currency if units else "")
else:
return localized_value
......@@ -112,7 +112,7 @@ class TxFilterProxyModel(QSortFilterProxyModel):
if source_index.column() == model.columns_types.index('payment') or \
source_index.column() == model.columns_types.index('deposit'):
if source_data is not "":
return self.account.current_ref(source_data, self.community, self.app).diff_localized()
return self.account.current_ref(source_data, self.community, self.app).diff_localized(international_system=True)
if role == Qt.FontRole:
font = QFont()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment