mmatyas / pegasus-frontend

A cross platform, customizable graphical frontend for launching emulators and managing your game collection.
http://pegasus-frontend.org
Other
1.17k stars 104 forks source link

`extra` properties not available as filter roleName for SortFilterProxyModel #1107

Closed doakey3 closed 6 months ago

doakey3 commented 6 months ago

In my game metadata files, I have a property: x-ESRB with values like E, E10plus, T, M. I was wondering if I could filter the games by their ESRB rating using a SortFilterProxyModel, but I can't seem to figure out the proper role name to use. I've tried game.extra.ESRB, extra.ESRB, x-ESRB. I was referring to this page in the api: https://pegasus-frontend.org/docs/themes/api/

Here is the relevant section of code:

SortFilterProxyModel {
    id: filteredGames
    sourceModel: api.allGames
    filters: [
        RegExpFilter {
            roleName: "title" // <-- This works when this filter is enabled
            pattern: "^(The\\s)?L.*"
            caseSensitivity: Qt.CaseInsensitive
            enabled: false
        },
        RegExpFilter {
            roleName: "game.extra.ESRB" // <-- This does not work. Can I get it to work somehow?
            pattern: "^T"
            caseSensitivity: Qt.CaseInsensitive
            enabled: true
        }
    ]
}
doakey3 commented 6 months ago

This is solved by using an ExpressionFilter

SortFilterProxyModel {
    id: filteredGames
    sourceModel: api.allGames

    filters: [
        ExpressionFilter {
            expression: {
                if (window.esrb_filter == "none") {
                    return true
                }
                else if (window.esrb_filter == model.extra.esrb) {
                    return true
                }
                return false
            }
            enabled: true
        }
    ]
}