프로젝트

일반

사용자정보

개정판 aa67ab4f

IDaa67ab4f22c16347e3fcfd258d50b3896a84a85a
상위 85340c7c
하위 d1566ccd

gaqhf 이(가) 6년 이상 전에 추가함

dev issue #581: Line Property 관련 Code Table UI 및 기능 개발

차이점 보기:

DTI_PID/DTI_PID/AppDocData.py
1418 1418
        return result
1419 1419

  
1420 1420
    '''
1421
        @brief      set Fluid Code
1421
        @brief      Set Common Code Data
1422 1422
        @author     kyouho
1423
        @date       2018.07.03
1423
        @date       2018.07.12
1424 1424
    '''
1425
    def setFluidCodeData(self, addDataList, removeDataList):
1425
    def setCommonCodeData(self, tableName, datas):
1426 1426
        try:
1427 1427
            # Creates or opens a file called mydb with a SQLite3 DB
1428 1428
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), 'ITI_PID.db')
......
1430 1430
            # Get a cursor object
1431 1431
            cursor = conn.cursor()
1432 1432

  
1433
            for data in addDataList:
1434
                uid = data.uid
1433
            for data in datas:
1434
                uid = data[0]
1435 1435
                if not uid:
1436
                    sql = "insert or replace into FluidCode(UID, CODE, DESCRIPTION) values(lower(hex(randomblob(16))), ?, ?)"
1437
                    param = (data.code, data.description)
1436
                    sql = "insert or replace into {}(UID, CODE, DESCRIPTION) values(lower(hex(randomblob(16))), ?, ?)".format(tableName)
1437
                    param = (data[1], data[2])
1438 1438
                else:
1439
                    sql = "update FluidCode SET CODE=?, DESCRIPTION=? WHERE UID = ?"
1440
                    param = (data.code, data.description, data.uid)
1439
                    sql = "update {} SET CODE=?, DESCRIPTION=? WHERE UID = ?".format(tableName)
1440
                    param = (data[1], data[2], data[0])
1441 1441
                cursor.execute(sql, param)
1442 1442

  
1443
            for data in removeDataList:
1444
                uid = data.uid
1443
            conn.commit()
1444
        
1445
        # Catch the exception
1446
        except Exception as ex:
1447
            # Roll back any change if something goes wrong
1448
            conn.rollback()
1449
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
1450
        finally:
1451
            # Close the db connection
1452
            conn.close()
1453

  
1454
    '''
1455
        @brief      Set Common Code Data
1456
        @author     kyouho
1457
        @date       2018.07.12
1458
    '''
1459
    def deleteCommonCodeData(self, datas):
1460
        try:
1461
            # Creates or opens a file called mydb with a SQLite3 DB
1462
            dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), 'ITI_PID.db')
1463
            conn = sqlite3.connect(dbPath)
1464
            # Get a cursor object
1465
            cursor = conn.cursor()
1466

  
1467
            for data in datas:
1468
                uid = data[0]
1469
                tableName = data[1]
1470

  
1445 1471
                if uid:
1446
                    sql = "delete from FluidCode where UID = ?"
1472
                    sql = "delete from {} where UID = ?".format(tableName)
1447 1473
                    param = (uid,)
1448 1474
                    cursor.execute(sql, param)
1449 1475

  
1476
                cursor.execute(sql, param)
1477

  
1450 1478
            conn.commit()
1451 1479
        
1452 1480
        # Catch the exception
DTI_PID/DTI_PID/CodeTableDialog.py
28 28
        
29 29

  
30 30

  
31

  
32

  
33 31
    '''
34 32
        @brief      Setting Table
35
        @author     humkyung
36
        @date       2018.06.28
33
        @author     kyouho
34
        @date       2018.07.10
37 35
    '''
38 36
    def settingTable(self, tableName):
39
        tableName = tableName.replace(' ','')
40
        docData = AppDocData.instance()
41
        if tableName == "NominalDiameter":
42
            tableDatas = docData.getNomialPipeSizeData()
43
        else:
44
            tableDatas = docData.getCodeTable(tableName)
45

  
46
        if tableName == "NominalDiameter":
47
            self.insertTableWidgetNominalPipeSizeRow(tableDatas)
48
        else:
37
        try:
38
            tableName = self.replaceText(tableName)
39
            docData = AppDocData.instance()
49 40
            table = self.findTableWidget(tableName)
