HAL
module_proxy_model.cpp
Go to the documentation of this file.
3 
4 #include "gui/gui_globals.h"
5 
6 namespace hal
7 {
8  ModuleProxyModel::ModuleProxyModel(QObject* parent) : SearchProxyModel(parent), mSortMechanism(gui_utility::mSortMechanism::lexical), mFilterNets(true), mFilterGates(true)
9  {
10  // QTS PROXY MODELS ARE DUMB, IMPLEMENT CUSTOM SOLUTION OR SWITCH TO A DIFFERENT FILTER METHOD
11 
12  // IN VIEW
13  // EVERY TIME FILTER CHANGES / ITEM GETS ADDED MODIFY LOCAL DATA STRUCTURE TO REFLECT CURRENT ITEM VISUALS
14  // STYLED DELEGATES USE THAT DATA STRUCTURE TO DRAW THEMSELVES
15  }
16 
18  {
19  mFilterNets = !mFilterNets;
21  return mFilterNets;
22  }
23 
25  {
26  mFilterGates = !mFilterGates;
28  return mFilterGates;
29  }
30 
31  bool ModuleProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
32  {
33  QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
34  if(!sourceIndex.isValid())
35  return true;
36  auto item = static_cast<ModuleItem*>(sourceIndex.internalPointer());
37 
38  if(mFilterGates && item->getType() == ModuleItem::TreeItemType::Gate)
39  return false;
40  if(mFilterNets && item->getType() == ModuleItem::TreeItemType::Net)
41  return false;
42 
43  return checkRowRecursion(sourceRow, sourceParent, 0, 2);
44  }
45 
46  bool ModuleProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
47  {
48  ModuleItem* item_left = static_cast<ModuleItem*>(source_left.internalPointer());
49  ModuleItem* item_right = static_cast<ModuleItem*>(source_right.internalPointer());
50  if(item_left->getType() != item_right->getType())
51  return item_left->getType() < item_right->getType();
52 
53  QString name_left = source_left.data().toString();
54  QString name_right = source_right.data().toString();
56  {
57  name_left = name_left.toLower();
58  name_right = name_right.toLower();
59  }
60 
61  return gui_utility::compare(mSortMechanism, name_left, name_right);
62  }
63 
65  {
66  return mSortMechanism;
67  }
68 
70  {
71  mSortMechanism = sortMechanism;
72  invalidate();
73  }
74  void ModuleProxyModel::startSearch(QString text, int options)
75  {
76  mSearchString = text;
77  mSearchOptions = SearchOptions(options);
79  }
80  bool ModuleProxyModel::checkRowRecursion(int sourceRow, const QModelIndex& sourceParent, int startIndex, int endIndex, int offset) const
81  {
82  QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
83  if(!sourceIndex.isValid())
84  return true;
85  auto item = static_cast<ModuleItem*>(sourceIndex.internalPointer());
86  QModelIndex currentIndex = sourceModel()->index(sourceRow, 0, sourceParent);
87 
88  if(mFilterGates && item->getType() == ModuleItem::TreeItemType::Gate)
89  {
90  return false;
91  }
92  if(mFilterNets && item->getType() == ModuleItem::TreeItemType::Net)
93  {
94  return false;
95  }
96 
97  if (checkRow(sourceRow, sourceParent, startIndex, endIndex, offset))
98  return true;
99 
100  int nrows = sourceModel()->rowCount(currentIndex);
101  for (int irow = 0; irow < nrows; irow++)
102  {
103  if (checkRowRecursion(irow, currentIndex, startIndex, endIndex, offset))
104  return true;
105  }
106  return false;
107  }
108 }
An item in the ModuleModel.
Definition: module_item.h:48
TreeItemType getType() const
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override
bool checkRowRecursion(int sourceRow, const QModelIndex &sourceParent, int startIndex, int endIndex, int offset=0) const override
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
void setSortMechanism(gui_utility::mSortMechanism sortMechanism)
void startSearch(QString text, int options) override
gui_utility::mSortMechanism sortMechanism()
ModuleProxyModel(QObject *parent=nullptr)
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
QVariant data(int role) const const
void * internalPointer() const const
bool isValid() const const
QString toLower() const const
CaseInsensitive
QString toString() const const