Limo
A simple mod manager
Loading...
Searching...
No Matches
modlistproxymodel.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include <QLabel>
9#include <QSortFilterProxyModel>
10
11
15class ModListProxyModel : public QSortFilterProxyModel
16{
17 Q_OBJECT
18public:
37
43 explicit ModListProxyModel(QLabel* row_count_label, QObject* parent = nullptr);
44
52 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
60 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
67 void setFilterMode(FilterMode mode, bool status, bool invalidate_filter = true);
73 void addFilter(FilterMode mode, bool invalidate_filter = true);
79 void removeFilter(FilterMode mode, bool invalidate_filter = true);
86 bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
91 void clearFilter(bool invalidate_filter = true);
96 int getFilterMode();
103 void addTagFilter(const QString& tag, bool include, bool invalidate_filter);
109 void removeTagFilter(const QString& tag, bool invalidate_filter);
111 void updateRowCountLabel();
116 bool isEditable() const;
121 std::vector<std::pair<QString, bool>> getTagFilters() const;
126 void setFilterString(const QString& filter_string);
127
128protected:
136 bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
137
138private:
145 std::vector<std::pair<QString, bool>> tag_filters_;
151 const QRegularExpression id_regex_;
158};
int getFilterMode()
Getter for the current filter mode.
Definition modlistproxymodel.cpp:127
const QRegularExpression id_regex_
Regex used to check if filter_string_ is used to filter for ids.
Definition modlistproxymodel.h:151
FilterMode
Describes different filter types.
Definition modlistproxymodel.h:21
@ filter_inactive
Show only mods not managed by any deployer.
Definition modlistproxymodel.h:27
@ filter_groups
Show only mods in groups.
Definition modlistproxymodel.h:23
@ filter_updates
Show only mods with available updates from their remote source.
Definition modlistproxymodel.h:33
@ filter_no_updates
Show only mods without available updates from their remote source.
Definition modlistproxymodel.h:35
@ filter_active
Show only mods managed by at least one deployer.
Definition modlistproxymodel.h:29
@ filter_tags
Show only mods with the given tags.
Definition modlistproxymodel.h:31
@ filter_no_groups
Show only mods without groups.
Definition modlistproxymodel.h:25
bool filter_string_is_int_
True if the current filter string is an integer.
Definition modlistproxymodel.h:153
bool filter_string_targets_id_
True if filter string matches id_regex_.
Definition modlistproxymodel.h:157
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
Compares two entries for sorting operations. Uses the base class implementation for all rows except f...
Definition modlistproxymodel.cpp:165
void updateRowCountLabel()
Updates the row count label with the current number of rows.
Definition modlistproxymodel.cpp:155
std::vector< std::pair< QString, bool > > tag_filters_
Contains every tag to be filtered as well as a bool indicating whether mods with that tag show be sho...
Definition modlistproxymodel.h:145
void setFilterString(const QString &filter_string)
Sets the string to use for filtering.
Definition modlistproxymodel.cpp:182
void setFilterMode(FilterMode mode, bool status, bool invalidate_filter=true)
Sets the given filter mode to the given status.
Definition modlistproxymodel.cpp:23
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
Checks if the given row will be accepted by the current filter.
Definition modlistproxymodel.cpp:60
std::vector< std::pair< QString, bool > > getTagFilters() const
Returns the currently set tag filters.
Definition modlistproxymodel.cpp:177
void clearFilter(bool invalidate_filter=true)
Resets the filter to allow all mods.
Definition modlistproxymodel.cpp:118
ModListProxyModel(QLabel *row_count_label, QObject *parent=nullptr)
Constructor.
Definition modlistproxymodel.cpp:8
bool isEditable() const
Returns true if the source model is editable;.
Definition modlistproxymodel.cpp:160
void addTagFilter(const QString &tag, bool include, bool invalidate_filter)
Adds a tag to the tag filters.
Definition modlistproxymodel.cpp:132
QString filter_string_
String used to filter rows.
Definition modlistproxymodel.h:149
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Maps the given index to the source mods index and sets its data to the given new data.
Definition modlistproxymodel.cpp:18
void removeTagFilter(const QString &tag, bool invalidate_filter)
Removes the filter for the given tag.
Definition modlistproxymodel.cpp:144
void addFilter(FilterMode mode, bool invalidate_filter=true)
Enables the given filter mode.
Definition modlistproxymodel.cpp:34
int filter_mode_
Contains the sum of all currently active filter modes.
Definition modlistproxymodel.h:140
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Maps the given index to the source models index and returns the source models data at that index.
Definition modlistproxymodel.cpp:13
QString filter_string_id_
If the current filter string is an integer, this contains that integer.
Definition modlistproxymodel.h:155
void removeFilter(FilterMode mode, bool invalidate_filter=true)
Disables the given filter mode.
Definition modlistproxymodel.cpp:49
QLabel * row_count_label_
Used to display to total number of rows.
Definition modlistproxymodel.h:147