50
            if table:
41
            if tableName == "NominalDiameter":
42
                tableDatas = docData.getNomialPipeSizeData()
43
            else:
44
                tableDatas = docData.getCodeTable(tableName)
45

  
46
            if tableName == "NominalDiameter":
47
                self.insertTableWidgetNominalPipeSizeRow(tableDatas)
48

  
49
                table.cellChanged.connect(self.cellValueChanged)
50
                self.checkRowAndAddRow(tableName, table)
51
            else:
51 52
                table.setColumnCount(3)
52 53
                table.setHorizontalHeaderLabels(['uid', 'Code', 'Desc.'])
54
                table.hideColumn(0)
55

  
53 56
                self.insertTableWidgetCommonRow(table, tableDatas)
54
                self.setCurrentCode(table, tableName)
55 57
                
56
                table.horizontalHeaderItem(0).setSizeHint(QSize(30, 30))
58
                table.horizontalHeaderItem(1).setSizeHint(QSize(30, 30))
57 59
                table.cellChanged.connect(self.cellValueChanged)
58
                self.checkRowAndAddRow(table)
60
                self.checkRowAndAddRow(tableName, table)
61
                self.setCurrentCode(table, tableName)
62
        except Exception as ex:
63
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
64

  
65

  
59 66
    '''
60 67
        @brief      Insert row NominalPipeSzie Tablewidget
61 68
        @author     kyouho
62 69
        @date       2018.07.10
63 70
    '''
64 71
    def insertTableWidgetNominalPipeSizeRow(self, pipeSizes):
65
        self.ui.tableWidgetNominalDiameter.setColumnCount(5)
66
        self.ui.tableWidgetNominalDiameter.setHorizontalHeaderLabels(['Code', 'Metric', 'Inch', 'InchStr', 'MetricStr'])
67
        self.ui.tableWidgetNominalDiameter.setRowCount(len(pipeSizes))
68
        row = 0
69
        for pipeSize in pipeSizes:
70
            self.ui.tableWidgetNominalDiameter.setItem(row, 0, QTableWidgetItem(pipeSize.code))
71
            self.ui.tableWidgetNominalDiameter.setItem(row, 1, QTableWidgetItem(str(pipeSize.metric)))
72
            self.ui.tableWidgetNominalDiameter.setItem(row, 2, QTableWidgetItem(str(pipeSize.inch)))
73
            self.ui.tableWidgetNominalDiameter.setItem(row, 3, QTableWidgetItem('' if pipeSize.inchStr is None else pipeSize.inchStr))
74
            self.ui.tableWidgetNominalDiameter.setItem(row, 4, QTableWidgetItem('' if pipeSize.metricStr is None else pipeSize.metricStr))
75
            row += 1
72
        try:
73
            self.ui.tableWidgetNominalDiameter.setColumnCount(5)
74
            self.ui.tableWidgetNominalDiameter.setHorizontalHeaderLabels(['Code', 'Metric', 'Inch', 'InchStr', 'MetricStr'])
75
            self.ui.tableWidgetNominalDiameter.setRowCount(len(pipeSizes))
76
            row = 0
77
            for pipeSize in pipeSizes:
78
                self.ui.tableWidgetNominalDiameter.setItem(row, 0, QTableWidgetItem(pipeSize.code))
79
                self.ui.tableWidgetNominalDiameter.setItem(row, 1, QTableWidgetItem(str(pipeSize.metric)))
80
                self.ui.tableWidgetNominalDiameter.setItem(row, 2, QTableWidgetItem(str(pipeSize.inch)))
81
                self.ui.tableWidgetNominalDiameter.setItem(row, 3, QTableWidgetItem('' if pipeSize.inchStr is None else pipeSize.inchStr))
82
                self.ui.tableWidgetNominalDiameter.setItem(row, 4, QTableWidgetItem('' if pipeSize.metricStr is None else pipeSize.metricStr))
83
                row += 1
84

  
85
            self.ui.tableWidgetNominalDiameter.horizontalHeaderItem(0).setSizeHint(QSize(30, 30))
86
        except Exception as ex:
87
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
88

  
76 89

  
77
        self.ui.tableWidgetNominalDiameter.horizontalHeaderItem(0).setSizeHint(QSize(30, 30))
78 90

  
79 91
    '''
80 92
        @brief      Insert row Common Tablewidget
......
82 94
        @date       2018.07.10
83 95
    '''
84 96
    def insertTableWidgetCommonRow(self, table, tableDatas):
85
        table.setRowCount(len(tableDatas))
86
        row = 0
87
        for tableData in tableDatas:
88
            table.setItem(row, 0, QTableWidgetItem(tableData[0]))
89
            table.setItem(row, 1, QTableWidgetItem(tableData[1]))
90
            table.setItem(row, 2, QTableWidgetItem(tableData[2]))
91
            row += 1
97
        try:
98
            table.setRowCount(len(tableDatas))
99
            row = 0
100
            for tableData in tableDatas:
101
                table.setItem(row, 0, QTableWidgetItem(tableData[0]))
102
                table.setItem(row, 1, QTableWidgetItem(tableData[1]))
103
                table.setItem(row, 2, QTableWidgetItem(tableData[2]))
104
                row += 1
105
        except Exception as ex:
106
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
107

  
108

  
92 109

  
93 110

  
94 111
    '''
......
97 114
        @date       2018.07.10
98 115
    '''
99 116
    def findTableWidget(self, tableName):
100
        tableName = tableName.replace(' ','').replace('&&', 'n')
117
        tableName = self.replaceText(tableName)
101 118
        return self.findChild(QTableWidget, 'tableWidget' + tableName)
102 119

  
103 120
    '''
......
110 127
            if e.key() == Qt.Key_Delete:
111 128
                _tabWidget = self.ui.tabWidget
112 129
                currentTabIndex = _tabWidget.currentIndex()
113
                tabText = _tabWidget.tabText(currentTabIndex)
130
                tabText = self.replaceText(_tabWidget.tabText(currentTabIndex))
114 131
                table = self.findTableWidget(tabText)
115 132
                if table:
116 133
                    selectedIndexes = table.selectedIndexes()
......
125 142
                    rowsIndex = list(set(rowsIndex))
126 143
                    rowsIndex.reverse()
127 144
                    
128
                    if tabText != "Nominal Diameter":
145
                    if tabText != "NominalDiameter":
129 146
                        for row in rowsIndex:
130 147
                            uid = table.item(row, 0).text()
131 148
                            self.removeUID[uid] = tabText
132 149
                            model.removeRow(row)
133 150

  
134
                        self.checkRowAndAddRow(table)
151
                        self.checkRowAndAddRow(tabText, table)
135 152
                    
136

  
153
                         
137 154
        except Exception as ex:
138 155
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
139 156

  
140 157
    '''
141 158
        @brief      Add new row
142 159
        @author     kyouho
143
        @date       2018.07.04
160
        @date       2018.07.10
144 161
    '''
145
    def checkRowAndAddRow(self, table):
162
    def checkRowAndAddRow(self, tableName, table):
146 163
        try:
147 164
            rowCount = table.rowCount()
148 165
            result = True
149
            for row in range(rowCount):
150
                code = table.item(row, 1).text()
151
                if not code:
152
                    result = False
153

  
154
            if result:
155
                table.cellChanged.disconnect(self.cellValueChanged)
156
                table.setRowCount(rowCount + 1)
157
                table.setItem(rowCount, 0, QTableWidgetItem(''))
158
                table.setItem(rowCount, 1, QTableWidgetItem(''))
159
                table.setItem(rowCount, 2, QTableWidgetItem(''))
160
                table.cellChanged.connect(self.cellValueChanged)
166
            if tableName != "NominalDiameter":
167
                for row in range(rowCount):
168
                    code = table.item(row, 1).text()
169
                    if not code:
170
                        result = False
171
                if result:
172
                    table.cellChanged.disconnect(self.cellValueChanged)
173
                    table.setRowCount(rowCount + 1)
174
                    table.setItem(rowCount, 0, QTableWidgetItem(''))
175
                    table.setItem(rowCount, 1, QTableWidgetItem(''))
176
                    table.setItem(rowCount, 2, QTableWidgetItem(''))
177
                    table.cellChanged.connect(self.cellValueChanged)
178
            else:
179
                columnCount = table.columnCount()
180

  
181
                for row in range(rowCount):
182
                    if not result:
183
                        break
184
                    for columnIndex in range(columnCount):
185
                        if not table.item(row, columnIndex).text():
186
                            result = False
187
                            break
188
 
189
                if result:
190
                    table.setRowCount(rowCount + 1)
191
                    table.cellChanged.disconnect(self.cellValueChanged)
192
                    for columnIndex in range(columnCount):
193
                        table.setItem(rowCount, columnIndex, QTableWidgetItem(''))    
194
                    table.cellChanged.connect(self.cellValueChanged)
161 195
            
162 196
        except Exception as ex:
163 197
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
......
165 199
    '''
166 200
        @brief      cellValueChange event
167 201
        @author     kyouho
168
        @date       2018.07.03
202
        @date       2018.07.10
169 203
    '''
170 204
    def cellValueChanged(self, row, column):
171 205
        try:
172 206
            _tabWidget = self.ui.tabWidget
173 207
            currentTabIndex = _tabWidget.currentIndex()
174
            tabText = _tabWidget.tabText(currentTabIndex).replace(' ', '').replace('&&', 'n')
208
            tabText = self.replaceText(_tabWidget.tabText(currentTabIndex))
175 209
            table = self.findTableWidget(tabText)
176 210

  
177 211
            if tabText != "NominalDiameter":
......
180 214
                if column == 1:
181 215
                    result = self.isExistCode(table, code)
182 216
                    if result:
183
                        self.checkRowAndAddRow(table)
217
                        self.checkRowAndAddRow(tabText, table)
184 218
                        self.setCurrentCode(table, tabText)
185 219
                    else:
186 220
                        item.setText(self.currentCode[tabText][row])
187 221
                else:
188 222
                    table.resizeColumnToContents(2)
223
            else:
224
                self.checkRowAndAddRow(tabText, table)
189 225

  
190 226
        except Exception as ex:
191 227
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
......
193 229
    '''
194 230
        @brief      Check  Duplicate Code 
195 231
        @author     kyouho
196
        @date       2018.07.03
232
        @date       2018.07.10
197 233
    '''
198 234
    def isExistCode(self, table, editCode):
199 235
        try:
......
219 255
    '''
220 256
        @brief      save current Code (self.currentCode)
221 257
        @author     kyouho
222
        @date       2018.07.03
258
        @date       2018.07.10
223 259
    '''
224 260
    def setCurrentCode(self, table, tabText):
225 261
        try:
......
236 272
        except Exception as ex:
237 273
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
238 274

  
275
    
276
    '''
277
        @brief      replaceTextForCodeTable
278
        @author     kyouho
279
        @date       2018.07.12
280
    '''
281
    def replaceText(self, text):
282
        return text.replace(' ','').replace('&&', 'n')
283

  
239 284

  
240 285
    '''
241
        @brief      
242
        @author     humkyung
243
        @date       2018.06.28
286
        @brief      save codes
287
        @author     kyouho
288
        @date       2018.07.12
244 289
    '''
245 290
    def accept(self):
246
        pass
291

  
292
        self.saveCommonCodeData("Fluid Code")
293
        self.saveCommonCodeData("Insulation Purpose")
294
        self.saveCommonCodeData("PnID NUMBER")
295
        self.saveCommonCodeData("Piping Materials Class")
296
        self.saveCommonCodeData("UNIT NUMBER")
297

  
298
        self.deleteCommonCodeData()
299

  
300
        QDialog.accept(self)
301

  
302
    '''
303
        @brief      save common code data
304
        @author     kyouho
305
        @date       2018.07.12
306
    '''
307
    def saveCommonCodeData(self, tableName):
308
        datas = []
309
        try:
310
            tableName = self.replaceText(tableName)
311
            table = self.findTableWidget(tableName)
312
            rowCount = table.rowCount()
313
            for row in range(rowCount):
314
                uid = table.item(row, 0).text()
315
                code = table.item(row, 1).text()
316
                description = table.item(row, 2).text()
317

  
318
                if code:
319
                    datas.append((uid, code, description))
320

  
321
            docData = AppDocData.instance()
322
            docData.setCommonCodeData(tableName, datas)
323

  
324
        except Exception as ex:
325
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
326

  
327
    '''
328
        @brief      save common code data
329
        @author     kyouho
330
        @date       2018.07.12
331
    '''
332
    def deleteCommonCodeData(self):
333
        try:
334
            datas = self.removeUID.items()
335
            docData = AppDocData.instance()
336
            docData.deleteCommonCodeData(datas)
337
        except Exception as ex:
338
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
339

  
340
        
341

  
342

  
343

  

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)