jeudi 13 février 2020

Best way to use a PyQt5 Model within a PyQt5 TreeModel

I have a code structure already using SQLAlchemy to make declarative models.

Example Tables/Models:

  • Repository
    • repository_id
    • name
    • owner
  • Endpoint
    • endpoint_id
    • name
    • method
  • Contexts
    • context_id
    • endpoint_id
    • parent_context_id
    • config
    • created_on
    • created_by

I'd like to make a QtTree to select a Repository > Endpoint > Context > Nested Context.

Similar to how an IDE may have a browser view that shows both folders/packages/files and give different right-click menus to each.

I'm trying to understand what the "proper" way of implementing this would be.

I've looked at GitHub to see what other people have done, but most of small open source apps just use a TreeWidget and have more or less hard-coded views or large projects like "Eric" which are doing things like Lazy Loading... and I'm not sure if it's total overkill for what I'm looking to do -- the 1700+ lines of custom implementation code in Eric has seemed to give more feedback than anything else I've seen... but I still have the issue that my model issue is already semi-defined once...

Since I'm primarily using SQLAlchemy for the rest of the application, should I first create/use a "SqlAlchemyTableModel" to scaffold each model, then create a "BrowserModel" that performs the logic to create these?

Should the RepositoryModel/EndpointModel/ContextModel be a subclass, or is it sufficient to just create them through a generic class?

Ideally I'd like the Repository/Endpoint/Etc to have different icons in the list and different ContextMenus. Should these be set in their model? Through the parent model? Through a decorator proxy? Through view delegates?

I feel like I have a million hammers but I have no clue if what I'm looking at is a nail or a screw.

Reference: https://github.com/davy39/eric/blob/master/UI/BrowserModel.py

Aucun commentaire:

Enregistrer un commentaire