refactor: move more tied logic to model and move logic to the resources
This moves the QSortFilterProxyModel to the resource model files, acessible via a factory method, and moves the sorting and filtering to the objects themselves, decoupling the code a bit. This also adds a basic implementation of methods in the ResourceFolderModel, simplifying the process of constructing a new model from it. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
@ -14,6 +14,13 @@ enum class ResourceType {
|
||||
LITEMOD, //!< The resource is a litemod
|
||||
};
|
||||
|
||||
enum class SortType {
|
||||
NAME,
|
||||
DATE,
|
||||
VERSION,
|
||||
ENABLED,
|
||||
};
|
||||
|
||||
/** General class for managed resources. It mirrors a file in disk, with some more info
|
||||
* for display and house-keeping purposes.
|
||||
*
|
||||
@ -40,6 +47,20 @@ class Resource : public QObject {
|
||||
[[nodiscard]] virtual auto name() const -> QString { return m_name; }
|
||||
[[nodiscard]] virtual bool valid() const { return m_type != ResourceType::UNKNOWN; }
|
||||
|
||||
/** Compares two Resources, for sorting purposes, considering a ascending order, returning:
|
||||
* > 0: 'this' comes after 'other'
|
||||
* = 0: 'this' is equal to 'other'
|
||||
* < 0: 'this' comes before 'other'
|
||||
*
|
||||
* The second argument in the pair is true if the sorting type that decided which one is greater was 'type'.
|
||||
*/
|
||||
[[nodiscard]] virtual auto compare(Resource const& other, SortType type = SortType::NAME) const -> std::pair<int, bool>;
|
||||
|
||||
/** Returns whether the given filter should filter out 'this' (false),
|
||||
* or if such filter includes the Resource (true).
|
||||
*/
|
||||
[[nodiscard]] virtual bool applyFilter(QRegularExpression filter) const;
|
||||
|
||||
[[nodiscard]] auto shouldResolve() const -> bool { return !m_is_resolving && !m_is_resolved; }
|
||||
[[nodiscard]] auto isResolving() const -> bool { return m_is_resolving; }
|
||||
[[nodiscard]] auto resolutionTicket() const -> int { return m_resolution_ticket; }
|
||||
|
Reference in New Issue
Block a user