HAL
gatelibrary_proxy_model.cpp
Go to the documentation of this file.
3 
4 #include "gui/gui_globals.h"
5 
6 namespace hal
7 {
9  {
10  }
11 
12  bool GatelibraryProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
13  {
14  if(filterRegularExpression().pattern().isEmpty())
15  return true;
16 
17  QModelIndex source_index = sourceModel()->index(sourceRow, filterKeyColumn(), sourceParent);
18  if(source_index.isValid())
19  {
20  if (sourceModel()->data(source_index, filterRole()).toString().contains(filterRegularExpression()))
21  return true;
22  else
23  return false;
24  }
25  return true;
26  }
27 
28  bool GatelibraryProxyModel::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const
29  {
30  if (source_left.column() == 0 || source_left.column() == 2)
31  {
32  QString name_left = source_left.data().toString();
33  QString name_right = source_right.data().toString();
34 
36  {
37  name_left = name_left.toLower();
38  name_right = name_right.toLower();
39  }
40 
41  return gui_utility::compare(mSortMechanism, name_left, name_right);
42  }
43  else if (source_left.column() == 1)
44  return source_left.data().toInt() < source_right.data().toInt();
45  else if (source_left.column() == 3)
46  return source_left.data(Qt::UserRole).toLongLong() < source_right.data(Qt::UserRole).toLongLong();
47  else
48  {
49  return true;
50  }
51 
52  }
53 
55  {
56  return mSortMechanism;
57  }
58 
60  {
61  mSortMechanism = sortMechanism;
62  invalidate();
63  }
64 
66  {
67  mSearchString = text;
68  mSearchOptions = SearchOptions(options);
70  }
71 }
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
void setSortMechanism(gui_utility::mSortMechanism sortMechanism)
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override
GatelibraryProxyModel(QObject *parent=nullptr)
gui_utility::mSortMechanism sortMechanism()
void startSearch(QString text, int options)
SearchOptions mSearchOptions
int compare(mSortMechanism mechanism, QString a, QString b)
Definition: sort.cpp:153
int column() const const
QVariant data(int role) const const
bool isValid() const const
virtual QVariant data(const QModelIndex &index, int role) const const override
QString toLower() const const
CaseInsensitive
UserRole
int toInt(bool *ok) const const
qlonglong toLongLong(bool *ok) const const
QString toString() const const