Example #1
0
    def __readSubData(self):
        tv = self.ui.tableView
        em = self.EditMode
        JFDM = JPEditFormDataMode
        if em is None:
            raise ValueError("没有指定子窗体的编辑模式!")
        # 建立子窗体模型
        ModelClass = self.onGetModelClass()

        if self.isNewMode:
            tfi = JPTabelFieldInfo(self.subSQL, False)
            if len(tfi.DeleteRows) == 0:
                tfi.addRow()
        if self.isReadOnlyMode:
            tfi = JPQueryFieldInfo(self.subSQL.format(self.PKValue))
        if self.isEditMode:
            tfi = JPTabelFieldInfo(self.subSQL.format(self.PKValue))
            tfi.addRow()
        self.subModel = ModelClass(tv, tfi)
        if self.isNewMode or self.isEditMode:
            self.subModel.firstHasDirty.connect(self.onFirstHasDirty)

        # 检查第一列是不是子表主键
        if tfi.Fields[0].IsPrimarykey is False:
            errtxt = "setSQL()方法第二个参数中Sql语句,第一列必须是主键字段。\n{}"
            errtxt = errtxt.format(self.subSQL)
            QMessageBox.warning(self, "错误", errtxt)
        self.subTableFieldsInfo = tfi
        smd = self.subModel
        tv.setModel(smd)

        smd.dataChanged.connect(self._emitDataChange)
        # 设置子窗体可编辑状态
        self.setEditState(em != JFDM.ReadOnly)
        # 设置子窗体的输入委托控件及格式等

        self.__readOnlyColumns = self.onGetReadOnlyColumns()
        smd.setColumnsDetegate()
        for col in self.__readOnlyColumns:
            tv.setItemDelegateForColumn(col, myDe.JPDelegate_ReadOnly(tv))
        self.__hideColumns = self.onGetHiddenColumns()
        # 设置隐藏列,第0列不隐藏(将显示删除按钮)
        for col in [c for c in self.__hideColumns if c > 0]:
            tv.setColumnHidden(col, True)
        self.__columnWidths = self.onGetColumnWidths()
        for i, w in enumerate(self.__columnWidths):
            tv.setColumnWidth(i, w)
        self.__columnsRowSources = self.onGetColumnRowSources()
        for field_key, data, bind_col in self.__columnsRowSources:
            smd.TabelFieldInfo.Fields[field_key].BindingColumn = bind_col
            smd.TabelFieldInfo.setFieldsRowSource(field_key, data)
        # 设置字段计算公式
        for i, f in self.onGetColumnFormulas():
            smd.TabelFieldInfo.Fields[i].Formula = f
        temp = self.afterSetDataBeforeInsterRowEvent
        smd.afterSetDataBeforeInsterRowEvent = temp
        temp1 = self.afterInsterRowEvent
        smd.afterInsterRowEvent = temp1
        self.subModel.deleteRowDelegate = MyButtonDelegate(tv)
        tv.setItemDelegateForColumn(0, self.subModel.deleteRowDelegate)
Example #2
0
 def clear456(self, r):
     # 只要修改了字段,清除后三项并禁止编辑
     de = myDe.JPDelegate_ReadOnly(self.tableView)
     self.tableView.setItemDelegateForColumn(4, de)
     self.tableView.setItemDelegateForColumn(5, de)
     self.tableView.setItemDelegateForColumn(6, de)
     self.setData(self.createIndex(r, 4), None)
     self.setData(self.createIndex(r, 5), None)
     self.setData(self.createIndex(r, 6), None)
