bool LibraryFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
	if (filterAcceptsRowItself(sourceRow, sourceParent)) {
		return true;
	}

	// Accept if any of the parents is accepted on it's own merits
	QModelIndex parent = sourceParent;
	while (parent.isValid()) {
		if (filterAcceptsRowItself(parent.row(), parent.parent())) {
			return true;
		}
		parent = parent.parent();
	}

	// Accept if any of the children is accepted on it's own merits
	if (hasAcceptedChildren(sourceRow, sourceParent)) {
		return true;
	}

	// Accept separators if any top level items and its children are accepted
	QStandardItemModel *model = qobject_cast<QStandardItemModel*>(sourceModel());
	QStandardItem *item = model->itemFromIndex(model->index(sourceRow, 0, sourceParent));
	if (item && item->type() == Miam::IT_Separator) {
		for (QModelIndex index : _topLevelItems.values(static_cast<SeparatorItem*>(item))) {
			if (filterAcceptsRow(index.row(), sourceParent)) {
				return true;
			}
		}
	}
	return (SettingsPrivate::instance()->librarySearchMode() == SettingsPrivate::LSM_HighlightOnly);
}
示例#2
0
bool RefItemProxyModel::hasAcceptedChildren(const QModelIndex &link_index,
                                            const QModelIndex &source_parent) const
{
    if (!source_parent.isValid())
        return false;

    if (source_parent.data(TreeXmlModel::TagRole) != DBCLASSXML::CLASS)
        return false;

    if (source_parent == link_index)
        return true;

    if (recursion()) {
        qint32 row = 0;
        QModelIndex childIndex = sourceModel()->index(row, 0, source_parent);
        while (childIndex.isValid())
        {
            if (hasAcceptedChildren(link_index, childIndex))
                return true;
            childIndex = sourceModel()->index(++row, 0, source_parent);
        }
    }

    return false;
}
bool MusicProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
    if (QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent))
        return true;

    QModelIndex parent = sourceParent;
    while (parent.isValid()) {
        if (QSortFilterProxyModel::filterAcceptsRow(parent.row(), parent.parent()))
            return true;
        parent = parent.parent();
    }

    return hasAcceptedChildren(sourceRow, sourceParent);
}
示例#4
0
bool RefItemProxyModel::filterAcceptsRowItself(qint32 source_row, const QModelIndex &source_parent) const
{
    QModelIndex srcIndex = sourceModel()->index(source_row, 0, source_parent);
    QString tag = srcIndex.data(TreeXmlModel::TagRole).toString();
    if (tag == DBMODELXML::MODEL || tag == DBREFLISTXML::REFLIST)
        return true;

     if (tag == DBREFGROUPXML::REFGROUP) {
         qint32 row = 0;
         QModelIndex childIndex = srcIndex.child(row,0);
         while (childIndex.isValid())
         {
             if (filterAcceptsRowItself(row, srcIndex))
                 return true;
             childIndex = srcIndex.child(++row,0);
         }
     }

     if (tag == DBREFXML::REF) {
         if (!m_classIndex.isValid())
             return true;

         TreeXmlHashModel *hashModel = qobject_cast<TreeXmlHashModel *>(sourceModel());
         if (hashModel) {
             qint32 refClassColumn = hashModel->columnDisplayedAttr(
                         DBLINKTOCLASSXML::LINKTOCLASS,
                         DBLINKTOCLASSXML::REFCLASS);

             qint32 row = 0;
             QModelIndex childIndex = srcIndex.child(row,0);
             while (childIndex.isValid())
             {
                 if (childIndex.data(TreeXmlModel::TagRole) == DBLINKTOCLASSXML::LINKTOCLASS)
                 {
                     QModelIndex linkIndex = hashModel->indexLink(
                                 childIndex.sibling(childIndex.row(),
                                                    refClassColumn));
                     if (hasAcceptedChildren(linkIndex.sibling(linkIndex.row(),0),
                                             m_classIndex))
                         return true;
                 }
                 childIndex = srcIndex.child(++row, 0);
             }
         }
     }

    return false;
}
示例#5
0
bool TvShowProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
    if (filterAcceptsRowItself(source_row, source_parent))
        return true;

    //accept if any of the parents is accepted on it's own merits
    QModelIndex parent = source_parent;
    while (parent.isValid()) {
        if (filterAcceptsRowItself(parent.row(), parent.parent()))
            return true;
        parent = parent.parent();
    }

    //accept if any of the children is accepted on it's own merits
    if (hasAcceptedChildren(source_row, source_parent)) {
        return true;
    }

    return false;
}
示例#6
0
bool TvShowProxyModel::hasAcceptedChildren(int source_row, const QModelIndex &source_parent) const
{
    QModelIndex item = sourceModel()->index(source_row, 0, source_parent);
    if (!item.isValid()) {
        //qDebug() << "item invalid" << source_parent << source_row;
        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 LibraryFilterProxyModel::hasAcceptedChildren(int sourceRow, const QModelIndex &sourceParent) const
{
	QModelIndex item = sourceModel()->index(sourceRow, 0, sourceParent);
	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
		if (hasAcceptedChildren(i, item)) {
			return true;
		}
	}
	return false;
}
bool LibraryFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
	if (filterAcceptsRowItself(sourceRow, sourceParent)) {
		if (!filterRegExp().isEmpty()) {
			emit aboutToExpand(mapFromSource(sourceParent));
		}
		return true;
	}

	//accept if any of the parents is accepted on it's own merits
	QModelIndex parent = sourceParent;
	while (parent.isValid()) {
		if (filterAcceptsRowItself(parent.row(), parent.parent())) {
			return true;
		}
		parent = parent.parent();
	}

	//accept if any of the children is accepted on it's own merits
	if (hasAcceptedChildren(sourceRow, sourceParent)) {
		return true;
	}
	return false;
}