qBittorrent
SearchSortModel Class Referencefinal

#include <searchsortmodel.h>

Inheritance diagram for SearchSortModel:
Collaboration diagram for SearchSortModel:

Public Types

enum  SearchColumn {
  NAME , SIZE , SEEDS , LEECHES ,
  ENGINE_URL , DL_LINK , DESC_LINK , NB_SEARCH_COLUMNS
}
 
enum  SearchDataRole { UnderlyingDataRole = Qt::UserRole }
 

Public Member Functions

 SearchSortModel (QObject *parent=nullptr)
 
void enableNameFilter (bool enabled)
 
void setNameFilter (const QString &searchTerm={})
 
void setSizeFilter (qint64 minSize, qint64 maxSize)
 Sets parameters for filtering by size. More...
 
void setSeedsFilter (int minSeeds, int maxSeeds)
 Sets parameters for filtering by seeds number. More...
 
void setLeechesFilter (int minLeeches, int maxLeeches)
 Sets parameters for filtering by leeches number. More...
 
bool isNameFilterEnabled () const
 
QString searchTerm () const
 
int minSeeds () const
 
int maxSeeds () const
 
qint64 minSize () const
 
qint64 maxSize () const
 

Protected Member Functions

bool lessThan (const QModelIndex &left, const QModelIndex &right) const override
 
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override
 

Private Types

using base = QSortFilterProxyModel
 

Private Attributes

bool m_isNameFilterEnabled
 
QString m_searchTerm
 
QStringList m_searchTermWords
 
int m_minSeeds
 
int m_maxSeeds
 
int m_minLeeches
 
int m_maxLeeches
 
qint64 m_minSize
 
qint64 m_maxSize
 
Utils::Compare::NaturalLessThan< Qt::CaseInsensitive > m_naturalLessThan
 

Detailed Description

Definition at line 36 of file searchsortmodel.h.

Member Typedef Documentation

◆ base

using SearchSortModel::base = QSortFilterProxyModel
private

Definition at line 38 of file searchsortmodel.h.

Member Enumeration Documentation

◆ SearchColumn

Enumerator
NAME 
SIZE 
SEEDS 
LEECHES 
ENGINE_URL 
DL_LINK 
DESC_LINK 
NB_SEARCH_COLUMNS 

Definition at line 41 of file searchsortmodel.h.

◆ SearchDataRole

Enumerator
UnderlyingDataRole 

Definition at line 53 of file searchsortmodel.h.

54  {
55  UnderlyingDataRole = Qt::UserRole
56  };

Constructor & Destructor Documentation

◆ SearchSortModel()

SearchSortModel::SearchSortModel ( QObject *  parent = nullptr)
explicit

Definition at line 33 of file searchsortmodel.cpp.

34  : base(parent)
35  , m_isNameFilterEnabled(false)
36  , m_minSeeds(0)
37  , m_maxSeeds(-1)
38  , m_minLeeches(0)
39  , m_maxLeeches(-1)
40  , m_minSize(0)
41  , m_maxSize(-1)
42 {
43  setSortRole(UnderlyingDataRole);
44  setFilterRole(UnderlyingDataRole);
45 }
QSortFilterProxyModel base

References UnderlyingDataRole.

Member Function Documentation

◆ enableNameFilter()

void SearchSortModel::enableNameFilter ( bool  enabled)

Definition at line 47 of file searchsortmodel.cpp.

48 {
49  m_isNameFilterEnabled = enabled;
50 }

References m_isNameFilterEnabled.

Referenced by SearchJobWidget::updateFilter().

Here is the caller graph for this function:

◆ filterAcceptsRow()

bool SearchSortModel::filterAcceptsRow ( int  sourceRow,
const QModelIndex &  sourceParent 
) const
overrideprotected

Definition at line 131 of file searchsortmodel.cpp.

132 {
133  const QAbstractItemModel *const sourceModel = this->sourceModel();
134 
135  if (m_isNameFilterEnabled && !m_searchTerm.isEmpty())
136  {
137  const QString name = sourceModel->data(sourceModel->index(sourceRow, NAME, sourceParent), UnderlyingDataRole).toString();
138  for (const QString &word : asConst(m_searchTermWords))
139  {
140  if (!name.contains(word, Qt::CaseInsensitive))
141  return false;
142  }
143  }
144 
145  if ((m_minSize > 0) || (m_maxSize >= 0))
146  {
147  const qlonglong size = sourceModel->data(sourceModel->index(sourceRow, SIZE, sourceParent), UnderlyingDataRole).toLongLong();
148  if (((m_minSize > 0) && (size < m_minSize))
149  || ((m_maxSize > 0) && (size > m_maxSize)))
150  return false;
151  }
152 
153  if ((m_minSeeds > 0) || (m_maxSeeds >= 0))
154  {
155  const int seeds = sourceModel->data(sourceModel->index(sourceRow, SEEDS, sourceParent), UnderlyingDataRole).toInt();
156  if (((m_minSeeds > 0) && (seeds < m_minSeeds))
157  || ((m_maxSeeds > 0) && (seeds > m_maxSeeds)))
158  return false;
159  }
160 
161  if ((m_minLeeches > 0) || (m_maxLeeches >= 0))
162  {
163  const int leeches = sourceModel->data(sourceModel->index(sourceRow, LEECHES, sourceParent), UnderlyingDataRole).toInt();
164  if (((m_minLeeches > 0) && (leeches < m_minLeeches))
165  || ((m_maxLeeches > 0) && (leeches > m_maxLeeches)))
166  return false;
167  }
168 
169  return base::filterAcceptsRow(sourceRow, sourceParent);
170 }
QStringList m_searchTermWords
constexpr std::add_const_t< T > & asConst(T &t) noexcept
Definition: global.h:42

References asConst(), LEECHES, m_isNameFilterEnabled, m_maxLeeches, m_maxSeeds, m_maxSize, m_minLeeches, m_minSeeds, m_minSize, m_searchTerm, m_searchTermWords, NAME, SEEDS, SIZE, and UnderlyingDataRole.

Here is the call graph for this function:

◆ isNameFilterEnabled()

bool SearchSortModel::isNameFilterEnabled ( ) const

Definition at line 84 of file searchsortmodel.cpp.

85 {
86  return m_isNameFilterEnabled;
87 }

References m_isNameFilterEnabled.

◆ lessThan()

bool SearchSortModel::lessThan ( const QModelIndex &  left,
const QModelIndex &  right 
) const
overrideprotected

Definition at line 114 of file searchsortmodel.cpp.

115 {
116  switch (sortColumn())
117  {
118  case NAME:
119  case ENGINE_URL:
120  {
121  const QString strL = left.data().toString();
122  const QString strR = right.data().toString();
123  return m_naturalLessThan(strL, strR);
124  }
125  break;
126  default:
127  return base::lessThan(left, right);
128  };
129 }
Utils::Compare::NaturalLessThan< Qt::CaseInsensitive > m_naturalLessThan

References ENGINE_URL, m_naturalLessThan, and NAME.

◆ maxSeeds()

int SearchSortModel::maxSeeds ( ) const

Definition at line 99 of file searchsortmodel.cpp.

100 {
101  return m_maxSeeds;
102 }

References m_maxSeeds.

Referenced by setSeedsFilter().

Here is the caller graph for this function:

◆ maxSize()

qint64 SearchSortModel::maxSize ( ) const

Definition at line 109 of file searchsortmodel.cpp.

110 {
111  return m_maxSize;
112 }

References m_maxSize.

Referenced by setSizeFilter().

Here is the caller graph for this function:

◆ minSeeds()

int SearchSortModel::minSeeds ( ) const

Definition at line 94 of file searchsortmodel.cpp.

95 {
96  return m_minSeeds;
97 }

References m_minSeeds.

Referenced by setSeedsFilter().

Here is the caller graph for this function:

◆ minSize()

qint64 SearchSortModel::minSize ( ) const

Definition at line 104 of file searchsortmodel.cpp.

105 {
106  return m_minSize;
107 }

References m_minSize.

Referenced by setSizeFilter().

Here is the caller graph for this function:

◆ searchTerm()

QString SearchSortModel::searchTerm ( ) const

Definition at line 89 of file searchsortmodel.cpp.

90 {
91  return m_searchTerm;
92 }

References m_searchTerm.

Referenced by setNameFilter().

Here is the caller graph for this function:

◆ setLeechesFilter()

void SearchSortModel::setLeechesFilter ( int  minLeeches,
int  maxLeeches 
)

Sets parameters for filtering by leeches number.

Parameters
minLeechesminimal number of leechers
maxLeechesmaximal number of leechers, negative value to disable filtering

Definition at line 78 of file searchsortmodel.cpp.

79 {
80  m_minLeeches = std::max(0, minLeeches);
81  m_maxLeeches = std::max(-1, maxLeeches);
82 }

References m_maxLeeches, and m_minLeeches.

◆ setNameFilter()

void SearchSortModel::setNameFilter ( const QString &  searchTerm = {})

Definition at line 52 of file searchsortmodel.cpp.

53 {
55  if ((searchTerm.length() > 2)
56  && searchTerm.startsWith(QLatin1Char('"')) && searchTerm.endsWith(QLatin1Char('"')))
57  {
58  m_searchTermWords = QStringList(m_searchTerm.mid(1, m_searchTerm.length() - 2));
59  }
60  else
61  {
62  m_searchTermWords = searchTerm.split(QLatin1Char(' '), Qt::SkipEmptyParts);
63  }
64 }
QString searchTerm() const

References m_searchTerm, m_searchTermWords, and searchTerm().

Referenced by SearchJobWidget::SearchJobWidget().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSeedsFilter()

void SearchSortModel::setSeedsFilter ( int  minSeeds,
int  maxSeeds 
)

Sets parameters for filtering by seeds number.

Parameters
minSeedsminimal number of seeders
maxSeedsmaximal number of seeders, negative value to disable filtering

Definition at line 72 of file searchsortmodel.cpp.

73 {
74  m_minSeeds = std::max(0, minSeeds);
75  m_maxSeeds = std::max(-1, maxSeeds);
76 }
int maxSeeds() const
int minSeeds() const

References m_maxSeeds, m_minSeeds, maxSeeds(), and minSeeds().

Referenced by SearchJobWidget::updateFilter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSizeFilter()

void SearchSortModel::setSizeFilter ( qint64  minSize,
qint64  maxSize 
)

Sets parameters for filtering by size.

Parameters
minSizeminimal size in bytes
maxSizemaximal size in bytes, negative value to disable filtering

Definition at line 66 of file searchsortmodel.cpp.

67 {
68  m_minSize = std::max(static_cast<qint64>(0), minSize);
69  m_maxSize = std::max(static_cast<qint64>(-1), maxSize);
70 }
qint64 minSize() const
qint64 maxSize() const

References m_maxSize, m_minSize, maxSize(), and minSize().

Referenced by SearchJobWidget::updateFilter().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_isNameFilterEnabled

bool SearchSortModel::m_isNameFilterEnabled
private

Definition at line 93 of file searchsortmodel.h.

Referenced by enableNameFilter(), filterAcceptsRow(), and isNameFilterEnabled().

◆ m_maxLeeches

int SearchSortModel::m_maxLeeches
private

Definition at line 97 of file searchsortmodel.h.

Referenced by filterAcceptsRow(), and setLeechesFilter().

◆ m_maxSeeds

int SearchSortModel::m_maxSeeds
private

Definition at line 96 of file searchsortmodel.h.

Referenced by filterAcceptsRow(), maxSeeds(), and setSeedsFilter().

◆ m_maxSize

qint64 SearchSortModel::m_maxSize
private

Definition at line 98 of file searchsortmodel.h.

Referenced by filterAcceptsRow(), maxSize(), and setSizeFilter().

◆ m_minLeeches

int SearchSortModel::m_minLeeches
private

Definition at line 97 of file searchsortmodel.h.

Referenced by filterAcceptsRow(), and setLeechesFilter().

◆ m_minSeeds

int SearchSortModel::m_minSeeds
private

Definition at line 96 of file searchsortmodel.h.

Referenced by filterAcceptsRow(), minSeeds(), and setSeedsFilter().

◆ m_minSize

qint64 SearchSortModel::m_minSize
private

Definition at line 98 of file searchsortmodel.h.

Referenced by filterAcceptsRow(), minSize(), and setSizeFilter().

◆ m_naturalLessThan

Utils::Compare::NaturalLessThan<Qt::CaseInsensitive> SearchSortModel::m_naturalLessThan
private

Definition at line 100 of file searchsortmodel.h.

Referenced by lessThan().

◆ m_searchTerm

QString SearchSortModel::m_searchTerm
private

Definition at line 94 of file searchsortmodel.h.

Referenced by filterAcceptsRow(), searchTerm(), and setNameFilter().

◆ m_searchTermWords

QStringList SearchSortModel::m_searchTermWords
private

Definition at line 95 of file searchsortmodel.h.

Referenced by filterAcceptsRow(), and setNameFilter().


The documentation for this class was generated from the following files: