Skip to content

Commit

Permalink
Fixed filtering button visible state
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLazarescu committed Jan 2, 2024
1 parent acae398 commit 01e6f60
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/adapters/data_models/library_model/library_proxy_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,19 @@ void LibraryProxyModel::setFilterRequest(QString authors, QString format,
.unread = unread,
};

emit filterUpdated();
invalidateFilter();
}

bool LibraryProxyModel::getIsFiltering()
{
return !m_filterRequest.authors.isEmpty() ||
!m_filterRequest.format.isEmpty() ||
!m_filterRequest.language.isEmpty() || m_filterRequest.onlyBooks ||
m_filterRequest.onlyFiles || m_filterRequest.read ||
m_filterRequest.unread;
}

bool LibraryProxyModel::filterAcceptsRow(int source_row,
const QModelIndex& source_parent) const
{
Expand Down Expand Up @@ -159,6 +169,8 @@ QString LibraryProxyModel::getSortString()
void LibraryProxyModel::addFilterTag(QString tag)
{
m_tags.emplace_back(tag);

emit filterUpdated();
invalidateFilter();
}

Expand All @@ -169,12 +181,16 @@ void LibraryProxyModel::removeFilterTag(QString tagToRemove)
return;

m_tags.erase(pos);

emit filterUpdated();
invalidateFilter();
}

void LibraryProxyModel::clearFilterTags()
{
m_tags.clear();

emit filterUpdated();
invalidateFilter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ADAPTERS_EXPORT LibraryProxyModel : public QSortFilterProxyModel
sortStringUpdated)
Q_PROPERTY(
int sortRole READ getSortRole WRITE setSortRole NOTIFY sortRoleUpdated)
Q_PROPERTY(bool isFiltering READ getIsFiltering NOTIFY filterUpdated)

public:
enum SortRole
Expand All @@ -45,6 +46,7 @@ class ADAPTERS_EXPORT LibraryProxyModel : public QSortFilterProxyModel
Q_INVOKABLE void setFilterRequest(QString authors, QString format,
QString language, bool onlyBooks,
bool onlyFiles, bool read, bool unread);
Q_INVOKABLE bool getIsFiltering();
Q_INVOKABLE void addFilterTag(QString tag);
Q_INVOKABLE void removeFilterTag(QString tag);
Q_INVOKABLE void clearFilterTags();
Expand All @@ -58,6 +60,7 @@ class ADAPTERS_EXPORT LibraryProxyModel : public QSortFilterProxyModel
signals:
void sortStringUpdated();
void sortRoleUpdated();
void filterUpdated();

private:
std::optional<bool> leftBookIsCloserToSortString(
Expand Down
5 changes: 1 addition & 4 deletions src/presentation/homePage/toolbar/MToolbar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ Item {
LibraryController.libraryModel.setFilterRequest(
authors, format, language, onlyBooks,
onlyFiles, read, unread)

resetFiltersButton.visible = true
}
}

Expand All @@ -71,7 +69,7 @@ Item {
*/
MRemoveOptionButton {
id: resetFiltersButton
visible: false
visible: LibraryController.libraryModel.isFiltering
text: qsTr("Remove Filters")

onClicked: root.resetFilters()
Expand Down Expand Up @@ -165,7 +163,6 @@ Item {
LibraryController.libraryModel.setFilterRequest("", "", "", false,
false, false, false)
filterByButton.resetFilter()
resetFiltersButton.visible = false
}

function resetTags() {
Expand Down

0 comments on commit 01e6f60

Please sign in to comment.