CSV Import - QAbstractTableModel has no reset method - modelReset replacement #440

Closed
brownnrl opened this Issue Jul 29, 2015 · 2 comments

Projects

None yet

2 participants

@brownnrl
Contributor

Ran into the following traceback while importing a CSV file:

Application Name: moneyGuru
Version: 2.9.3

Traceback (most recent call last):
  File "/home/nelson/projects/moneyguru/qt/controller/main_window.py", line 629, in importDocument
    self.model.parse_file_for_import(docpath)
  File "/home/nelson/projects/moneyguru/core/gui/main_window.py", line 479, in parse_file_for_import
    self.csv_options.show()
  File "/home/nelson/projects/moneyguru/core/gui/csv_options.py", line 211, in show
    self._refresh_columns()
  File "/home/nelson/projects/moneyguru/core/gui/csv_options.py", line 118, in _refresh_columns
    self.view.refresh_columns()
  File "/home/nelson/projects/moneyguru/qt/controller/import_/csv_options.py", line 153, in refresh_columns
    self.tableModel.reset()
AttributeError: 'CSVOptionsTableModel' object has no attribute 'reset'

It turns out QAbstractItemModel (and it's inheritance chain) no longer supports the deprecated reset method in PyQt5. At a minimum, the following re-definition of the reset method is necessary in QAbstractItemModel subclasses for PyQt5.

class ChildTable(QAbstractTableModel):
   # [... other methods / members ...]

    def reset(self):
        self.beginResetModel()
        # unnecessary call to actually clear data, but recommended by design guidance from Qt docs
        # left blank in preliminary testing
        self.endResetModel()

Will try to submit a PR against this ticket.

@brownnrl
Contributor

Obviously, this is against the master and not maintenance branch. I should have mentioned that.

@hsoft hsoft added bug ready qt labels Jul 29, 2015
@hsoft
Owner
hsoft commented Jul 29, 2015

Thanks for the catch. I had made the same fix during the Qt5 transition of dupeGuru, but it seems that I forgot about it this time. I didn't bother redefining reset(). I simply replaced the reset call by these two calls. Example at https://github.com/hsoft/dupeguru/blob/43974f9ebdcca8cc0dcabceafe385069ee85ffe4/qt/base/details_dialog.py#L44

@hsoft hsoft added this to the v2.10 milestone Jul 31, 2015
@hsoft hsoft added a commit that closed this issue Jan 10, 2016
@hsoft qt: fix crash on CSV import
fixes #440
69f1717
@hsoft hsoft closed this in 69f1717 Jan 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment