示例#1
1
bool RKObjectListViewSettings::filterAcceptsRow (int source_row, const QModelIndex& source_parent) const {
//	RK_TRACE (APP);

	// So I tried to use a KRecursiveFilterProxyModel, but
	// a) we don't really want recursion to the full depth. Thus limiting it, here.
	// b) While we don't handle insertions / removals of source indices in the presence of a filter, correctly, with KRecursiveFilterProxyModel
	//    I got crashes on this (arguably with the depth-limit in place)
	if (acceptRow (source_row, source_parent)) return true;

	RObject *parent = static_cast<RObject*> (source_parent.internalPointer ());
	if (!parent) {
		RK_ASSERT (parent);    // should have been accepted, above
		return true;
	}
	RObject *object = parent->findChildByObjectModelIndex (source_row);
	if (!object) {
		RK_ASSERT (object);    // should have been accepted, above
		RK_DEBUG (APP, DL_ERROR, "row %d of %d in %s", source_row, sourceModel ()->rowCount (source_parent), qPrintable (parent->getShortName ()));
		return false;
	}

	if (object->isType (RObject::ToplevelEnv | RObject::Workspace) || ((depth_limit > 0) && parent->isType (RObject::ToplevelEnv | RObject::Workspace))) {
		QModelIndex source_index = sourceModel ()->index (source_row, 0, source_parent);
		for (int row = 0, rows = sourceModel()->rowCount (source_index); row < rows; ++row) {
			if (filterAcceptsRow (row, source_index)) return true;
		}
	}

	return false;
}
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);
}
bool BtBookshelfFilterModel::hiddenFilterAcceptsRow(int row, const QModelIndex &parent) const
{
    if (m_showHidden && m_showShown) return true;

    typedef Qt::CheckState CS;

    QAbstractItemModel *m(sourceModel());
    Q_ASSERT(m != 0);

    QModelIndex itemIndex(m->index(row, m_hiddenFilterColumn, parent));
    int numChildren(m->rowCount(itemIndex));
    if (numChildren == 0) {
        if ((CS) m->data(itemIndex, m_hiddenFilterRole).toBool()) {
            return m_showHidden;
        }
        else {
            return m_showShown;
        }
    }
    else {
        for (int i(0); i < numChildren; i++) {
            if (filterAcceptsRow(i, itemIndex)) return true;
        }
        return false;
    }
}
bool KSortFilterProxyModel::filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const
{
    if( filterRegExp().isEmpty() ) return true; //Shortcut for common case

    if( QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent) )
        return true;

    //one of our children might be accepted, so accept this row if one of our children are accepted.
    QModelIndex source_index = sourceModel()->index(source_row, 0, source_parent);
    for(int i = 0 ; i < sourceModel()->rowCount(source_index); i++) {
        if(filterAcceptsRow(i, source_index)) return true;
    }

    //one of our parents might be accepted, so accept this row if one of our parents is accepted.
    if(d_ptr->showAllChildren) {
        QModelIndex parent_index = source_parent;
        while(parent_index.isValid()) {
            int row = parent_index.row();
            parent_index = parent_index.parent();
            if(QSortFilterProxyModel::filterAcceptsRow(row, parent_index)) return true;
        }
    }

    return false;
}
示例#5
0
bool AndFilterProxy::filterAcceptsRow(int source_row, const QModelIndex & source_parent) const
{
    QModelIndex currntIndex = sourceModel()->index(source_row, 0, source_parent);
    if (sourceModel()->hasChildren(currntIndex)) {
        bool result = false;
        for (int i = 0; i < sourceModel()->rowCount(currntIndex) && !result; ++i) {
            result = result || filterAcceptsRow(i, currntIndex);
        }
        return result;
    }
    else {
        for (int i = 0; i < sourceModel()->columnCount(source_parent); ++i) {
            currntIndex = sourceModel()->index(source_row, i, source_parent);
            if (currntIndex.data().isNull() && currntIndex.parent().isValid()) {
                currntIndex = sourceModel()->index(source_parent.row(), i, source_parent.parent());
            }
            for (auto dateRngIter = m_dateRangeFilter.at(i).constBegin(); dateRngIter != m_dateRangeFilter.at(i).constEnd(); ++dateRngIter) {
                const QDate testDate = currntIndex.data(dateRngIter.key()).toDate();
                if (!((testDate >= dateRngIter.value().first || dateRngIter.value().first.isNull()) && (testDate <= dateRngIter.value().second || dateRngIter.value().second.isNull())))
                    return false;
                
            }
            for (auto boolIter = m_boolFilter.at(i).constBegin(); boolIter != m_boolFilter.at(i).constEnd(); ++boolIter) {
                const bool testBool = currntIndex.data(boolIter.key()).toBool();
                if (testBool != boolIter.value())
                    return false;
            }
            for (auto regExpIter = m_regExpFilter.at(i).constBegin(); regExpIter != m_regExpFilter.at(i).constEnd(); ++regExpIter) {
                if (regExpIter.value().first.match(currntIndex.data(regExpIter.key()).toString()).hasMatch() != regExpIter.value().second)
                    return false;
            }
        }
    }
    return true;
}
示例#6
0
bool ChildrenFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
	// custom behaviour :
	if(filterRegExp().isEmpty()==false)
	{
		// get source-model index for current row
		QModelIndex source_index = sourceModel()->index(source_row, this->filterKeyColumn(), source_parent) ;
		if(source_index.isValid())
		{
			// if any of children matches the filter, then current index matches the filter as well
			int i, nb = sourceModel()->rowCount(source_index) ;
			for(i=0; i<nb; ++i)
			{
				if(filterAcceptsRow(i, source_index))
				{
					return true ;
				}
			}
			// check current index itself :
			QString key = sourceModel()->data(source_index, filterRole()).toString();
			return key.contains(filterRegExp()) ;
		}
	}
	// parent call for initial behaviour
	return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent) ;
}
bool ModListSortProxy::filterAcceptsRow(int row, const QModelIndex &parent) const
{
  if (m_Profile == nullptr) {
    return false;
  }

  if (row >= static_cast<int>(m_Profile->numMods())) {
    qWarning("invalid row idx %d", row);
    return false;
  }

  QModelIndex idx = sourceModel()->index(row, 0, parent);
  if (!idx.isValid()) {
    qDebug("invalid index");
    return false;
  }
  if (sourceModel()->hasChildren(idx)) {
    for (int i = 0; i < sourceModel()->rowCount(idx); ++i) {
      if (filterAcceptsRow(i, idx)) {
        return true;
      }
    }

    return false;
  } else {
    bool modEnabled = idx.sibling(row, 0).data(Qt::CheckStateRole).toInt() == Qt::Checked;
    unsigned int index = idx.data(Qt::UserRole + 1).toInt();
    return filterMatchesMod(ModInfo::getByIndex(index), modEnabled);
  }
}
void FilterProxyModel::commitBatchToModel (int src_from, int src_to, BatchCmd const & batch)
{
	int const rows = src_to - src_from;
	int const from = m_map_from_tgt.size();

	m_map_from_src.reserve(m_log_widget.m_src_model->rowCount());

	QVector<int> accepted_rows; // grr
	accepted_rows.reserve(32);
	int tgt_idx = m_map_from_tgt.size();
	for (size_t src_idx = src_from; src_idx < src_to; ++src_idx)
	{
		if (filterAcceptsRow(src_idx, QModelIndex()))
		{
			accepted_rows.push_back(src_idx);
			m_map_from_src.insert(std::make_pair(src_idx, tgt_idx));
			++tgt_idx;
		}
	}

	if (int const n_accepted = accepted_rows.size())
	{
		m_map_from_tgt.reserve(from + n_accepted);
		int const to = from + n_accepted - 1;
		beginInsertRows(QModelIndex(), from, to);
		for (int i = 0, ie = n_accepted; i < ie; ++i)
		{
			m_map_from_tgt.push_back(accepted_rows[i]);
		}
		endInsertRows();
	}

	//@FIXME l8r: this does not work in general!
	if (m_cmap_from_src.size() < m_log_widget.m_src_model->columnCount())
	{
		int const from = m_cmap_from_src.size();
		m_cmap_from_tgt.clear();
		m_cmap_from_src.clear();
		m_cmap_from_src.reserve(m_log_widget.m_src_model->columnCount());
		int ctgt_idx = 0;
		for (size_t src_idx = 0, se = m_log_widget.m_src_model->columnCount(); src_idx < se; ++src_idx)
		{
			if (filterAcceptsColumn(src_idx, QModelIndex()))
			{
				m_cmap_from_src.insert(std::make_pair(src_idx, ctgt_idx));
				++ctgt_idx;
			}
		}
		int const to = ctgt_idx - 1;
		beginInsertColumns(QModelIndex(), from, to);
		m_cmap_from_tgt.resize(m_cmap_from_src.size());
		for (map_t::const_iterator it = m_cmap_from_src.begin(), ite = m_cmap_from_src.end(); it != ite; ++it)
		{
			m_cmap_from_tgt[it->second] = it->first;
		}
		endInsertColumns();
	}
}
示例#9
0
bool DocumentFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
    QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
    if( !index.isValid()) {
        return false;
    }

    bool accepted = false;

    // filter works on the document ID, the client name and the document type.
    const QRegExp filter = filterRegExp();
    if( filter.pattern().isEmpty() ) {
        accepted = true;
    } else {
        const QModelIndex index0 = sourceModel()->index(sourceRow, DocumentModel::Document_Ident, sourceParent);
        const QString idStr = sourceModel()->data(index0).toString();

        const QModelIndex index1 = sourceModel()->index(sourceRow, DocumentModel::Document_Type, sourceParent);
        const QString typeStr = sourceModel()->data(index1).toString();

        const QModelIndex index2 = sourceModel()->index(sourceRow, DocumentModel::Document_ClientName, sourceParent);
        const QString clientNameStr = sourceModel()->data(index2).toString();

        const QModelIndex index3 = sourceModel()->index(sourceRow, DocumentModel::Document_Whiteboard, sourceParent);
        const QString whiteboardStr = sourceModel()->data(index3).toString();

        const QModelIndex index4 = sourceModel()->index(sourceRow, DocumentModel::Document_ProjectLabel, sourceParent);
        const QString projectStr = sourceModel()->data(index4).toString();

        if( idStr.contains(filter) || typeStr.contains(filter) || clientNameStr.contains(filter)
                || whiteboardStr.contains(filter) || projectStr.contains(filter)) {
            accepted = true;
        }
    }

    // for the treeview, check all the children
    if( _enableTreeView ) {
        int rows = sourceModel()->rowCount(index);
        for (int row = 0; row < rows; row++) {
            if (filterAcceptsRow(row, index)) {
                accepted = true;
            }
        }
    }

    // if the entry is accepted so far, check if it is within the time limit
    if( accepted && m_MaxRows > -1 ) {
        const QModelIndex index = sourceModel()->index(sourceRow, DocumentModel::Document_CreationDateRaw, sourceParent);
        const QDate docDate = sourceModel()->data(index).toDate();

        int dateDiff = docDate.daysTo(QDate::currentDate());
        if( dateDiff > m_MaxRows ) {
            accepted = false;
        }
    }

    return accepted;
}
void QtMessageLogProxyModel::onRowsInserted(const QModelIndex &index, int start, int end)
{
    int rowIndex = end;
    do {
        if (filterAcceptsRow(rowIndex, index)) {
            emit scrollToBottom();
            break;
        }
    } while (--rowIndex >= start);
}
示例#11
0
bool
PlayableProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
{
    PlayableItem* pi = itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) );
    if ( !pi )
        return false;

    if ( m_maxVisibleItems >= 0 && sourceRow > m_maxVisibleItems - 1 )
        return false;

    if ( m_hideDupeItems )
    {
        for ( int i = 0; i < sourceRow; i++ )
        {
            PlayableItem* di = itemFromIndex( sourceModel()->index( i, 0, sourceParent ) );
            if ( !di )
                continue;

            bool b = ( pi->query() && pi->query()->equals( di->query() ) ) ||
                     ( pi->album() && pi->album() == di->album() ) ||
                     ( pi->artist() && pi->artist()->name() == di->artist()->name() );

            if ( b && filterAcceptsRow( i, sourceParent ) )
                return false;
        }
    }

    if ( pi->query() )
    {
        const Tomahawk::query_ptr& q = pi->query()->displayQuery();
        if ( q.isNull() ) // uh oh? filter out invalid queries i guess
            return false;

        Tomahawk::result_ptr r;
        if ( q->numResults() )
            r = q->results().first();

        if ( !m_showOfflineResults && ( r.isNull() || !r->isOnline() ) )
            return false;

        if ( filterRegExp().isEmpty() )
            return true;

        QStringList sl = filterRegExp().pattern().split( " ", QString::SkipEmptyParts );
        foreach( QString s, sl )
        {
            s = s.toLower();
            if ( !q->artist().toLower().contains( s ) &&
                    !q->album().toLower().contains( s ) &&
                    !q->track().toLower().contains( s ) )
            {
                return false;
            }
        }
    }
示例#12
0
bool QtSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const {
	if (sourceParent.isValid()) {
		return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
	}
	QModelIndex index = sourceModel()->index(sourceRow, filterKeyColumn(), sourceParent);
	bool visibleChild = false;
	for (int i = 0; i < sourceModel()->rowCount(index); i++) {
		visibleChild |= filterAcceptsRow(i, index);
	}
	return visibleChild;
}
bool EventsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
    if (sourceParent.isValid())
        return true;

    EventData *eventData = sourceModel()->index(sourceRow, 0).data(EventsModel::EventDataPtr).value<EventData *>();
    if (!eventData)
        return false;

    return filterAcceptsRow(eventData);
}
/** Redefined from MiamSortFilterProxyModel. */
bool UniqueLibraryFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
	QStandardItem *item = _model->itemFromIndex(_model->index(sourceRow, 1, sourceParent));
	if (!item) {
		return false;
	}
	bool result = false;
	switch (item->type()) {
	case Miam::IT_Artist:
		if (MiamSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent)) {
			result = true;
		} else {
			QSqlQuery getArtist(*SqlDatabase::instance());
			getArtist.prepare("SELECT * FROM tracks WHERE title LIKE ? AND artistId = ?");
			getArtist.addBindValue("%" + filterRegExp().pattern() + "%");
			getArtist.addBindValue(item->data(Miam::DF_ID).toUInt());
			result = getArtist.exec() && getArtist.next();
		}
		break;
	case Miam::IT_Album:
		if (MiamSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent)) {
			result = true;
		} else if (filterRegExp().indexIn(item->data(Miam::DF_Artist).toString()) != -1) {
			result = true;
		} else {
			QSqlQuery getAlbum(*SqlDatabase::instance());
			getAlbum.prepare("SELECT * FROM tracks WHERE title LIKE ? AND albumId = ?");
			getAlbum.addBindValue("%" + filterRegExp().pattern() + "%");
			getAlbum.addBindValue(item->data(Miam::DF_ID).toUInt());
			result = getAlbum.exec() && getAlbum.next();
		}
		break;
	case Miam::IT_Track:
		if (MiamSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent)) {
			result = true;
		} else {
			result = filterRegExp().indexIn(item->data(Miam::DF_Artist).toString()) != -1 ||
					filterRegExp().indexIn(item->data(Miam::DF_Album).toString()) != -1;
		}
		break;
	case Miam::IT_Separator:
		for (QModelIndex index : _topLevelItems.values(static_cast<SeparatorItem*>(item))) {
			if (filterAcceptsRow(index.row(), sourceParent)) {
				result = true;
			}
		}
		break;
	default:
		break;
	}
	return result;
}
bool omni::ui::tree_sort_filter_proxy_model::filterAcceptsRow (int sourceRow, const QModelIndex & sourceParent) const
{
    // If this row matches, return true:
    if (filterAcceptsRowExactly (sourceRow,  sourceParent)) {
        return true;
    }
    // Now check whether any of this row's child rows matches:
    QModelIndex row = sourceModel ()->index (sourceRow, filterKeyColumn (), sourceParent);
    for (int i = 0; i < sourceModel ()->rowCount (row); ++ i) {
        if (filterAcceptsRow (i, row)) {
            return true;
        }
    }
    // Neither this row, nor any children, match.
    return false;
}
示例#16
0
	void FontFilter::processRowFilter() {
		m_accepted_indexes.clear();

		m_search_result_count = 0;

		int source_row_count = totalFontCount();
		for(int i=0; i<source_row_count; i++) {
			if (filterAcceptsRow(i))
				m_accepted_indexes.append(i);
		}

		if (searchFiltered())
			emit searchResultsChanged(m_search_result_count);
		else
			emit searchResultsChanged(-1);

		reset();
	}
bool CategorySortFilterModel::filterAcceptsRow(int source_row,
                                               const QModelIndex &source_parent) const
{
    if (!source_parent.isValid()) {
        // category items should be visible if any of its children match
        const QRegExp &regexp = filterRegExp();
        const QModelIndex &categoryIndex = sourceModel()->index(source_row, 0, source_parent);
        if (regexp.indexIn(sourceModel()->data(categoryIndex, filterRole()).toString()) != -1)
            return true;
        const int rowCount = sourceModel()->rowCount(categoryIndex);
        for (int row = 0; row < rowCount; ++row) {
            if (filterAcceptsRow(row, categoryIndex))
                return true;
        }
        return false;
    }
    return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
}
示例#18
0
bool SortFilterProxy::filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const
{
   const int column=0;
   // Filter Mask/Value check
   QModelIndex item=sourceModel()->index(source_row,column,source_parent);
   QVariant filter=item.data(FilterRole);
   if (filter.isValid())
   {
      bool f=filter.toBool();
      if (f)
         return false;
   }
   

   // parent check
   QModelIndex p=source_parent;

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


   // Child check
   if (QSortFilterProxyModel::filterAcceptsRow(source_row,source_parent))
      return true;
   else
   {
      if (! _recurse)
         return false;

      QModelIndex item=sourceModel()->index(source_row,column,source_parent);
      for (int r=0;;r++)
      {
         if (! item.child(r,column).isValid() ) 
            return false;

         if (filterAcceptsRow(r,item))
            return true;
      }
   }
}
bool BtBookshelfFilterModel::nameFilterAcceptsRow(int row, const QModelIndex &parent) const {
    if (m_nameFilter.isEmpty()) return true;

    const QAbstractItemModel *m(sourceModel());
    Q_ASSERT(m != 0);

    QModelIndex itemIndex(m->index(row, m_nameFilterColumn, parent));
    int numChildren(m->rowCount(itemIndex));
    if (numChildren == 0) {
        QVariant data(m->data(itemIndex, m_nameFilterRole));
        return data.toString().contains(m_nameFilter, m_nameFilterCase);
    }
    else {
        for (int i(0); i < numChildren; i++) {
            if (filterAcceptsRow(i, itemIndex)) return true;
        }
        return false;
    }
}
bool BtModuleNameFilterProxyModel::filterAcceptsRow(int row,
        const QModelIndex &p) const {
    if (!m_enabled) return true;

    const QAbstractItemModel *m(sourceModel());
    Q_ASSERT(m != 0);

    QModelIndex itemIndex(m->index(row, filterKeyColumn(), p));
    int numChildren(m->rowCount(itemIndex));
    if (numChildren == 0) {
        return QSortFilterProxyModel::filterAcceptsRow(row, p);
    }
    else {
        for (int i(0); i < numChildren; i++) {
            if (filterAcceptsRow(i, itemIndex)) return true;
        }
        return false;
    }
}
// this solution was taken from:
// http://stackoverflow.com/questions/250890/using-qsortfilterproxymodel-with-a-tree-model
bool TagSortFilterProxyModel::filterAcceptsRow(int source_row,
        const QModelIndex &source_parent) const
{
    if(filterRegExp().isEmpty() == false)
    {
        QModelIndex source_index = sourceModel()->index(source_row, filterKeyColumn(), source_parent) ;
        if(source_index.isValid())
        {
            int nb = sourceModel()->rowCount(source_index) ;
            for(int i = 0; i < nb; ++i)
                if(filterAcceptsRow(i, source_index))
                    return true;

            QString key = sourceModel()->data(source_index, filterRole()).toString();
            return key.contains(filterRegExp());
        }
    }

    return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent) ;
}
bool MimetypeFilterItemModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
    QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
  
    if (source_parent.isValid()) 
    {
        return filterHelper(index);
    } 
    else 
    {
        for (int i = 0; i < sourceModel()->rowCount(index); i++)
        {
            if (filterAcceptsRow(i, index)) 
            {
                return true;
            }
        }
    }

    return false;
}
bool BtBookshelfFilterModel::categoryFilterAcceptsRow(int row,
        const QModelIndex &parent) const
{
    if (m_categoryFilter == CSwordModuleInfo::AllCategories) return true;

    QAbstractItemModel *m(sourceModel());
    Q_ASSERT(m != 0);

    QModelIndex itemIndex(m->index(row, m_categoryFilterColumn, parent));
    int numChildren(m->rowCount(itemIndex));
    if (numChildren == 0) {
        int cat = m->data(itemIndex, m_categoryFilterRole).toInt();
        return m_categoryFilter.testFlag((CSwordModuleInfo::Category) cat);
    }
    else {
        for (int i(0); i < numChildren; i++) {
            if (filterAcceptsRow(i, itemIndex)) return true;
        }
        return false;
    }
}
bool DwarfModelProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
    bool matches = true;

    int dwarf_id = 0;
	const DwarfModel *m = get_dwarf_model();
	if (m->current_grouping() == DwarfModel::GB_NOTHING) {
		QModelIndex idx = m->index(source_row, 0, source_parent);
        dwarf_id = m->data(idx, DwarfModel::DR_ID).toInt();
		QString data = m->data(idx, filterRole()).toString();
        if (!m_filter_text.isEmpty())
		    matches = matches && data.contains(m_filter_text, Qt::CaseInsensitive);	
	} else {
		QModelIndex tmp_idx = m->index(source_row, 0, source_parent);
		QStandardItem *item = m->itemFromIndex(tmp_idx);
		if (m->data(tmp_idx, DwarfModel::DR_IS_AGGREGATE).toBool()) {
			int matches = 0;
			for(int i = 0; i < item->rowCount(); ++i) {
				if (filterAcceptsRow(i, tmp_idx)) // a child matches
					matches++;
			}
			matches = matches && matches > 0;
		} else {
			QModelIndex idx = m->index(source_row, 0, source_parent);
            dwarf_id = m->data(idx, DwarfModel::DR_ID).toInt();
			QString data = m->data(idx, filterRole()).toString();
            if (!m_filter_text.isEmpty())
			    matches = matches && data.contains(m_filter_text, Qt::CaseInsensitive);	
		}
	}
    
    if (dwarf_id && !m_active_filter_script.isEmpty()) {
        Dwarf *d = m->get_dwarf_by_id(dwarf_id);
        if (d) {
            QScriptValue d_obj = m_engine->newQObject(d);
            m_engine->globalObject().setProperty("d", d_obj);
            matches = matches && m_engine->evaluate(m_active_filter_script).toBool();
        }
    }
	return matches;
}
bool BtBookshelfFilterModel::hiddenFilterAcceptsRow(int row,
                                                    const QModelIndex & parent) const
{
    if (m_showHidden && m_showShown)
        return true;

    const QAbstractItemModel * const m = sourceModel();
    Q_ASSERT(m != 0);

    const QModelIndex itemIndex = m->index(row, m_hiddenFilterColumn, parent);
    const int numChildren = m->rowCount(itemIndex);
    if (numChildren == 0) {
        if (static_cast<Qt::CheckState>(m->data(itemIndex, m_hiddenFilterRole).toBool()))
            return m_showHidden;
        return m_showShown;
    }

    for (int i = 0; i < numChildren; i++)
        if (filterAcceptsRow(i, itemIndex))
            return true;
    return false;
}
示例#26
0
bool ShortcutsFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
	if (filterRegExp().isEmpty())
		return true;
	
	if (source_parent.isValid())
	{
		QModelIndex index = source_parent.child(source_row, filterKeyColumn());
		QString data = sourceModel()->data(index, filterRole()).toString();
		return data.contains(filterRegExp());
	}
	else
	{
		QModelIndex index = sourceModel()->index(source_row, filterKeyColumn());
		for (int row = 0; row < sourceModel()->rowCount(index); row++)
		{
			if (filterAcceptsRow(row, index))
				return true;
		}
	}
	return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
}
示例#27
0
bool QFPseudoTreeModelSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
    QFPseudoTreeModel* tree=qobject_cast<QFPseudoTreeModel*>(sourceModel());

    if (tree) {
        QModelIndex idx=tree->index(sourceRow, 0, sourceParent);
        if (idx.isValid()) {
            if (tree->isFolder(idx)) {
                QList<int> c=tree->folderContentsRows(idx);
                for (int i=0; i<c.size(); i++) {
                    if (filterAcceptsRow(c[i], sourceParent)) {
                        return true;
                    }
                }
                return false;
            } else {
                return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
            }
        }
    } else {
        return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
    }
    return true;
}
	bool SortFilterProxyModel::filterAcceptsRow (int row, const QModelIndex& parent) const
	{
		if (MUCMode_)
		{
			if (!MUCEntry_)
				return false;

			const QModelIndex& idx = sourceModel ()->index (row, 0, parent);
			switch (GetType (idx))
			{
			case Core::CLETAccount:
			{
				QObject *acc = qobject_cast<ICLEntry*> (MUCEntry_)->GetParentAccount ();
				return acc == idx.data (Core::CLRAccountObject).value<QObject*> ();
			}
			case Core::CLETCategory:
			{
				const QString& gName = idx.data ().toString ();
				return gName == qobject_cast<IMUCEntry*> (MUCEntry_)->GetGroupName () ||
						qobject_cast<ICLEntry*> (MUCEntry_)->Groups ().contains (gName);
			}
			default:
				break;
			}
		}
		else
		{
			const QModelIndex& idx = sourceModel ()->index (row, 0, parent);
			if (!filterRegExp ().isEmpty ())
				return GetType (idx) == Core::CLETContact ?
						idx.data ().toString ().contains (filterRegExp ()) :
						true;

			if (idx.data (Core::CLRUnreadMsgCount).toInt ())
				return true;

			const auto type = GetType (idx);

			if (type == Core::CLETContact)
			{
				ICLEntry *entry = GetEntry (idx);
				const State state = entry->GetStatus ().State_;

				if (!ShowOffline_ &&
						state == SOffline &&
						!idx.data (Core::CLRUnreadMsgCount).toInt ())
					return false;

				if (HideMUCParts_ &&
						entry->GetEntryType () == ICLEntry::ETPrivateChat)
					return false;

				if (!ShowSelfContacts_ &&
						entry->GetEntryFeatures () & ICLEntry::FSelfContact)
					return false;
			}
			else if (type == Core::CLETCategory)
			{
				if (!ShowOffline_ &&
						!idx.data (Core::CLRNumOnline).toInt ())
					return false;

				for (int subRow = 0; subRow < sourceModel ()->rowCount (idx); ++subRow)
					if (filterAcceptsRow (subRow, idx))
						return true;

				return false;
			}
			else if (type == Core::CLETAccount)
			{
				const auto& accObj = idx.data (Core::CLRAccountObject).value<QObject*> ();
				auto acc = qobject_cast<IAccount*> (accObj);
				return acc->IsShownInRoster ();
			}
		}

		return QSortFilterProxyModel::filterAcceptsRow (row, parent);
	}
