Example #1
0
 def sortByName(self):
     self.treeWidget.setSortingEnabled(True)
     if self.sortToggle:
         self.treeWidget.sortByColumn(0, Qt.SortOrder(Qt.AscendingOrder))
     else:
         self.treeWidget.sortByColumn(0, Qt.SortOrder(Qt.DescendingOrder))
     self.treeWidget.setSortingEnabled(False)
     self.sortToggle = not self.sortToggle
Example #2
0
def get_model(db):
    """
    Create and populate the model used for all tblSTREET operations.
    
    :param db: Open QSqlDatabase object
    :return model: QSqlRelationalTableModel instance
    """
    # Assign names for easier access to column IDs
    (PK_UID, USRN, VERSION_NO, CURRENCY_FLAG, STREET_REF_TYPE, DESCRIPTION,
     ENTRY_DATE, UPDATE_DATE, START_DATE, AUTHORITY, CLOSURE_DATE, START_XREF,
     START_YREF, END_XREF, END_YREF, TOLERANCE, STREET_SUB_TYPE, STREET_STATE,
     STATE_DATE, STREET_CLASS, LOC_REF, COUNTY_REF, TOWN_REF, UPDATED_BY,
     CLOSED_BY, MIN_X, MIN_Y, MAX_X, MAX_Y, DESCRIPTION_ALT) = range(30)
    # Define model settings
    model = QSqlRelationalTableModel(db=db)
    model.setTable("tblSTREET")
    model.setFilter("currency_flag = 0")  # Only get most recent
    model.setSort(USRN, Qt.SortOrder())  # Order by usrn
    model.setEditStrategy(QSqlTableModel.OnManualSubmit)

    # Set up relational links to other tables
    model.setRelation(
        STREET_REF_TYPE,
        QSqlRelation("tlkpSTREET_REF_TYPE", "street_ref", "description"))
    model.setRelation(LOC_REF, QSqlRelation("tlkpLOCALITY", "loc_ref", "name"))
    model.setRelation(TOWN_REF, QSqlRelation("tlkpTOWN", "town_ref", "name"))
    model.setRelation(COUNTY_REF,
                      QSqlRelation("tlkpCOUNTY", "county_ref", "name"))
    model.setRelation(
        STREET_STATE,
        QSqlRelation("tlkpSTREET_STATE", "state_ref", "state_desc"))
    model.setRelation(
        STREET_CLASS,
        QSqlRelation("tlkpSTREET_CLASS", "class_ref", "street_classification"))
    model.setRelation(
        AUTHORITY, QSqlRelation("tlkpAUTHORITY", "auth_code", "description"))

    # Populate the model with data from the table
    model.select()
    # The following is required if table has more than 256 rows
    while model.canFetchMore():
        model.fetchMore()

    # Populate relational tables (which may have more than 256 rows)
    for relational_column in [
            STREET_REF_TYPE, LOC_REF, TOWN_REF, COUNTY_REF, STREET_STATE,
            STREET_CLASS, AUTHORITY
    ]:
        relation_model = model.relationModel(relational_column)
        while relation_model.canFetchMore():
            relation_model.fetchMore()

    return model
Example #3
0
 def sortTimeDesc(self):
     self.treeWidget.setSortingEnabled(True)
     self.treeWidget.sortByColumn(1, Qt.SortOrder(Qt.DescendingOrder))
     self.treeWidget.setSortingEnabled(False)