# Path: OpenNumismat/Collection/CollectionFields.py
# class FieldTypes():
#     String = 1
#     ShortString = 2
#     Number = 3
#     Text = 4
#     Money = 5
#     Date = 6
#     BigInt = 7
#     Image = 8
#     Value = 9
#     Status = 10
#     DateTime = 11
#     PreviewImage = 13
#     Denomination = 14
# 
#     Mask = 0xFF
#     Checkable = 0x100
#     Disabled = 0x200
# 
#     ImageTypes = (Image, PreviewImage)
# 
#     @staticmethod
#     def toSql(type_):
#         if type_ == FieldTypes.String:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.ShortString:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.Number:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.Text:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.Money:
#             sql_type = 'NUMERIC'
#         elif type_ == FieldTypes.Denomination:
#             sql_type = 'NUMERIC'
#         elif type_ == FieldTypes.Date:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.BigInt:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.PreviewImage:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.Image:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.Value:
#             sql_type = 'NUMERIC'
#         elif type_ == FieldTypes.Status:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.DateTime:
#             sql_type = 'TEXT'
#         else:
#             raise TypeError
# 
#         return sql_type
# 
# Path: OpenNumismat/Collection/CollectionFields.py
# class FieldTypes():
# class Status(dict):
# class CollectionField():
# class CollectionFieldsBase(QObject):
# class CollectionFields(CollectionFieldsBase):
#     def toSql(type_):
#     def __init__(self):
#     def keys(self):
#     def items(self):
#     def values(self):
#     def __getitem__(self, key):
#     def __init__(self, id_, name, title, type_):
#     def __init__(self, parent=None):
#     def field(self, id_):
#     def __iter__(self):
#     def __next__(self):
#     def __init__(self, db, parent=None):
#     def getCustomTitle(self, name):
#     def save(self):
#     def create(db=QSqlDatabase()):
# 
# Path: OpenNumismat/Tools/Gui.py
# def statusIcon(status):
#     return QIcon(":/%s.png" % status)
# 
# Path: OpenNumismat/Tools/Converters.py
# def numberWithFraction(string, enabled=True):
#     if enabled:
#         try:
#             if float(string) == 0.25:
#                 return '¼', True
#             elif float(string) == 0.33:
#                 return '⅓', True
#             elif float(string) == 0.5:
#                 return '½', True
#             elif float(string) == 0.75:
#                 return '¾', True
#             elif float(string) == 1.25:
#                 return '1¼', True
#             elif float(string) == 1.5:
#                 return '1½', True
#             elif float(string) == 2.5:
#                 return '2½', True
#         except (ValueError, TypeError):
#             pass
# 
#     return string, False


from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtSql import QSqlQuery
from PyQt5.QtWidgets import *
from OpenNumismat.Collection.CollectionFields import FieldTypes as Type
from OpenNumismat.Collection.CollectionFields import Statuses, StatusesOrder
from OpenNumismat.Tools.Gui import statusIcon
from OpenNumismat.Tools.Converters import numberWithFraction



class CustomSortListWidgetItem(QListWidgetItem):

    def __lt__(self, other):
        left = self.data(Qt.UserRole + 1)
        right = other.data(Qt.UserRole + 1)

        if isinstance(left, str):
            right = str(right)
        elif isinstance(right, str):
            left = str(left)

        return left < right


class StatusSortListWidgetItem(QListWidgetItem):

    def __lt__(self, other):
        left = self.data(Qt.UserRole)
        right = other.data(Qt.UserRole)

# Path: OpenNumismat/Collection/CollectionFields.py
# class FieldTypes():
#     String = 1
#     ShortString = 2
#     Number = 3
#     Text = 4
#     Money = 5
#     Date = 6
#     BigInt = 7
#     Image = 8
#     Value = 9
#     Status = 10
#     DateTime = 11
#     PreviewImage = 13
#     Denomination = 14
# 
#     Mask = 0xFF
#     Checkable = 0x100
#     Disabled = 0x200
# 
#     ImageTypes = (Image, PreviewImage)
# 
#     @staticmethod
#     def toSql(type_):
#         if type_ == FieldTypes.String:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.ShortString:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.Number:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.Text:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.Money:
#             sql_type = 'NUMERIC'
#         elif type_ == FieldTypes.Denomination:
#             sql_type = 'NUMERIC'
#         elif type_ == FieldTypes.Date:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.BigInt:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.PreviewImage:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.Image:
#             sql_type = 'INTEGER'
#         elif type_ == FieldTypes.Value:
#             sql_type = 'NUMERIC'
#         elif type_ == FieldTypes.Status:
#             sql_type = 'TEXT'
#         elif type_ == FieldTypes.DateTime:
#             sql_type = 'TEXT'
#         else:
#             raise TypeError
# 
#         return sql_type
# 
# Path: OpenNumismat/Collection/CollectionFields.py
# class FieldTypes():
# class Status(dict):
# class CollectionField():
# class CollectionFieldsBase(QObject):
# class CollectionFields(CollectionFieldsBase):
#     def toSql(type_):
#     def __init__(self):
#     def keys(self):
#     def items(self):
#     def values(self):
#     def __getitem__(self, key):
#     def __init__(self, id_, name, title, type_):
#     def __init__(self, parent=None):
#     def field(self, id_):
#     def __iter__(self):
#     def __next__(self):
#     def __init__(self, db, parent=None):
#     def getCustomTitle(self, name):
#     def save(self):
#     def create(db=QSqlDatabase()):
# 
# Path: OpenNumismat/Tools/Gui.py
# def statusIcon(status):
#     return QIcon(":/%s.png" % status)
# 
# Path: OpenNumismat/Tools/Converters.py
# def numberWithFraction(string, enabled=True):
#     if enabled:
#         try:
#             if float(string) == 0.25:
#                 return '¼', True
#             elif float(string) == 0.33:
#                 return '⅓', True
#             elif float(string) == 0.5:
#                 return '½', True
#             elif float(string) == 0.75:
#                 return '¾', True
#             elif float(string) == 1.25:
#                 return '1¼', True
#             elif float(string) == 1.5:
#                 return '1½', True
#             elif float(string) == 2.5:
#                 return '2½', True
#         except (ValueError, TypeError):
#             pass
# 
#     return string, False


# Path: OpenNumismat/Collection/HeaderFilterMenu.py
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtSql import QSqlQuery
from PyQt5.QtWidgets import *
from OpenNumismat.Collection.CollectionFields import FieldTypes as Type
from OpenNumismat.Collection.CollectionFields import Statuses, StatusesOrder
from OpenNumismat.Tools.Gui import statusIcon
from OpenNumismat.Tools.Converters import numberWithFraction




class CustomSortListWidgetItem(QListWidgetItem):

    def __lt__(self, other):
        left = self.data(Qt.UserRole + 1)
        right = other.data(Qt.UserRole + 1)

        if isinstance(left, str):
            right = str(right)
        elif isinstance(right, str):
            left = str(left)

        return left < right


class StatusSortListWidgetItem(QListWidgetItem):

    def __lt__(self, other):
        left = self.data(Qt.UserRole)
        right = other.data(Qt.UserRole)

        return StatusesOrder[left] < StatusesOrder[right]