Beispiel #1
0
def UseSqlTable(db, table_name, columns, relations):
    if relations:
        model = QSqlRelationalTableModel(db=db)
    else:
        model = QSqlTableModel(db=db)
    model.setTable(table_name)
    model.setEditStrategy(QSqlTableModel.OnManualSubmit)
    if relations:
        model.setJoinMode(QSqlRelationalTableModel.LeftJoin
                          )  # to work correctly with NULL values in fields
        for relation in relations:
            model.setRelation(
                model.fieldIndex(relation[rel_idx.KEY_FIELD]),
                QSqlRelation(relation[rel_idx.LOOKUP_TABLE],
                             relation[rel_idx.FOREIGN_KEY],
                             relation[rel_idx.LOOKUP_FIELD]))
    for column in columns:
        if column[hcol_idx.DISPLAY_NAME]:
            model.setHeaderData(
                model.fieldIndex(column[hcol_idx.DB_NAME]), Qt.Horizontal,
                g_tr('TableViewConfig', column[hcol_idx.DISPLAY_NAME]))
        if column[hcol_idx.SORT_ORDER] is not None:
            model.setSort(model.fieldIndex(column[hcol_idx.DB_NAME]),
                          column[hcol_idx.SORT_ORDER])
    return model
Beispiel #2
0
 def match_valasztas(self):
     matches = QSqlRelationalTableModel(db=db)
     matches.setTable("match_settings")
     matches.setSort(8, Qt.DescendingOrder)
     matches.select()
     self.merkozesek.clear()
     for i in  range(matches.rowCount()):
         self.merkozesek.addItem(str(matches.record(i).value(1)) + "\t" +
                                 str(matches.record(i).value(2)) + "\t" +
                                 str(int(matches.record(i).value(3)) + matches.record(i).value(6)) + "\t" +
                                 str(int(matches.record(i).value(3)) + matches.record(i).value(7)) + "\t" +
                                 str(matches.record(i).value(4)) + "\t" +
                                 str(matches.record(i).value(5)) + "\t" +
                                 str(matches.record(i).value(8))[:16] + "\t" +
                                 str(matches.record(i).value(0))
         )