Example #1
0
class QMLPersonListModel(QtCore.QAbstractListModel):
    """
    A simple ListModel for the People in the database
    """
    ROLE_NAME_COL = 0
    COLUMNS = ((ROLE_NAME_COL, 'name'), )

    def __init__(self, db):
        QtCore.QAbstractListModel.__init__(self)
        self.__db = db
        self.gen_cursor = db.get_person_cursor
        self.sort_func = self.sort_name
        self.node_map = FlatNodeMap()
        self._reverse = False
        #build node map with all peopls
        allkeys = self.sort_keys()
        ident = True
        dlist = allkeys
        self.node_map.set_path_map(dlist, allkeys, identical=ident,
                                   reverse=self._reverse)

        #every column has a role from 0 to nrcol-1, and name as in COLUMNS
        self.setRoleNames(dict(QMLPersonListModel.COLUMNS))
        #we create an array with all the QMLPerson that we need so
        #that we can match a rowindex with correct QMLPerson
        self._qmlpersons = []
        for _, handle in self.node_map.full_srtkey_hndl_map():
            self._qmlpersons.append(QMLPerson(self.__db, handle))

    def sort_keys(self):
        """
        Return the (sort_key, handle) list of all data that can maximally
        be shown.
        This list is sorted ascending, via localized string sort.
        conv_unicode_tosrtkey which uses strxfrm, which is apparently
        broken in Win ?? --> they should fix base lib, we need strxfrm, fix it
        in the Utils module.
        """
        # use cursor as a context manager
        with self.gen_cursor() as cursor:
            #loop over database and store the sort field, and the handle
            return sorted((list(map(conv_unicode_tosrtkey,
                           self.sort_func(data))), key) for key, data in cursor)

    def sort_name(self, data):
        n = Name()
        n.unserialize(data[COLUMN_NAME])
        return (n.get_primary_surname().get_surname(), n.get_first_name())

    def rowCount(self, parent=QtCore.QModelIndex()):
        return self.__db.get_number_of_people()

    def data(self, index, role):
        """
        Obtain QMLPerson to show. Role is a number that corresponds to a column,
        different columns can obtain data from different objects
        """
        if index.isValid() and role <= QMLPersonListModel.ROLE_NAME_COL:
            return self._qmlpersons[index.row()]
        return None
Example #2
0
    def __init__(self, db):
        QtCore.QAbstractListModel.__init__(self)
        self.__db = db
        self.gen_cursor = db.get_person_cursor
        self.sort_func = self.sort_name
        self.node_map = FlatNodeMap()
        self._reverse = False
        #build node map with all peopls
        allkeys = self.sort_keys()
        ident = True
        dlist = allkeys
        self.node_map.set_path_map(dlist,
                                   allkeys,
                                   identical=ident,
                                   reverse=self._reverse)

        #every column has a role from 0 to nrcol-1, and name as in COLUMNS
        self.setRoleNames(dict(QMLPersonListModel.COLUMNS))
        #we create an array with all the QMLPerson that we need so
        #that we can match a rowindex with correct QMLPerson
        self._qmlpersons = []
        for _, handle in self.node_map.full_srtkey_hndl_map():
            self._qmlpersons.append(QMLPerson(self.__db, handle))
Example #3
0
    def __init__(self, db):
        QtCore.QAbstractListModel.__init__(self)
        self.__db = db
        self.gen_cursor = db.get_person_cursor
        self.sort_func = self.sort_name
        self.node_map = FlatNodeMap()
        self._reverse = False
        #build node map with all peopls
        allkeys = self.sort_keys()
        ident = True
        dlist = allkeys
        self.node_map.set_path_map(dlist, allkeys, identical=ident,
                                   reverse=self._reverse)

        #every column has a role from 0 to nrcol-1, and name as in COLUMNS
        self.setRoleNames(dict(QMLPersonListModel.COLUMNS))
        #we create an array with all the QMLPerson that we need so
        #that we can match a rowindex with correct QMLPerson
        self._qmlpersons = []
        for _, handle in self.node_map.full_srtkey_hndl_map():
            self._qmlpersons.append(QMLPerson(self.__db, handle))
Example #4
0
class QMLPersonListModel(QtCore.QAbstractListModel):
    """
    A simple ListModel for the People in the database
    """
    ROLE_NAME_COL = 0
    COLUMNS = ((ROLE_NAME_COL, 'name'), )

    def __init__(self, db):
        QtCore.QAbstractListModel.__init__(self)
        self.__db = db
        self.gen_cursor = db.get_person_cursor
        self.sort_func = self.sort_name
        self.node_map = FlatNodeMap()
        self._reverse = False
        #build node map with all peopls
        allkeys = self.sort_keys()
        ident = True
        dlist = allkeys
        self.node_map.set_path_map(dlist,
                                   allkeys,
                                   identical=ident,
                                   reverse=self._reverse)

        #every column has a role from 0 to nrcol-1, and name as in COLUMNS
        self.setRoleNames(dict(QMLPersonListModel.COLUMNS))
        #we create an array with all the QMLPerson that we need so
        #that we can match a rowindex with correct QMLPerson
        self._qmlpersons = []
        for _, handle in self.node_map.full_srtkey_hndl_map():
            self._qmlpersons.append(QMLPerson(self.__db, handle))

    def sort_keys(self):
        """
        Return the (sort_key, handle) list of all data that can maximally 
        be shown. 
        This list is sorted ascending, via localized string sort. 
        conv_unicode_tosrtkey which uses strxfrm, which is apparently 
        broken in Win ?? --> they should fix base lib, we need strxfrm, fix it 
        in the Utils module.
        """
        # use cursor as a context manager
        with self.gen_cursor() as cursor:
            #loop over database and store the sort field, and the handle
            return sorted(
                (list(map(conv_unicode_tosrtkey, self.sort_func(data))), key)
                for key, data in cursor)

    def sort_name(self, data):
        n = Name()
        n.unserialize(data[COLUMN_NAME])
        return (n.get_primary_surname().get_surname(), n.get_first_name())

    def rowCount(self, parent=QtCore.QModelIndex()):
        return self.__db.get_number_of_people()

    def data(self, index, role):
        """
        Obtain QMLPerson to show. Role is a number that corresponds to a column,
        different columns can obtain data from different objects
        """
        if index.isValid() and role <= QMLPersonListModel.ROLE_NAME_COL:
            return self._qmlpersons[index.row()]
        return None