u/PoopsInUrPee

Proxy Model or Normal Model For This?

(I'll provide code if requested, but this is more of a "philosophy" question in my opinion)

I have a subclassed QAbstractListModel which doesn't do anything special except for custom data roles. That model is used for a bunch of stuff, so it should be its own "thing."

But I'm also making an "editor" proxy model which takes the single-column source model, and adds additional columns for options such as "edit" "hide" "delete." This will be hooked up to a QTableView, and will have an item delegate drawing those additional options as buttons and, ideally, handling the click events via editorEvent.


So my question is about the "Editor" model. Since it refers to the source model, my instinct was to subclass a QAbstractProxyModel. mapToSource and mapFromSource hard-codes the column to 0 in both cases, since I can't properly map a column from a one-column model to a many-column model.

But then, in my delegate's editorEvent, the index I receive is correctly from the editor proxy model, but it's always column=0, so I can't determine which column/button was "pressed." It appears there are built-in mechanisms (which I didn't write) which cause the index to get mapped from source?

So, that's getting into some nasty territory in my opinion.

Alternatively, I could just subclass a QAbstractTableModel instead of a "real" proxy, and do it that way. But isn't that "incorrect" since it would be dependent upon a source model anyway?

reddit.com
u/PoopsInUrPee — 7 days ago

Efficiently using QFileSystemModel for watching several subfolders

I'm writing a program, and for many features, the user can save presets. Those presets are written to individual files in appropriate subfolders inside the application's local storage path. So on macos it might look like:

  • ~/Library/Application Support/MyOrg/MyProgram/themes
  • ~/Library/Application Support/MyOrg/MyProgram/filters
  • ~/Library/Application Support/MyOrg/MyProgram/sounds

For the user to select existing presets, I want to list the contents of the appropriate subfolder in a QComboBox. I want the combo boxes to update live.

So I can do this if I create a QFileSystemModel for every combo box and set its root path to each subfolder and set each combo box root index to the index of that model. But that seems inefficient, especially since on some platforms, file watchers are limited.

So I tried making a QSortFilterProxyModel, and for filterAcceptsRow, I tried taking the source parent index, getting the Roles.FilePathRole, and comparing it to the path of the subfolder I want to watch for each QComboBox. But the way the file system model populates data is apparently async, so I'm hitting all kinds of invalid index issues getting this to work.

The user may have many multiple instances of the main window open, so the number of combo boxes needed to show preset selections can grow pretty large. So I want to approach this with SOME sort of attempt at optimization.

Am I approaching things the wrong way here?

reddit.com
u/PoopsInUrPee — 14 days ago