Suspicious of calling saveIt() in the AbstractModel via the QtableView nested button. I wonder if its causing the initial load-up of the CSV data to overwrite any editing just before save?
If this is the case, how can such be avoided?
Button call function in QtableView:
@QtCore.pyqtSlot()
def on_pushButtonSave_clicked(self):
CSVModel(self).saveIt()
@QtCore.pyqtSlot()
def on_pushButtonSave_clicked(self):
CSVModel(self).saveIt()
To copy to clipboard, switch view to plain text mode
__init__ for AbstractTableModel, and subsequent saveIt() function therein:
def __init__(self, fileName, parent=None):
super(CSVModel,self).__init__()
self.header = []
self.rows = []
self.fileName = r'E:\Documents\SIUC\2014\Fall\440 - Hydro\QGIS\test_bay\CSVtesting\mfLayer1_Grid.csv'
with open(self.fileName, "rb") as fileInput:
for idx, row in enumerate(csv.reader(fileInput)):
headerIDx = 0
if idx is headerIDx:
self.header.append(row)
elif idx>headerIDx:
items = [field for field in row]
self.rows.append(items)
self.rowsLoaded = CSVModel.activeRows
def __init__(self, fileName, parent=None):
super(CSVModel,self).__init__()
self.header = []
self.rows = []
self.fileName = r'E:\Documents\SIUC\2014\Fall\440 - Hydro\QGIS\test_bay\CSVtesting\mfLayer1_Grid.csv'
with open(self.fileName, "rb") as fileInput:
for idx, row in enumerate(csv.reader(fileInput)):
headerIDx = 0
if idx is headerIDx:
self.header.append(row)
elif idx>headerIDx:
items = [field for field in row]
self.rows.append(items)
self.rowsLoaded = CSVModel.activeRows
To copy to clipboard, switch view to plain text mode
def saveIt(self):
with open(self.fileName, "wb") as fileOutput:
writer = csv.writer(fileOutput)
writer.writerow(self.header[0])
for rowNumber in range(len(self.rows)):
fields = self.rows[rowNumber]
writer.writerow(fields)
def saveIt(self):
with open(self.fileName, "wb") as fileOutput:
writer = csv.writer(fileOutput)
writer.writerow(self.header[0])
for rowNumber in range(len(self.rows)):
fields = self.rows[rowNumber]
writer.writerow(fields)
To copy to clipboard, switch view to plain text mode
Bookmarks