/ filters / rolefilter.cpp
rolefilter.cpp
 1  #include "rolefilter.h"
 2  #include "qqmlsortfilterproxymodel.h"
 3  
 4  namespace qqsfpm {
 5  
 6  /*!
 7      \qmltype RoleFilter
 8      \qmlabstract
 9      \inherits Filter
10      \inqmlmodule SortFilterProxyModel
11      \ingroup Filters
12      \brief Base type for filters based on a source model role.
13  
14      The RoleFilter type cannot be used directly in a QML file.
15      It exists to provide a set of common properties and methods,
16      available across all the other filter types that inherit from it.
17      Attempting to use the RoleFilter type directly will result in an error.
18  */
19  
20  /*!
21      \qmlproperty string RoleFilter::roleName
22  
23      This property holds the role name that the filter is using to query the source model's data when filtering items.
24  */
25  const QString& RoleFilter::roleName() const
26  {
27      return m_roleName;
28  }
29  
30  void RoleFilter::setRoleName(const QString& roleName)
31  {
32      if (m_roleName == roleName)
33          return;
34  
35      m_roleName = roleName;
36      Q_EMIT roleNameChanged();
37      invalidate();
38  }
39  
40  QVariant RoleFilter::sourceData(const QModelIndex &sourceIndex, const QQmlSortFilterProxyModel& proxyModel) const
41  {
42      return proxyModel.sourceData(sourceIndex, m_roleName);
43  }
44  
45  }