Example #1
0
/**
 * Check if the source_row index is identical to the previous index
 */
bool DeduplicateProxy::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
   // Get both source QModelIndex and compare them
   if (source_row > 0) {
      const QModelIndex idx = sourceModel()->index(source_row, filterKeyColumn(), source_parent);

      // It is correct to assume sourceModelIndex - 1 will be part of the same group
      if (idx.row() > 0) {
         const QModelIndex sibling = sourceModel()->index(idx.row() - 1, idx.column(), idx.parent());

         bool accept = false;

         // Allow to filter with more than one role, apply only if they exist
         foreach(const int r, d_ptr->m_lOtherRoles) {
            const QVariant v1 = idx.data    (r);
            const QVariant v2 = sibling.data(r);

            // Yes, this is an "=", not "=="
            if ((accept = !(v1.isValid() && v2.isValid() && (v1 == v2))))
               break;
         }

         return accept || idx.data(filterRole()) != sibling.data(filterRole());
      }
   }

   return true;
}
Example #2
0
	bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
	{
		QModelIndex aliasIndex = sourceModel()->index( sourceRow, AliasColumns::Alias, sourceParent );
		QModelIndex commandIndex = sourceModel()->index( sourceRow, AliasColumns::Command, sourceParent );
		QString alias, command;
		if ( !aliasIndex.isValid() || !commandIndex.isValid() ) // the column may not exist
		{
			alias = aliasIndex.data( filterRole() ).toString();
		}
		command = commandIndex.data( filterRole() ).toString();

		return alias.contains( filterRegExp() ) || command.contains( filterRegExp() );
		return false;
	}
Example #3
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) ;
}
/*!
	From QSortFilterProxyModel.

	Called for each index in the source model. Returns true if the index
	satisfies the filter criteria.

	\sa QSortFilterProxyModel.
 */
bool ClockCityListProxyModel::filterAcceptsRow(
		int sourceRow, const QModelIndex &sourceParent) const
{
	OstTraceFunctionEntry0( CLOCKCITYLISTPROXYMODEL_FILTERACCEPTSROW_ENTRY );
	// Get the model index of the source model.
	QModelIndex modelIndex = sourceModel()->index(
			sourceRow, filterKeyColumn(), sourceParent);

	if (!modelIndex.isValid()) {
		OstTraceFunctionExit0( CLOCKCITYLISTPROXYMODEL_FILTERACCEPTSROW_EXIT );
		return false;
	}

	// Get the data corresponding to that model.
	int role = filterRole();
	QString filterExp(filterRegExp().pattern());

	QVariant modelData = sourceModel()->data(modelIndex, role);

	// We just have one item and search is done only on data set with
	// Qt::DisplayRole.
	if (Qt::UserRole + 100 == role) {
		QString string = modelData.value<QString>();
		if (string.contains(filterExp)) {
			OstTraceFunctionExit0( DUP1_CLOCKCITYLISTPROXYMODEL_FILTERACCEPTSROW_EXIT );
			return true;
		}
	}
	return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
bool HelpProxyModel::filterAcceptsRow(int sourceRow,
        const QModelIndex &sourceParent) const
{
	QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);

	switch(filterRole())
	{
	case KeywordRole:
		{			
			QStringList keywordLst = sourceModel()->data(index, KeywordRole).toStringList();

			foreach(QString str, keywordLst)
			{
				if(HelpUtils::findStr(str, filterRegExp().pattern()) != -1)
				{
					return true;
				}
			}
			return false;
		}
	case Qt::DisplayRole:
		{
			QString title = sourceModel()->data(index, Qt::DisplayRole).toString();
			if(HelpUtils::findStr(title, filterRegExp().pattern()) != -1)
			{
				return true;
			}
			return false;
		}
	default:
		return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
	}
}
Example #6
0
bool SearchModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
    if (filterRegExp().isEmpty())
        return false;

    QModelIndex source_index = sourceModel()->index(source_row, filterKeyColumn(), source_parent);
    QString key = sourceModel()->data(source_index, filterRole()).toString();
    return key.contains(filterRegExp());
}
int QSortFilterProxyModel::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QAbstractProxyModel::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 20)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 20;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QRegExp*>(_v) = filterRegExp(); break;
        case 1: *reinterpret_cast< int*>(_v) = filterKeyColumn(); break;
        case 2: *reinterpret_cast< bool*>(_v) = dynamicSortFilter(); break;
        case 3: *reinterpret_cast< Qt::CaseSensitivity*>(_v) = filterCaseSensitivity(); break;
        case 4: *reinterpret_cast< Qt::CaseSensitivity*>(_v) = sortCaseSensitivity(); break;
        case 5: *reinterpret_cast< bool*>(_v) = isSortLocaleAware(); break;
        case 6: *reinterpret_cast< int*>(_v) = sortRole(); break;
        case 7: *reinterpret_cast< int*>(_v) = filterRole(); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setFilterRegExp(*reinterpret_cast< QRegExp*>(_v)); break;
        case 1: setFilterKeyColumn(*reinterpret_cast< int*>(_v)); break;
        case 2: setDynamicSortFilter(*reinterpret_cast< bool*>(_v)); break;
        case 3: setFilterCaseSensitivity(*reinterpret_cast< Qt::CaseSensitivity*>(_v)); break;
        case 4: setSortCaseSensitivity(*reinterpret_cast< Qt::CaseSensitivity*>(_v)); break;
        case 5: setSortLocaleAware(*reinterpret_cast< bool*>(_v)); break;
        case 6: setSortRole(*reinterpret_cast< int*>(_v)); break;
        case 7: setFilterRole(*reinterpret_cast< int*>(_v)); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 8;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
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 QgsPluginSortFilterProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
{
  QModelIndex inx = sourceModel()->index( sourceRow, 0, sourceParent );

  if ( ! sourceModel()->data( inx, SPACER_ROLE ).toString().isEmpty() )
  {
    // it's a status spacer.
    // TODO: the condition below is only suitable for status spacers
    return ( filterByStatus( inx ) &&  mAcceptedStatuses.count() > 1 && sourceModel()->data( inx, SPACER_ROLE ).toString() == mAcceptedSpacers );
  }

  return ( filterByStatus( inx ) && sourceModel()->data( inx, filterRole() ).toString().contains( filterRegExp() ) );
}
Example #10
0
	bool FontFilter::filterAcceptsRow(int source_row) {

		QModelIndex sourceIndex = fontsModel()->index(source_row, 0);

		bool search_filter = (searchText().isEmpty()) or (fontsModel()->data(sourceIndex, filterRole()).toString().contains(searchText(), Qt::CaseInsensitive));

		bool selection_filter = (not m_show_only_selected) or (fontsModel()->familySelected(source_row) or fontsModel()->familyMarked(source_row));

		if (search_filter)
			m_search_result_count++;

		return selection_filter and search_filter;

	}
