From: Jean-Baptiste M. <jb...@kd...> - 2015-05-22 21:35:20
|
Git commit d027bdc83abe68876230e616fc88ad65617f4774 by Jean-Baptiste Mardelle. Committed on 22/05/2015 at 21:32. Pushed by mardelle into branch 'master'. Bin filter should now works on subclips M +39 -1 src/bin/projectsortproxymodel.cpp M +2 -0 src/bin/projectsortproxymodel.h http://commits.kde.org/kdenlive/d027bdc83abe68876230e616fc88ad65617f4774 diff --git a/src/bin/projectsortproxymodel.cpp b/src/bin/projectsortproxymodel.cpp index 9d02840..930e885 100644 --- a/src/bin/projectsortproxymodel.cpp +++ b/src/bin/projectsortproxymodel.cpp @@ -30,17 +30,55 @@ ProjectSortProxyModel::ProjectSortProxyModel(QObject *parent) { m_selection = new QItemSelectionModel(this); connect(m_selection, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(onCurrentRowChanged(QItemSelection,QItemSelection))); - setSortRole(AbstractProjectItem::SortRole); setDynamicSortFilter(true); + setSortRole(AbstractProjectItem::SortRole); } bool ProjectSortProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { + if (filterAcceptsRowItself(sourceRow, sourceParent)) { + return true; + } + //accept if any of the children is accepted on it's own merits + if (hasAcceptedChildren(sourceRow, sourceParent)) { + return true; + } + return false; +} + +bool ProjectSortProxyModel::filterAcceptsRowItself(int sourceRow, + const QModelIndex &sourceParent) const +{ QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent); + if (!index0.isValid()) { + return false; + } return (sourceModel()->data(index0).toString().contains(m_searchString)); } +bool ProjectSortProxyModel::hasAcceptedChildren(int sourceRow, const QModelIndex &source_parent) const +{ + QModelIndex item = sourceModel()->index(sourceRow,0,source_parent); + if (!item.isValid()) { + return false; + } + + //check if there are children + int childCount = item.model()->rowCount(item); + if (childCount == 0) + return false; + + for (int i = 0; i < childCount; ++i) { + if (filterAcceptsRowItself(i, item)) + return true; + //recursive call -> NOTICE that this is depth-first searching, you're probably better off with breadth first search... + if (hasAcceptedChildren(i, item)) + return true; + } + return false; +} + bool ProjectSortProxyModel::lessThan(const QModelIndex & left, const QModelIndex & right) const { // Check item type (folder or clip) as defined in projectitemmodel diff --git a/src/bin/projectsortproxymodel.h b/src/bin/projectsortproxymodel.h index 02249c7..2ee4766 100644 --- a/src/bin/projectsortproxymodel.h +++ b/src/bin/projectsortproxymodel.h @@ -55,6 +55,8 @@ protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; /** @brief Reimplemented to show folders first */ bool lessThan(const QModelIndex & left, const QModelIndex & right) const; + bool filterAcceptsRowItself(int source_row, const QModelIndex &source_parent) const; + bool hasAcceptedChildren(int source_row, const QModelIndex &source_parent) const; private: QItemSelectionModel*m_selection; |