HAL  v4.5.0-151-g9638bf6b9
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
grouping_proxy_model.cpp
Go to the documentation of this file.
1 
2 
3 
4 
6 
7 #include <QColor>
8 
9 #include "gui/gui_globals.h"
10 
11 namespace hal
12 {
14  {
15 
16  }
17 
18  bool GroupingProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
19  {
20  return checkRow(sourceRow, sourceParent, 0, 2);
21  }
22 
23  bool GroupingProxyModel::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const
24  {
25  // column 0: name, column 1: ID, column 2: color
26  switch (source_left.column())
27  {
28  case 1:
29  return source_left.data().toInt() < source_right.data().toInt();
30  case 2: {
31  // sort by hue, then saturation, then value (plain hex codes would sort by red component only)
32  const QColor color_left = source_left.data(Qt::BackgroundRole).value<QColor>();
33  const QColor color_right = source_right.data(Qt::BackgroundRole).value<QColor>();
34  if (color_left.hsvHue() != color_right.hsvHue())
35  return color_left.hsvHue() < color_right.hsvHue();
36  if (color_left.hsvSaturation() != color_right.hsvSaturation())
37  return color_left.hsvSaturation() < color_right.hsvSaturation();
38  return color_left.value() < color_right.value();
39  }
40  default: {
41  QString name_left = source_left.data().toString();
42  QString name_right = source_right.data().toString();
43 
45  {
46  name_left = name_left.toLower();
47  name_right = name_right.toLower();
48  }
49 
50  return gui_utility::compare(mSortMechanism, name_left, name_right);
51  }
52  }
53 
54  }
55 
57  {
58  return mSortMechanism;
59  }
60 
62  {
63  mSortMechanism = sortMechanism;
64  invalidate();
65  }
66  void GroupingProxyModel::startSearch(QString text, int options)
67  {
68  mSearchString = text;
69  mSearchOptions = SearchOptions(options);
71  }
72 }
void setSortMechanism(gui_utility::mSortMechanism sortMechanism)
void startSearch(QString text, int options) override
gui_utility::mSortMechanism sortMechanism()
GroupingProxyModel(QObject *parent=nullptr)
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override
SearchOptions mSearchOptions
bool checkRow(int sourceRow, const QModelIndex &sourceParent, int startIndex, int endIndex, int offset=0) const
Should be called inside filterAcceptsRow function and returns true if the source_row,...
int compare(mSortMechanism mechanism, QString a, QString b)
Definition: sort.cpp:153
Definition: defines.h:45
int hsvHue() const const
int hsvSaturation() const const
int value() const const
int column() const const
QVariant data(int role) const const
QString toLower() const const
CaseInsensitive
BackgroundRole
int toInt(bool *ok) const const
QString toString() const const
T value() const const