Commit 026a554e authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Add "unused clip" filter in Project Bin.

BUG: 430035
parent ec0441c9
......@@ -1091,11 +1091,14 @@ Bin::Bin(std::shared_ptr<ProjectItemModel> model, QWidget *parent)
QList<QAction *> list = m_filterMenu->actions();
int rateFilters = 0;
int typeFilters = 0;
bool usedFilter = false;
QStringList tagFilters;
for (QAction *ac : qAsConst(list)) {
if (ac->isChecked()) {
QString actionData = ac->data().toString();
if (actionData.startsWith(QLatin1Char('#'))) {
if (actionData == QLatin1String("unused")) {
usedFilter = true;
} else if (actionData.startsWith(QLatin1Char('#'))) {
// Filter by tag
tagFilters << actionData;
} else if (actionData.startsWith(QLatin1Char('.'))) {
......@@ -1118,7 +1121,7 @@ Bin::Bin(std::shared_ptr<ProjectItemModel> model, QWidget *parent)
} else {
m_filterButton->setChecked(false);
}
m_proxyModel->slotSetFilters(tagFilters, rateFilters, typeFilters);
m_proxyModel->slotSetFilters(tagFilters, rateFilters, typeFilters, usedFilter);
});
connect(m_filterMenu, &QMenu::triggered, this, [this](QAction *action) {
......@@ -1137,11 +1140,14 @@ Bin::Bin(std::shared_ptr<ProjectItemModel> model, QWidget *parent)
QList<QAction *> list = m_filterMenu->actions();
int rateFilters = 0;
int typeFilters = 0;
bool usedFilter = false;
QStringList tagFilters;
for (QAction *ac : qAsConst(list)) {
if (ac->isChecked()) {
QString actionData = ac->data().toString();
if (actionData.startsWith(QLatin1Char('#'))) {
if (actionData == QLatin1String("unused")) {
usedFilter = true;
} else if (actionData.startsWith(QLatin1Char('#'))) {
// Filter by tag
tagFilters << actionData;
} else if (actionData.startsWith(QLatin1Char('.'))) {
......@@ -1164,7 +1170,7 @@ Bin::Bin(std::shared_ptr<ProjectItemModel> model, QWidget *parent)
} else {
m_filterButton->setChecked(false);
}
m_proxyModel->slotSetFilters(tagFilters, rateFilters, typeFilters);
m_proxyModel->slotSetFilters(tagFilters, rateFilters, typeFilters, usedFilter);
});
m_tagAction->setCheckable(true);
......@@ -1738,6 +1744,12 @@ void Bin::rebuildFilters(QMap <QString, QString> tags)
rateFilter->setCheckable(true);
m_filterMenu->addAction(rateFilter);
}
// Add unused filter
m_filterMenu->addSeparator();
QAction *unusedFilter = new QAction(i18n("Unused clips"), this);
unusedFilter->setData(QStringLiteral("unused"));
unusedFilter->setCheckable(true);
m_filterMenu->addAction(unusedFilter);
// Add type filters
m_filterMenu->addSeparator();
......
......@@ -104,6 +104,9 @@ int ProjectItemModel::mapToColumn(int column) const
case 7:
return AbstractProjectItem::DataRating;
break;
case 8:
return AbstractProjectItem::UsageCount;
break;
default:
return AbstractProjectItem::DataName;
}
......
......@@ -28,6 +28,7 @@ ProjectSortProxyModel::ProjectSortProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
, m_searchType(0)
, m_searchRating(0)
, m_unusedFilter(false)
{
m_collator.setLocale(QLocale()); // Locale used for sorting → OK
m_collator.setCaseSensitivity(Qt::CaseInsensitive);
......@@ -49,6 +50,13 @@ bool ProjectSortProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &s
bool ProjectSortProxyModel::filterAcceptsRowItself(int sourceRow, const QModelIndex &sourceParent) const
{
if (m_unusedFilter) {
// Column 8 contains the usage
QModelIndex indexTag = sourceModel()->index(sourceRow, 8, sourceParent);
if (sourceModel()->data(indexTag).toInt() > 0) {
return false;
}
}
if (m_searchRating > 0) {
// Column 7 contains the rating
QModelIndex indexTag = sourceModel()->index(sourceRow, 7, sourceParent);
......@@ -146,11 +154,12 @@ void ProjectSortProxyModel::slotSetSearchString(const QString &str)
invalidateFilter();
}
void ProjectSortProxyModel::slotSetFilters(const QStringList tagFilters, const int rateFilters, const int typeFilters)
void ProjectSortProxyModel::slotSetFilters(const QStringList tagFilters, const int rateFilters, const int typeFilters, bool unusedFilter)
{
m_searchType = typeFilters;
m_searchRating = rateFilters;
m_searchTag = tagFilters;
m_unusedFilter = unusedFilter;
invalidateFilter();
}
......@@ -159,6 +168,7 @@ void ProjectSortProxyModel::slotClearSearchFilters()
m_searchTag.clear();
m_searchRating = 0;
m_searchType = 0;
m_unusedFilter = false;
invalidateFilter();
}
......
......@@ -44,7 +44,7 @@ public slots:
/** @brief Set search string that will filter the view */
void slotSetSearchString(const QString &str);
/** @brief Set search tag that will filter the view */
void slotSetFilters(const QStringList tagFilters, int rateFilters, int typeFilters);
void slotSetFilters(const QStringList tagFilters, int rateFilters, int typeFilters, bool unusedFilter);
/** @brief Reset search filters */
void slotClearSearchFilters();
/** @brief Relay datachanged signal from view's model */
......@@ -71,6 +71,7 @@ private:
QStringList m_searchTag;
int m_searchType;
int m_searchRating;
bool m_unusedFilter;
QCollator m_collator;
signals:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment