Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brownnrl opened this issue Jul 29, 2015 · 2 comments
Closed
Labels

Comments

@brownnrl
Copy link
Contributor

@brownnrl brownnrl commented Jul 29, 2015

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
Copy link
Contributor Author

@brownnrl brownnrl commented Jul 29, 2015

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

@hsoft
Copy link
Owner

@hsoft 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 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
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants