summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--archivebrowser.cpp15
-rw-r--r--archivebrowsermodel.cpp53
-rw-r--r--archivebrowsermodel.h2
3 files changed, 48 insertions, 22 deletions
diff --git a/archivebrowser.cpp b/archivebrowser.cpp
index 281c2fa..9234dbb 100644
--- a/archivebrowser.cpp
+++ b/archivebrowser.cpp
@@ -56,6 +56,7 @@ ArchiveBrowser::ArchiveBrowser(QWidget *parent) : QWidget(parent), mSelectedSize
mQualityFilter = new QComboBox;
toolBar->addWidget(mQualityFilter);
setupQualityFilter();
+ toolBar->addSeparator();
QStringList genres = mModel->availableGenres();
std::sort(genres.begin(), genres.end());
QActionGroup *gDataAG = new QActionGroup(this);
@@ -72,6 +73,20 @@ ArchiveBrowser::ArchiveBrowser(QWidget *parent) : QWidget(parent), mSelectedSize
genreMenu->addActions(gDataAG->actions());
genreA->setMenu(genreMenu);
toolBar->addAction(genreA);
+ QActionGroup *gDataExcludedAG = new QActionGroup(this);
+ gDataExcludedAG->setExclusive(false);
+ for(const QString &g : std::as_const(genres)){
+ QAction *a = new QAction(g, this);
+ a->setCheckable(true);
+ gDataExcludedAG->addAction(a);
+ connect(a, &QAction::triggered, a, [=] { mProxy->toggleExcludedGenre(a); });
+ }
+ QIcon excludedGenreIcon = Helper::icon(Qt::transparent, qApp->palette().color(QPalette::Text), 'E', true, false);
+ QAction *excludedGenreA = new QAction(excludedGenreIcon, tr("Filter genres"), this);
+ QMenu *excludedGenreMenu = new QMenu;
+ excludedGenreMenu->addActions(gDataExcludedAG->actions());
+ excludedGenreA->setMenu(excludedGenreMenu);
+ toolBar->addAction(excludedGenreA);
toolBar->addSeparator();
mSizeFilter = new QCheckBox(tr("Filter by size"));
connect(mSizeFilter, &QCheckBox::checkStateChanged, mProxy, &ArchiveBrowserModelProxy::setSizeFilter);
diff --git a/archivebrowsermodel.cpp b/archivebrowsermodel.cpp
index 9181d3f..e572a41 100644
--- a/archivebrowsermodel.cpp
+++ b/archivebrowsermodel.cpp
@@ -243,6 +243,16 @@ void ArchiveBrowserModelProxy::toggleGenre(QAction *a){
invalidateFilter();
}
+void ArchiveBrowserModelProxy::toggleExcludedGenre(QAction *a){
+ QString text = a->text();
+ if(a->isChecked()){
+ mExcludedGenreFilters << text;
+ }else{
+ mExcludedGenreFilters.removeAll(text);
+ }
+ invalidateFilter();
+}
+
void ArchiveBrowserModelProxy::setSizeFilter(int activate){
mSizeFilter = activate;
invalidateFilter();
@@ -255,7 +265,7 @@ void ArchiveBrowserModelProxy::setBytesRemaining(qint64 bytes){
bool ArchiveBrowserModelProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
- if(mQuality == -1 && !mSizeFilter && mGenreFilters.isEmpty()){
+ if(mQuality == -1 && !mSizeFilter && mGenreFilters.isEmpty() && mExcludedGenreFilters.isEmpty()){
return true;
}
QModelIndex selIdx = sourceModel()->index(sourceRow, ArchiveBrowserModel::Selected, sourceParent);
@@ -267,37 +277,36 @@ bool ArchiveBrowserModelProxy::filterAcceptsRow(int sourceRow, const QModelIndex
if(nodeType == ArchiveBrowserModel::FileNode){
return true;
}
+ QModelIndex genreIdx = sourceModel()->index(sourceRow, ArchiveBrowserModel::Genres, sourceParent);
+ QStringList genres = genreIdx.data().toStringList();
+ if(!mExcludedGenreFilters.isEmpty()){
+ for(const QString &exg : std::as_const(mExcludedGenreFilters)){
+ if(genres.contains(exg)){
+ return false;
+ }
+ }
+ }
+ bool retval = true;
if(!mGenreFilters.isEmpty()){
- QModelIndex genreIdx = sourceModel()->index(sourceRow, ArchiveBrowserModel::Genres, sourceParent);
- QStringList genres = genreIdx.data().toStringList();
for(const QString &fg : std::as_const(mGenreFilters)){
- if(genres.contains(fg)){
- return true;
+ if(!genres.contains(fg)){
+ retval = false;
}
}
- return false;
}
QModelIndex qualIdx = sourceModel()->index(sourceRow, ArchiveBrowserModel::Quality, sourceParent);
int quality = qualIdx.data().toInt();
QModelIndex sizeIdx = sourceModel()->index(sourceRow, ArchiveBrowserModel::TotalSize, sourceParent);
qint64 size = sizeIdx.data().toLongLong();
- if(mQuality > -1 && mSizeFilter){
- if(quality <= mQuality && size <= mBytesRemaining){
- return true;
- }
- return false;
- }
- if(mQuality > -1){
- if(quality <= mQuality){
- return true;
+ if(retval){
+ if(quality < mQuality){
+ retval = false;
}
- return false;
- }
- if(mSizeFilter){
- if(size <= mBytesRemaining){
- return true;
+ if(mSizeFilter){
+ if(size > mBytesRemaining){
+ retval = false;
+ }
}
- return false;
}
- return false;
+ return retval;
}
diff --git a/archivebrowsermodel.h b/archivebrowsermodel.h
index 212ecea..ccf601a 100644
--- a/archivebrowsermodel.h
+++ b/archivebrowsermodel.h
@@ -57,6 +57,7 @@ class ArchiveBrowserModelProxy : public QSortFilterProxyModel {
void setSizeFilter(int activate);
void setBytesRemaining(qint64 bytes);
void toggleGenre(QAction *a);
+ void toggleExcludedGenre(QAction *a);
protected:
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
@@ -66,6 +67,7 @@ class ArchiveBrowserModelProxy : public QSortFilterProxyModel {
bool mSizeFilter;
qint64 mBytesRemaining;
QStringList mGenreFilters;
+ QStringList mExcludedGenreFilters;
};
#endif // ARCHIVEBROWSERMODEL_H