/ filters / filter.cpp
filter.cpp
 1  #include "filter.h"
 2  #include "qqmlsortfilterproxymodel.h"
 3  
 4  namespace qqsfpm {
 5  
 6  /*!
 7      \qmltype Filter
 8      \qmlabstract
 9      \inqmlmodule SortFilterProxyModel
10      \ingroup Filters
11      \brief Base type for the \l SortFilterProxyModel filters.
12  
13      The Filter type cannot be used directly in a QML file.
14      It exists to provide a set of common properties and methods,
15      available across all the other filter types that inherit from it.
16      Attempting to use the Filter type directly will result in an error.
17  */
18  
19  Filter::Filter(QObject *parent) : QObject(parent)
20  {
21  }
22  
23  /*!
24      \qmlproperty bool Filter::enabled
25  
26      This property holds whether the filter is enabled.
27      A disabled filter will accept every rows unconditionally (even if it's inverted).
28  
29      By default, filters are enabled.
30  */
31  bool Filter::enabled() const
32  {
33      return m_enabled;
34  }
35  
36  void Filter::setEnabled(bool enabled)
37  {
38      if (m_enabled == enabled)
39          return;
40  
41      m_enabled = enabled;
42      Q_EMIT enabledChanged();
43      Q_EMIT invalidated();
44  }
45  
46  /*!
47      \qmlproperty bool Filter::inverted
48  
49      This property holds whether the filter is inverted.
50      When a filter is inverted, a row normally accepted would be rejected, and vice-versa.
51  
52      By default, filters are not inverted.
53  */
54  bool Filter::inverted() const
55  {
56      return m_inverted;
57  }
58  
59  void Filter::setInverted(bool inverted)
60  {
61      if (m_inverted == inverted)
62          return;
63  
64      m_inverted = inverted;
65      Q_EMIT invertedChanged();
66      invalidate();
67  }
68  
69  bool Filter::filterAcceptsRow(const QModelIndex &sourceIndex, const QQmlSortFilterProxyModel& proxyModel) const
70  {
71      return !m_enabled || filterRow(sourceIndex, proxyModel) ^ m_inverted;
72  }
73  
74  void Filter::proxyModelCompleted(const QQmlSortFilterProxyModel& proxyModel)
75  {
76      Q_UNUSED(proxyModel)
77  }
78  
79  void Filter::invalidate()
80  {
81      if (m_enabled)
82          Q_EMIT invalidated();
83  }
84  
85  }