Example #3
0
    def __init__(self, tabinfo, base_sql, parent=None, flags=Qt.WindowFlags()):
        super().__init__(parent=parent, flags=flags)
        self.ui = Ui_DlgSearch()
        self.ui.setupUi(self)
        self.tv = self.ui.tableView
        self.BaseSQL = base_sql

        sql = """
        SELECT fID,'' AS Guanxi, '' AS ZuoKuoHao, 
            '' AS Ziduan, '' AS YunSuan, '' AS Zhi1,
            '' AS Zhi2, '' AS YouKuoHao
        FROM sysconfig
        LIMIT 0
        """
        tab = myTabelFieldInfo(sql, True)
        titles = [
            " ", "关系", "(", "字段Field", "运算Symbols", "值1 Value1", "值2 Value2",
            ")"
        ]
        for i, t in enumerate(titles):
            tab.Fields[i].Title = t

        self.tab = tab
        self.tab.addRow()
        self.Model = myJPTableViewModelEditForm(self.tv, self.tab)
        self.tv.setModel(self.Model)
        widths = [30, 50, 50, 150, 150, 100, 100, 50]
        for i, w in enumerate(widths):
            self.tv.setColumnWidth(i, w)
        lst_gx = [['', ''], ['And', 'And'], ['Or', 'Or'], ['Not', 'Not']]
        self.de_sy = myDe.JPDelegate_ComboBox(self.tv, lst_gx)
        self.de_kh_left = myDe.JPDelegate_ComboBox(self.tv, [
            ['', ''],
            ['(', '('],
        ])
        self.de_kh_right = myDe.JPDelegate_ComboBox(self.tv,
                                                    [['', ''], [')', ')']])
        self.de_field = JDFieldComboBox(tabinfo)
        self.de_field.setDialog(self)
        self.tv.setItemDelegateForColumn(3, self.de_field)
        self.de_no = myDe.JPDelegate_ReadOnly(self.tv)
        self.tv.setItemDelegateForColumn(4, self.de_no)
        self.tv.setItemDelegateForColumn(5, self.de_no)
        self.tv.setItemDelegateForColumn(6, self.de_no)
        self.tv.cellButtonClicked = self.cellButtonClicked
        self.tv.setItemDelegateForColumn(0, MyButtonDelegate(self.tv))
        self.setDelegate127(0)
        self.tv.setCurrentIndex(self.Model.createIndex(0, 3))
Example #4
0
    def __init__(self, tabinfo, base_sql, parent=None, flags=Qt.WindowFlags()):
        super().__init__(parent=parent, flags=flags)
        self.ui = Ui_DlgSearch()
        self.ui.setupUi(self)
        self.tv = self.ui.tableView
        self.BaseSQL = base_sql
        self.tabinfo = copy.deepcopy(tabinfo)

        sql = """
        SELECT fID,'' AS Guanxi, '' AS ZuoKuoHao, 
            '' AS Ziduan, '' AS YunSuan, '' AS Zhi1,
            '' AS Zhi2, '' AS YouKuoHao
        FROM sysconfig
        LIMIT 0
        """
        tab = myTabelFieldInfo(sql, True)
        titles = [
            " ", "关系", "(", "字段Field", "运算Symbols", "值1 Value1", "值2 Value2",
            ")"
        ]
        for i, t in enumerate(titles):
            tab.Fields[i].Title = t

        self.tab = tab
        self.tab.addRow()
        self.Model = myJPTableViewModelEditForm(self.tv, self.tab)
        self.tv.setModel(self.Model)
        widths = [30, 50, 50, 150, 150, 100, 100, 50]
        for i, w in enumerate(widths):
            self.tv.setColumnWidth(i, w)
        lst_gx = [['', ''], ['And', 'And'], ['Or', 'Or'], ['Not', 'Not']]
        self.de_sy = myDe.JPDelegate_ComboBox(self.tv, lst_gx)
        self.de_kh_left = myDe.JPDelegate_ComboBox(self.tv, [
            ['', ''],
            ['(', '('],
        ])
        self.de_kh_right = myDe.JPDelegate_ComboBox(self.tv,
                                                    [['', ''], [')', ')']])
        self.de_field = JDFieldComboBox(self.tabinfo)
        self.de_field.setDialog(self)
        self.tv.setItemDelegateForColumn(3, self.de_field)
        self.de_no = myDe.JPDelegate_ReadOnly(self.tv)
        self.tv.setItemDelegateForColumn(4, self.de_no)
        self.tv.setItemDelegateForColumn(5, self.de_no)
        self.tv.setItemDelegateForColumn(6, self.de_no)
        self.tv.cellButtonClicked = self.cellButtonClicked
        self.tv.setItemDelegateForColumn(0, MyButtonDelegate(self.tv))
        self.setDelegate127(0)
        self.tv.setCurrentIndex(self.Model.createIndex(0, 3))

        # 设置各种代理
        de_bool = myDe.JPDelegate_ComboBox(self.tv, [['SIM', 1], ['Non', 0]])
        de_date = myDe.JPDelegate_DateEdit(self.tv)
        de_int = myDe.JPDelegate_LineEdit(self.tv, 1)
        de_float = myDe.JPDelegate_LineEdit(self.tv, 2)
        de_str = myDe.JPDelegate_LineEdit(self.tv)
        self.des = {
            JPFieldType.Other: de_str,
            JPFieldType.String: de_str,
            JPFieldType.Int: de_int,
            JPFieldType.Float: de_float,
            JPFieldType.Boolean: de_bool,
            JPFieldType.Date: de_date
        }
        for fld in self.tabinfo.Fields:
            if fld.RowSource:
                fld.TypeCode = 9999
                tempde = myDe.JPDelegate_ComboBox(self.tv, fld.RowSource)
                self.des[fld.FieldName] = tempde