-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomModel.py
735 lines (633 loc) · 27.1 KB
/
CustomModel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# IMPORTS FOR GUI
from PySide2 import QtWidgets
from PySide2 import QtCore
from PySide2 import QtGui
import databaseOperations
from PySide2.QtGui import QBrush,QColor
# IMPORTS FOR DATABASE MODEL
import databaseOperations
from Database import *
class CustomTableModel(QtCore.QAbstractTableModel):
"""
Class to create custom table model
"""
def __init__(self,table):
QtCore.QAbstractTableModel.__init__(self)
self.table_name = table.name
self.user_data = databaseOperations.get_multiple_data(self.table_name)
self.columns = table.headers
self.column_names = table.column_names
def flags(self, index):
"""
Will set the flags for the table cells
@param index: index of the cell
make first column non editable
"""
# print(index.column())
if index.column() > 0:
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
# elif index.column() == 1:
# return QtCore.Qt.DecorationRole
else:
return QtCore.Qt.ItemIsSelectable
def rowCount(self, *args, **kwargs):
"""
Will count number of rows in the table
@param args:
@return: row count
"""
return len(self.user_data)
def columnCount(self, *args, **kwargs):
"""
Will count number of columns in the table
@param args:
@return: column count
"""
return len(self.columns)
def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
"""
Will set the header data for the table
@param section: section of the table
@param orientation: orientation of the table
@param role: role of the table
@return: header data
"""
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
# print(self.columns[section])
return self.columns[section]
def data(self, index, role):
"""
Will return the data in the table cells
@param index: index of the cell
@param role: role of the cell
@return: data in the cell
"""
row = self.user_data[index.row()]
column = self.columns[index.column()]
if role == QtCore.Qt.TextAlignmentRole:
return QtCore.Qt.AlignCenter
try:
if role == QtCore.Qt.DisplayRole:
if(row[index.column()]!= None):
return (row[index.column()])
else:
return ""
except KeyError:
return None
def setData(self, index, value, role=QtCore.Qt.EditRole):
"""
Will set the data in the table cells
@param index: index of the cell
@param value: value to be set in the cell
@param role: role of the cell
@return: True if data is set
"""
if index.isValid():
selected_row = self.user_data[index.row()]
selected_column = self.columns[index.column()]
new_data = list(selected_row)
new_data[index.column()] = value
self.dataChanged.emit(index, index, (QtCore.Qt.DisplayRole, ))
# if new_data[0] != "":
ok = databaseOperations.update_existing(new_data[0], new_data[1:],self.column_names,self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
if ok:
return True
return False
def insertRows(self):
row_count = len(self.user_data)
self.beginInsertRows(QtCore.QModelIndex(), row_count, row_count)
empty_data = []
for key in self.columns:
if not key =='id_':
empty_data.append("")
document_id = databaseOperations.insert_data(empty_data,self.column_names,self.table_name)
row_count += 1
new_data = databaseOperations.get_single_data(row_count,self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
self.endInsertRows()
return True
def insertRows_vendor_part(self,details):
row_count = len(self.user_data)
self.beginInsertRows(QtCore.QModelIndex(), row_count, row_count)
empty_data = []
if len(details) == 1: #Vendor
for key in self.columns:
if not key =='id_':
if key =="Vendor Name":
empty_data.append(str(details[0]))
else:
empty_data.append("")
print(empty_data)
document_id = databaseOperations.insert_data(empty_data,self.column_names,self.table_name)
else:
for key in self.columns:
if not key == 'id_':
if key =="Part Name":
empty_data.append(str(details[0]))
elif key == "Vehicle Type":
empty_data.append(str(details[1]))
else:
empty_data.append("")
document_id = databaseOperations.insert_data(empty_data,self.column_names,self.table_name)
row_count += 1
new_data = databaseOperations.get_single_data(row_count,self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
self.endInsertRows()
return True
def removeRows(self, position):
row_count = self.rowCount()
row_count -= 1
self.beginRemoveRows(QtCore.QModelIndex(), row_count, row_count)
if isinstance(position,int):
document_id = self.user_data[position][0]
databaseOperations.remove_data(document_id,self.table_name)
elif isinstance(position,QtCore.QModelIndex):
row_id = position.row()
document_id = self.user_data[row_id][0]
databaseOperations.remove_data(document_id,self.table_name)
elif isinstance(position,list):
for data in self.user_data:
k = 0
for i in range(len(position)):
if data[i+1] == position[i].data():
k+=1
if(k == len(position)):
rowid = data[0]
databaseOperations.remove_data(rowid,self.table_name)
else:
return False
self.user_data = databaseOperations.get_multiple_data(self.table_name)
# print(self.user_data)
self.endRemoveRows()
return True
def removeRows_fromList(self,details,position):
row_count = self.rowCount()
row_count -= 1
self.beginRemoveRows(QtCore.QModelIndex(), row_count, row_count)
if len(details) == 1: #Vendor
databaseOperations.remove_data_from_list(details,[position[0],position[1]],self.table_name)
else:
databaseOperations.remove_data_from_list(details,[position[0]],self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
# print(self.user_data)
self.endRemoveRows()
return True
def removeRows_vendor_part(self,details):
row_count = self.rowCount()
row_count -= 1
self.beginRemoveRows(QtCore.QModelIndex(), row_count, row_count)
if len(details) == 1: #Vendor
databaseOperations.remove_data_vendor_part(details,self.table_name)
else:
databaseOperations.remove_data_vendor_part(details,self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
# print(self.user_data)
self.endRemoveRows()
return True
class CustomTableModelThreshold(QtCore.QAbstractTableModel):
"""
Custom Table Model
"""
def __init__(self,table):
QtCore.QAbstractTableModel.__init__(self)
self.table_name = table.name
self.user_data = databaseOperations.get_multiple_data(self.table_name)
self.columns = table.headers
self.column_names = table.column_names
def flags(self, index):
"""
Will make the table editable
@param index: index of the cell
@return: flags of the cell
"""
# print(index.column())
if index.column() > 0:
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
# elif index.column() == 1:
# return QtCore.Qt.DecorationRole
else:
return QtCore.Qt.ItemIsSelectable
def rowCount(self, *args, **kwargs):
"""
Will return the number of rows in the table
@param args:
@param kwargs:
@return: number of rows in the table
"""
return len(self.user_data)
def columnCount(self, *args, **kwargs):
"""
Will set the number of columns in the table
@param args:
@param kwargs:
@return: number of columns in the table
"""
return len(self.columns)
def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
"""
Will set the header of the table
@param section: section of the table
@param orientation: orientation of the table
@param role: role of the table
@return: header of the table
"""
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
# print(self.columns[section])
return self.columns[section]
def data(self, index, role):
"""
Will define the data of the table
@param index: index of the cell
@param role: role of the cell
@return: data of the cell
"""
row = self.user_data[index.row()]
column = self.columns[index.column()]
if role == QtCore.Qt.BackgroundRole:
if databaseOperations.get_stocksum([self.user_data[index.row()][2],self.user_data[index.row()][3]]) < databaseOperations.get_threshold([self.user_data[index.row()][2],self.user_data[index.row()][3]]):
return QBrush(QColor(QtCore.Qt.red))
if role == QtCore.Qt.TextAlignmentRole:
return QtCore.Qt.AlignCenter
try:
if role == QtCore.Qt.DisplayRole:
if(row[index.column()]!= None):
return (row[index.column()])
else:
return ""
except KeyError:
return None
def setData(self, index, value, role=QtCore.Qt.EditRole):
"""
Will edit data in table cells
@param index: index of the cell
@param value: value of the cell
@param role: role of the cell
@return: True if successful
"""
if index.isValid():
selected_row = self.user_data[index.row()]
selected_column = self.columns[index.column()]
new_data = list(selected_row)
new_data[index.column()] = value
self.dataChanged.emit(index, index, (QtCore.Qt.DisplayRole, ))
# if new_data[0] != "":
ok = databaseOperations.update_existing(new_data[0], new_data[1:],self.column_names,self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
if ok:
return True
return False
def insertRows(self):
row_count = len(self.user_data)
self.beginInsertRows(QtCore.QModelIndex(), row_count, row_count)
empty_data = []
for key in self.columns:
if not key =='id_':
empty_data.append("")
document_id = databaseOperations.insert_data(empty_data,self.column_names,self.table_name)
row_count += 1
new_data = databaseOperations.get_single_data(row_count,self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
self.endInsertRows()
return True
def insertRows_vendor_part(self,details):
row_count = len(self.user_data)
self.beginInsertRows(QtCore.QModelIndex(), row_count, row_count)
empty_data = []
if len(details) == 1: #Vendor
for key in self.columns:
if not key =='id_':
if key =="Vendor Name":
empty_data.append(str(details[0]))
else:
empty_data.append("")
print(empty_data)
document_id = databaseOperations.insert_data(empty_data,self.column_names,self.table_name)
else:
for key in self.columns:
if not key == 'id_':
if key =="Part Name":
empty_data.append(str(details[0]))
elif key == "Vehicle Type":
empty_data.append(str(details[1]))
else:
empty_data.append("")
document_id = databaseOperations.insert_data(empty_data,self.column_names,self.table_name)
row_count += 1
new_data = databaseOperations.get_single_data(row_count,self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
self.endInsertRows()
return True
def removeRows(self, position):
row_count = self.rowCount()
row_count -= 1
self.beginRemoveRows(QtCore.QModelIndex(), row_count, row_count)
if isinstance(position,int):
document_id = self.user_data[position][0]
databaseOperations.remove_data(document_id,self.table_name)
elif isinstance(position,QtCore.QModelIndex):
row_id = position.row()
document_id = self.user_data[row_id][0]
databaseOperations.remove_data(document_id,self.table_name)
elif isinstance(position,list):
for data in self.user_data:
k = 0
for i in range(len(position)):
if data[i+1] == position[i].data():
k+=1
if(k == len(position)):
rowid = data[0]
databaseOperations.remove_data(rowid,self.table_name)
else:
return False
self.user_data = databaseOperations.get_multiple_data(self.table_name)
# print(self.user_data)
self.endRemoveRows()
return True
def removeRows_fromList(self,details,position):
row_count = self.rowCount()
row_count -= 1
self.beginRemoveRows(QtCore.QModelIndex(), row_count, row_count)
if len(details) == 1: #Vendor
databaseOperations.remove_data_from_list(details,[position[0],position[1]],self.table_name)
else:
databaseOperations.remove_data_from_list(details,[position[0]],self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
# print(self.user_data)
self.endRemoveRows()
return True
def removeRows_vendor_part(self,details):
row_count = self.rowCount()
row_count -= 1
self.beginRemoveRows(QtCore.QModelIndex(), row_count, row_count)
if len(details) == 1: #Vendor
databaseOperations.remove_data_vendor_part(details,self.table_name)
else:
databaseOperations.remove_data_vendor_part(details,self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
# print(self.user_data)
self.endRemoveRows()
return True
class CustomTableModelUserData(QtCore.QAbstractTableModel):
"""
Custom Table Model for User Data
"""
def __init__(self, data,headers,column_names,table_name):
QtCore.QAbstractTableModel.__init__(self)
self.user_data = data
self.columns = headers
self.column_names = column_names
self.table_name = table_name
def flags(self, index):
"""
This function is used to set the flags for the table view
@param index: index of the table
@return: flags
"""
# print(index.column())
if index.column() > 0:
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
# elif index.column() == 1:
# return QtCore.Qt.DecorationRole
else:
return QtCore.Qt.ItemIsSelectable
def rowCount(self, *args, **kwargs):
"""
Will set row counts
@param args:
@param kwargs:
"""
return len(self.user_data)
def columnCount(self, *args, **kwargs):
return len(self.columns)
def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
# print(self.columns[section])
return self.columns[section]
def data(self, index, role):
row = self.user_data[index.row()]
column = self.columns[index.column()]
if role == QtCore.Qt.TextAlignmentRole:
return QtCore.Qt.AlignCenter
try:
if role == QtCore.Qt.DisplayRole:
if(row[index.column()]!= None):
return (row[index.column()])
else:
return ""
except KeyError:
return None
def setData(self, index, value, role=QtCore.Qt.EditRole):
if index.isValid():
selected_row = self.user_data[index.row()]
selected_column = self.columns[index.column()]
new_data = list(selected_row)
new_data[index.column()] = value
self.dataChanged.emit(index, index, (QtCore.Qt.DisplayRole, ))
ok = databaseOperations.update_existing(new_data[0], new_data[1:],self.column_names,self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
if ok:
return True
return False
def insertRows(self,invoice_number):
row_count = len(self.user_data)
self.beginInsertRows(QtCore.QModelIndex(), row_count, row_count)
empty_data = []
for key in self.columns:
if not key =='id_':
empty_data.append("")
document_id = databaseOperations.insert_data(empty_data,self.column_names,self.table_name)
row_count += 1
new_data = databaseOperations.get_single_data(row_count,self.table_name)
self.user_data = databaseOperations.get_multiple_data_invoice(invoice_number,self.table_name)
self.endInsertRows()
return True
def removeRows(self,invoice_number, position):
row_count = self.rowCount()
row_count -= 1
self.beginRemoveRows(QtCore.QModelIndex(), row_count, row_count)
row_id = position.row()
document_id = self.user_data[row_id][0]
# print("To be deleted: {}".format(document_id))
databaseOperations.remove_data(document_id,self.table_name)
self.user_data = databaseOperations.get_multiple_data_invoice(invoice_number,self.table_name)
# print(self.user_data)
self.endRemoveRows()
return True
class CustomTableModelNoDatabase(QtCore.QAbstractTableModel):
def __init__(self, data,headers,column_names,table_name):
QtCore.QAbstractTableModel.__init__(self)
self.user_data = data
self.columns = headers
self.column_names = column_names
self.table_name = table_name
def add_data(self,data):
self.user_data.append(data)
def flags(self, index):
# print(index.column())
if index.column() > 0:
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
# elif index.column() == 1:
# return QtCore.Qt.DecorationRole
else:
return QtCore.Qt.ItemIsSelectable
def rowCount(self, *args, **kwargs):
return len(self.user_data)
def columnCount(self, *args, **kwargs):
return len(self.columns)
def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
# print(self.columns[section])
return self.columns[section]
def data(self, index, role):
row = self.user_data[index.row()]
column = self.columns[index.column()]
if role == QtCore.Qt.TextAlignmentRole:
return QtCore.Qt.AlignCenter
try:
if role == QtCore.Qt.DisplayRole:
if(row[index.column()]!= None):
return (row[index.column()])
else:
return ""
except KeyError:
return None
def setData(self, index, value, role=QtCore.Qt.EditRole):
if index.isValid():
selected_row = self.user_data[index.row()]
selected_column = self.columns[index.column()]
new_data = list(selected_row)
new_data[index.column()] = value
# self.dataChanged.emit(index, index, (QtCore.Qt.DisplayRole, ))
# ok = databaseOperations.update_existing(new_data[0], new_data[1:],self.column_names,self.table_name)
# self.user_data = databaseOperations.get_multiple_data(self.table_name)
ok = True
if ok:
return True
return False
def insertRows(self,invoice_number):
row_count = len(self.user_data)
self.beginInsertRows(QtCore.QModelIndex(), row_count, row_count)
empty_data = []
for key in self.columns:
if not key =='id_':
empty_data.append("")
# document_id = databaseOperations.insert_data(empty_data,self.column_names,self.table_name)
row_count += 1
# new_data = databaseOperations.get_single_data(row_count,self.table_name)
self.user_data.append(new_data)
self.endInsertRows()
return True
def removeRows(self,invoice_number, position):
row_count = self.rowCount()
row_count -= 1
self.beginRemoveRows(QtCore.QModelIndex(), row_count, row_count)
row_id = position.row()
document_id = self.user_data[row_id][0]
# print("To be deleted: {}".format(document_id))
# databaseOperations.remove_data(document_id,self.table_name)
self.user_data.pop(row_id)
# print(self.user_data)
self.endRemoveRows()
return True
class CustomTableModelNoHeaders(QtCore.QAbstractTableModel):
def __init__(self,data,headers):
QtCore.QAbstractTableModel.__init__(self)
self.user_data = data
self.columns = headers
def flags(self, index):
"""
Make table editable.
make first column non editable
@param index: index of the cell
@return: flags
"""
# print(index.column())
if index.column() > 0:
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
# elif index.column() == 1:
# return QtCore.Qt.DecorationRole
else:
return QtCore.Qt.ItemIsSelectable
def rowCount(self, *args, **kwargs):
return len(self.user_data)
def columnCount(self, *args, **kwargs):
return len(self.columns)
def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
# print(self.columns[section])
return self.columns[section]
def data(self, index, role):
row = self.user_data[index.row()]
column = self.columns[index.column()]
if role == QtCore.Qt.TextAlignmentRole:
return QtCore.Qt.AlignCenter
try:
if role == QtCore.Qt.DisplayRole:
if(row[index.column()]!= None):
return (row[index.column()])
else:
return ""
except KeyError:
return None
def setData(self, index, value, role=QtCore.Qt.EditRole):
if index.isValid():
selected_row = self.user_data[index.row()]
selected_column = self.columns[index.column()]
new_data = list(selected_row)
new_data[index.column()] = value
self.dataChanged.emit(index, index, (QtCore.Qt.DisplayRole, ))
# if new_data[0] != "":
ok = databaseOperations.update_existing(new_data[0], new_data[1:],self.column_names,self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
if ok:
return True
return False
def insertRows(self):
row_count = len(self.user_data)
self.beginInsertRows(QtCore.QModelIndex(), row_count, row_count)
empty_data = []
for key in self.columns:
if not key =='id_':
empty_data.append("")
document_id = databaseOperations.insert_data(empty_data,self.column_names,self.table_name)
row_count += 1
new_data = databaseOperations.get_single_data(row_count,self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
self.endInsertRows()
return True
def removeRows(self, position):
row_count = self.rowCount()
row_count -= 1
self.beginRemoveRows(QtCore.QModelIndex(), row_count, row_count)
if isinstance(position,int):
document_id = self.user_data[position][0]
else:
row_id = position.row()
document_id = self.user_data[row_id][0]
# print("To be deleted: {}".format(document_id))
print(document_id)
databaseOperations.remove_data(document_id,self.table_name)
self.user_data = databaseOperations.get_multiple_data(self.table_name)
# print(self.user_data)
self.endRemoveRows()
return True
class ProfilePictureDelegate(QtWidgets.QStyledItemDelegate):
"""
This will open QFileDialog to select image
"""
def __init__(self):
QtWidgets.QStyledItemDelegate.__init__(self)
def createEditor(self, parent, option, index):
editor = QtWidgets.QFileDialog()
return editor
def setModelData(self, editor, model, index):
selected_file =editor.selectedFiles()[0]
image = open(selected_file, 'rb').read()
model.setData(index, image)
class InLineEditDelegate(QtWidgets.QItemDelegate):
def createEditor(self, parent, option, index):
return super(InLineEditDelegate, self).createEditor(parent, option, index)
def setEditorData(self, editor, index):
text = index.data(QtCore.Qt.EditRole) or index.data(QtCore.Qt.DisplayRole)
editor.setText(str(text))