bool
NameNumberFilterProxy::filterAcceptsRow(int source_row, const QModelIndex & source_parent) const
{
    // we filter the regex only on Calls, Contacts and ContactMethods; however we don't want to display
    // the top nodes (Categories) if they have no children
    if (!source_parent.isValid() && filterRegExp().isEmpty()) {
        return true;
    } else if (!source_parent.isValid()) {
        // check if there are any children, don't display the categroy if not
        auto idx = sourceModel()->index(source_row, 0, source_parent);
        if (!idx.isValid())
            return false;

        for (int row = 0; row <  sourceModel()->rowCount(idx); ++row) {
            if (filterAcceptsRow(row, idx)) {
                return true;
            }
        }
        return false;
    } else {
        auto idx = sourceModel()->index(source_row, 0, source_parent);

        if (!idx.isValid()) {
            return false;
        }

        //we want to filter on name and number; note that Person object may have many numbers
        if (idx.data(static_cast<int>(Ring::Role::Name)).toString().contains(filterRegExp())) {
            return true;
        } else {
            auto type = idx.data(static_cast<int>(Ring::Role::ObjectType));
            auto object = idx.data(static_cast<int>(Ring::Role::Object));

            if (!type.isValid() || !object.isValid()) {
                return false;
            }

            switch (type.value<Ring::ObjectType>()) {
                case Ring::ObjectType::Person:
                {
                    auto p = object.value<Person *>();
                    for (auto cm : p->phoneNumbers()) {
                        if (cm->uri().full().contains(filterRegExp())) {
                            return true;
                        }
                    }
                    return false;
                }
                break;
                case Ring::ObjectType::ContactMethod:
                {
                    auto cm = object.value<ContactMethod *>();
                    return cm->uri().full().contains(filterRegExp());
                }
                break;
                case Ring::ObjectType::Call:
                {
                    auto call = object.value<Call *>();
                    return call->peerContactMethod()->uri().full().contains(filterRegExp());
                }
                break;
                case Ring::ObjectType::Media:
                case Ring::ObjectType::Certificate:
                case Ring::ObjectType::COUNT__:
                break;
            }

        }
        return false; // no matches
    }
}