diff options
| author | Bicker <bickerkards@tuta.io> | 2019-05-22 17:45:37 +0200 |
|---|---|---|
| committer | Bicker <bickerkards@tuta.io> | 2019-05-22 17:45:37 +0200 |
| commit | 25314fd2aed81aa5281bc3d93dbcc7919368ebe1 (patch) | |
| tree | 1995521ee652e419926de5fced0f2e3b655e70fb /ql/types/decimal.py | |
Diffstat (limited to 'ql/types/decimal.py')
| -rw-r--r-- | ql/types/decimal.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/ql/types/decimal.py b/ql/types/decimal.py new file mode 100644 index 0000000..af0952d --- /dev/null +++ b/ql/types/decimal.py @@ -0,0 +1,74 @@ +from gui.widgets.double_spinbox import DoubleSpinBox +from ql.ast.nodes.expressions.literals.decimal_literal import DecimalNode +from ql.types.boolean import QLBoolean +from ql.types.money import QLMoney +from ql.types.type import QLType + + +class QLDecimal(QLType): + def __init__(self, value=0.0): + super(QLDecimal, self).__init__() + self.__value = float(value) + + @property + def value(self): + return self.__value + + def __repr__(self): + return str(self.value) + + def __str__(self): + return str(self.value) + + def __neg__(self): + return QLDecimal(- self.value) + + def __eq__(self, other): + if isinstance(other, QLDecimal): + return QLBoolean(self.value == other.value) + + return QLBoolean(False) + + def __ne__(self, other): + return QLBoolean(not self == other) + + def __lt__(self, other): + return QLBoolean(self.value < other.value) + + def __gt__(self, other): + return QLBoolean(self.value > other.value) + + def __le__(self, other): + return QLBoolean(self.value <= other.value) + + def __ge__(self, other): + return QLBoolean(self.value >= other.value) + + def __add__(self, other): + return QLDecimal(self.value + other.value) + + def __sub__(self, other): + return QLDecimal(self.value - other.value) + + def __mul__(self, other): + if isinstance(other, QLMoney): + return QLMoney(self.value * other.value, other.currency) + + return QLDecimal(self.value * other.value) + + def __truediv__(self, other): + if isinstance(other, QLMoney): + return QLMoney(other.value / self.value, other.currency) + + return QLDecimal(self.value / other.value) + + def get_json_value(self): + return self.value + + @staticmethod + def get_literal_node(value): + return DecimalNode(None, QLDecimal, value) + + @staticmethod + def pyqt5_default_widget(): + return DoubleSpinBox() |