aboutsummaryrefslogtreecommitdiff
path: root/ql/types
diff options
context:
space:
mode:
Diffstat (limited to 'ql/types')
-rw-r--r--ql/types/__pycache__/boolean.cpython-35.pycbin0 -> 2085 bytes
-rw-r--r--ql/types/__pycache__/date.cpython-35.pycbin0 -> 3328 bytes
-rw-r--r--ql/types/__pycache__/decimal.cpython-35.pycbin0 -> 3514 bytes
-rw-r--r--ql/types/__pycache__/integer.cpython-35.pycbin0 -> 3568 bytes
-rw-r--r--ql/types/__pycache__/money.cpython-35.pycbin0 -> 3747 bytes
-rw-r--r--ql/types/__pycache__/string.cpython-35.pycbin0 -> 2788 bytes
-rw-r--r--ql/types/__pycache__/type.cpython-35.pycbin0 -> 443 bytes
-rw-r--r--ql/types/__pycache__/undefined.cpython-35.pycbin0 -> 2013 bytes
-rw-r--r--ql/types/boolean.py42
-rw-r--r--ql/types/date.py67
-rw-r--r--ql/types/decimal.py74
-rw-r--r--ql/types/integer.py75
-rw-r--r--ql/types/money.py76
-rw-r--r--ql/types/string.py55
-rw-r--r--ql/types/type.py3
-rw-r--r--ql/types/undefined.py40
16 files changed, 432 insertions, 0 deletions
diff --git a/ql/types/__pycache__/boolean.cpython-35.pyc b/ql/types/__pycache__/boolean.cpython-35.pyc
new file mode 100644
index 0000000..0acd5ee
--- /dev/null
+++ b/ql/types/__pycache__/boolean.cpython-35.pyc
Binary files differ
diff --git a/ql/types/__pycache__/date.cpython-35.pyc b/ql/types/__pycache__/date.cpython-35.pyc
new file mode 100644
index 0000000..389ffc4
--- /dev/null
+++ b/ql/types/__pycache__/date.cpython-35.pyc
Binary files differ
diff --git a/ql/types/__pycache__/decimal.cpython-35.pyc b/ql/types/__pycache__/decimal.cpython-35.pyc
new file mode 100644
index 0000000..03e70c2
--- /dev/null
+++ b/ql/types/__pycache__/decimal.cpython-35.pyc
Binary files differ
diff --git a/ql/types/__pycache__/integer.cpython-35.pyc b/ql/types/__pycache__/integer.cpython-35.pyc
new file mode 100644
index 0000000..eacf953
--- /dev/null
+++ b/ql/types/__pycache__/integer.cpython-35.pyc
Binary files differ
diff --git a/ql/types/__pycache__/money.cpython-35.pyc b/ql/types/__pycache__/money.cpython-35.pyc
new file mode 100644
index 0000000..4213628
--- /dev/null
+++ b/ql/types/__pycache__/money.cpython-35.pyc
Binary files differ
diff --git a/ql/types/__pycache__/string.cpython-35.pyc b/ql/types/__pycache__/string.cpython-35.pyc
new file mode 100644
index 0000000..18b2f54
--- /dev/null
+++ b/ql/types/__pycache__/string.cpython-35.pyc
Binary files differ
diff --git a/ql/types/__pycache__/type.cpython-35.pyc b/ql/types/__pycache__/type.cpython-35.pyc
new file mode 100644
index 0000000..f81c2f7
--- /dev/null
+++ b/ql/types/__pycache__/type.cpython-35.pyc
Binary files differ
diff --git a/ql/types/__pycache__/undefined.cpython-35.pyc b/ql/types/__pycache__/undefined.cpython-35.pyc
new file mode 100644
index 0000000..ddc6cc1
--- /dev/null
+++ b/ql/types/__pycache__/undefined.cpython-35.pyc
Binary files differ
diff --git a/ql/types/boolean.py b/ql/types/boolean.py
new file mode 100644
index 0000000..f9dc76c
--- /dev/null
+++ b/ql/types/boolean.py
@@ -0,0 +1,42 @@
+from gui.widgets.checkbox import CheckBox
+from ql.ast.nodes.expressions.literals.boolean_literal import BooleanNode
+from ql.types.type import QLType
+
+
+class QLBoolean(QLType):
+ def __init__(self, value=False):
+ super(QLBoolean, self).__init__()
+ self.__value = bool(value)
+
+ @property
+ def value(self):
+ return self.__value
+
+ def __bool__(self):
+ return bool(self.value)
+
+ def __str__(self):
+ return str(self.value)
+
+ def __repr__(self):
+ return str(self.value)
+
+ def __eq__(self, other):
+ if isinstance(other, QLBoolean):
+ return QLBoolean(self.value == other.value)
+
+ return QLBoolean(False)
+
+ def __ne__(self, other):
+ return QLBoolean(not self == other)
+
+ def get_json_value(self):
+ return self.value
+
+ @staticmethod
+ def get_literal_node(value):
+ return BooleanNode(None, QLBoolean, value)
+
+ @staticmethod
+ def pyqt5_default_widget():
+ return CheckBox()
diff --git a/ql/types/date.py b/ql/types/date.py
new file mode 100644
index 0000000..fca5366
--- /dev/null
+++ b/ql/types/date.py
@@ -0,0 +1,67 @@
+from datetime import date
+
+from gui.widgets.calendar import CalendarWidget
+from ql.ast.nodes.expressions.literals.date_literal import DateNode
+from ql.types.boolean import QLBoolean
+from ql.types.type import QLType
+
+
+class QLDate(QLType):
+ def __init__(self, day=1, month=1, year=1):
+ super(QLDate, self).__init__()
+ self.__day = int(day)
+ self.__month = int(month)
+ self.__year = int(year)
+ date(self.year, self.month, self.day)
+
+ @property
+ def day(self):
+ return self.__day
+
+ @property
+ def month(self):
+ return self.__month
+
+ @property
+ def year(self):
+ return self.__year
+
+ def __repr__(self):
+ return '{}-{}-{}'.format(self.day, self.month, self.year)
+
+ def __str__(self):
+ return '{}-{}-{}'.format(self.day, self.month, self.year)
+
+ def __eq__(self, other):
+ if isinstance(other, QLDate):
+ return QLBoolean(self.day == other.day and self.month == other.month and self.year == other.year)
+
+ return QLBoolean(False)
+
+ def __ne__(self, other):
+ return QLBoolean(not self == other)
+
+ def __lt__(self, other):
+ return QLBoolean(self.year < other.year or (self.month < other.month and self.year == other.year) or
+ (self.day < other.day and self.month == other.month and self.year == other.year))
+
+ def __gt__(self, other):
+ return QLBoolean(self.year > other.year or (self.month > other.month and self.year == other.year) or
+ (self.day > other.day and self.month == other.month and self.year == other.year))
+
+ def __le__(self, other):
+ return QLBoolean(self < other or self == other)
+
+ def __ge__(self, other):
+ return QLBoolean(self > other or self == other)
+
+ def get_json_value(self):
+ return {'day': self.day, 'month': self.month, 'year': self.year}
+
+ @staticmethod
+ def get_literal_node(value):
+ return DateNode(None, QLDate, value)
+
+ @staticmethod
+ def pyqt5_default_widget():
+ return CalendarWidget()
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()
diff --git a/ql/types/integer.py b/ql/types/integer.py
new file mode 100644
index 0000000..ddc8666
--- /dev/null
+++ b/ql/types/integer.py
@@ -0,0 +1,75 @@
+from gui.widgets.spinbox import SpinBox
+from ql.ast.nodes.expressions.literals.integer_literal import IntegerNode
+from ql.types.boolean import QLBoolean
+from ql.types.decimal import QLDecimal
+from ql.types.money import QLMoney
+from ql.types.type import QLType
+
+
+class QLInteger(QLType):
+ def __init__(self, value=0):
+ super(QLInteger, self).__init__()
+ self.__value = int(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 QLInteger(- self.value)
+
+ def __eq__(self, other):
+ if isinstance(other, QLInteger):
+ 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 type(other)(self.value + other.value)
+
+ def __sub__(self, other):
+ return type(other)(self.value - other.value)
+
+ def __mul__(self, other):
+ if isinstance(other, QLMoney):
+ return QLMoney(self.value * other.value, other.currency)
+
+ return type(other)(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 IntegerNode(None, QLInteger, value)
+
+ @staticmethod
+ def pyqt5_default_widget():
+ return SpinBox()
diff --git a/ql/types/money.py b/ql/types/money.py
new file mode 100644
index 0000000..edac58f
--- /dev/null
+++ b/ql/types/money.py
@@ -0,0 +1,76 @@
+from gui.widgets.money_spinbox import MoneySpinbox
+from ql.ast.nodes.expressions.literals.money_literal import MoneyNode
+from ql.types.boolean import QLBoolean
+from ql.types.type import QLType
+
+
+class QLMoney(QLType):
+ def __init__(self, value=0.0, currency='$'):
+ super(QLMoney, self).__init__()
+ self.__value = float(value)
+ self.__currency = currency
+
+ @property
+ def value(self):
+ return self.__value
+
+ @property
+ def currency(self):
+ return self.__currency
+
+ def __repr__(self):
+ return '{}{:.2f}'.format(self.currency, self.value)
+
+ def __str__(self):
+ return '{}{:.2f}'.format(self.currency, self.value)
+
+ def __neg__(self):
+ return QLMoney(- self.value, self.currency)
+
+ def __eq__(self, other):
+ if isinstance(other, QLMoney):
+ return QLBoolean(self.value == other.value and self.currency == other.currency)
+
+ return QLBoolean(False)
+
+ def __ne__(self, other):
+ return QLBoolean(not self == other)
+
+ def __lt__(self, other):
+ return QLBoolean(self.value < other.value and self.currency == other.currency)
+
+ def __gt__(self, other):
+ return QLBoolean(self.value > other.value and self.currency == other.currency)
+
+ def __le__(self, other):
+ return QLBoolean(self.value <= other.value and self.currency == other.currency)
+
+ def __ge__(self, other):
+ return QLBoolean(self.value >= other.value and self.currency == other.currency)
+
+ def __add__(self, other):
+ if self.currency == other.currency:
+ return QLMoney(self.value + other.value, self.currency)
+ return NotImplemented
+
+ def __sub__(self, other):
+ if self.currency == other.currency:
+ return QLMoney(self.value - other.value, self.currency)
+ return NotImplemented
+
+ def __mul__(self, other):
+ return other * self
+
+ def __truediv__(self, other):
+ return other / self
+
+ def get_json_value(self):
+ return {'value': round(self.value, 2), 'currency': self.currency}
+
+ @staticmethod
+ def get_literal_node(value):
+ return MoneyNode(None, QLMoney, value)
+
+ @staticmethod
+ def pyqt5_default_widget():
+ return MoneySpinbox()
diff --git a/ql/types/string.py b/ql/types/string.py
new file mode 100644
index 0000000..ece46a7
--- /dev/null
+++ b/ql/types/string.py
@@ -0,0 +1,55 @@
+from gui.widgets.line_edit import LineEdit
+from ql.ast.nodes.expressions.literals.string_literal import StringNode
+from ql.types.boolean import QLBoolean
+from ql.types.type import QLType
+
+
+class QLString(QLType):
+ def __init__(self, value=''):
+ super(QLString, self).__init__()
+ self.__value = str(value)
+
+ @property
+ def value(self):
+ return self.__value
+
+ def __repr__(self):
+ return str(self.value)
+
+ def __str__(self):
+ return str(self.value)
+
+ def __eq__(self, other):
+ if isinstance(other, QLString):
+ return QLBoolean(self.value == other.value)
+
+ return QLBoolean(False)
+
+ def __ne__(self, other):
+ return QLBoolean(not self == other)
+
+ def __lt__(self, other):
+ return QLBoolean(len(self.value) < len(other.value))
+
+ def __gt__(self, other):
+ return QLBoolean(len(self.value) > len(other.value))
+
+ def __le__(self, other):
+ return QLBoolean(len(self.value) <= len(other.value))
+
+ def __ge__(self, other):
+ return QLBoolean(len(self.value) >= len(other.value))
+
+ def __add__(self, other):
+ return QLString(self.value + other.value)
+
+ def get_json_value(self):
+ return self.value
+
+ @staticmethod
+ def get_literal_node(value):
+ return StringNode(None, QLString, value)
+
+ @staticmethod
+ def pyqt5_default_widget():
+ return LineEdit()
diff --git a/ql/types/type.py b/ql/types/type.py
new file mode 100644
index 0000000..912946d
--- /dev/null
+++ b/ql/types/type.py
@@ -0,0 +1,3 @@
+class QLType:
+ def __init__(self):
+ pass
diff --git a/ql/types/undefined.py b/ql/types/undefined.py
new file mode 100644
index 0000000..2deafe0
--- /dev/null
+++ b/ql/types/undefined.py
@@ -0,0 +1,40 @@
+from gui.widgets.label import Label
+from ql.ast.nodes.expressions.literals.undefined_literal import UndefinedNode
+from ql.types.boolean import QLBoolean
+from ql.types.type import QLType
+
+
+class QLUndefined(QLType):
+ def __init__(self, *unused):
+ super(QLUndefined, self).__init__()
+ self.__value = None
+
+ @property
+ def value(self):
+ return self.__value
+
+ def __bool__(self):
+ return False
+
+ def __repr__(self):
+ return 'Undefined'
+
+ def __eq__(self, other):
+ if isinstance(other, QLUndefined):
+ return QLBoolean(self.value == other.value)
+
+ return QLBoolean(False)
+
+ def __ne__(self, other):
+ return QLBoolean(not self == other)
+
+ def get_json_value(self):
+ return self.value
+
+ @staticmethod
+ def get_literal_node(unused):
+ return UndefinedNode(None, QLUndefined, QLUndefined(None))
+
+ @staticmethod
+ def pyqt5_default_widget():
+ return Label('Undefined')