bool SortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
    QRegExp rx = filterRegExp();
    if (rx.isEmpty())
        return true;
    QAbstractItemModel *model = sourceModel();
    if (filterRole().isEmpty()) {
        QHash<int, QByteArray> roles = roleNames();
        QHashIterator<int, QByteArray> it(roles);
        while (it.hasNext()) {
            it.next();
            QModelIndex sourceIndex = model->index(sourceRow, 0, sourceParent);
            QString key = model->data(sourceIndex, it.key()).toString();
            if (key.contains(rx))
                return true;
        }
        return false;
    }
    QModelIndex sourceIndex = model->index(sourceRow, 0, sourceParent);
    if (!sourceIndex.isValid())
        return true;
    QString key = model->data(sourceIndex, roleKey(filterRole())).toString();
    return key.contains(rx);
}
bool QgsPluginSortFilterProxyModel::filterByPhrase( QModelIndex &index ) const
{
  switch ( filterRole() )
  {
    case PLUGIN_TAGS_ROLE:
      // search in tags only
      return sourceModel()->data( index, PLUGIN_TAGS_ROLE ).toString().contains( filterRegExp() );
    case 0:
      // full search: name + description + tags + author
      return sourceModel()->data( index, PLUGIN_DESCRIPTION_ROLE ).toString().contains( filterRegExp() )
             || sourceModel()->data( index, PLUGIN_AUTHOR_ROLE ).toString().contains( filterRegExp() )
             || sourceModel()->data( index, Qt::DisplayRole ).toString().contains( filterRegExp() )
             || sourceModel()->data( index, PLUGIN_TAGS_ROLE ).toString().contains( filterRegExp() );
    default:
      // unknown filter mode, return nothing
      return false;
  }
}
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);
}
Example #14
0
bool SortFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
    if (filterRole() == "fromNow" && sourceModel()->roleNames().values().contains("start")) {
        QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
        QDateTime date = sourceModel()->data(index, sourceModel()->roleNames().key("start")).toDateTime();
        QDateTime currentDateTime = QDateTime::currentDateTime();
        int localTimeZoneOffset = currentDateTime.offsetFromUtc();
        currentDateTime.setMSecsSinceEpoch(currentDateTime.currentMSecsSinceEpoch() + localTimeZoneOffset*1000);
        return date >= currentDateTime;
    } else {
        if (m_hide && sourceModel()->roleNames().values().contains("hideInSchedule")) {
            QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
            bool willBeHidden = sourceModel()->data(index, sourceModel()->roleNames().key("hideInSchedule")).toBool();
            if (willBeHidden)
                return false;
        }
        return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
    }
}
// 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) ;
}
Example #16
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);
}
bool ApplicationFilterModel::filterAcceptsRow(int sourceRow,
                                              const QModelIndex &sourceParent)
    const
{
    PANORAMA_PRIVATE(const ApplicationFilterModel);
    if(sourceRow < priv->drop || (priv->take && (sourceRow >= priv->drop + priv->take)))
        return false;

    if(filterRole() == ApplicationModel::Categories)
    {
        const QModelIndex idx = sourceModel()->index(sourceRow, 0,
                                                     sourceParent);
        QStringList categories =
                sourceModel()->data(idx, ApplicationModel::Categories)
                    .toStringList();

        foreach(const QString &category, categories)
            if(filterRegExp().exactMatch(category))
                return true;

        return false;
    }
    else
        return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);