filterabletreemodelsortfilterproxymodel.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore::core
19  * @author Cedric Seehausen (usdnr at kit dot edu)
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
27 
28 #include <QDate>
29 #include <QModelIndexList>
30 #include <QString>
31 
33 
34 #include "treeitem.h"
35 
37  QSortFilterProxyModel(0)
38 {
39  qRegisterMetaType<ScenarioItem*>();
40  qRegisterMetaType<ApplicationDatabaseItem*>();
41  qRegisterMetaType<OpenScenarioItem*>();
42  qRegisterMetaType<SettingsItem*>();
43 }
44 
45 QVariant
46 FilterableTreeModelSortFilterProxyModel::data(const QModelIndex& proxy_index, int role) const
47 {
48  switch (role)
49  {
50  case SCENARIOITEMSOURCE:
53  case SETTINGSITEMSOURCE:
54  {
55  QModelIndex source_index = mapToSource(proxy_index);
56  return sourceModel()->data(source_index, role);
57  }
58  case SCENARIOITEMPROXY:
59  return QVariant::fromValue(
60  reinterpret_cast<ScenarioItem*>(proxy_index.internalPointer()));
62  return QVariant::fromValue(
63  reinterpret_cast<ApplicationDatabaseItem*>(proxy_index.internalPointer()));
65  return QVariant::fromValue(
66  reinterpret_cast<OpenScenarioItem*>(proxy_index.internalPointer()));
67  case SETTINGSITEMPROXY:
68  return QVariant::fromValue(
69  reinterpret_cast<SettingsItem*>(proxy_index.internalPointer()));
70 
71  default:
72  return QSortFilterProxyModel::data(proxy_index, role);
73  }
74 }
75 
76 bool
78  const QModelIndex& sourceParent) const
79 {
80  QModelIndexList childrenColumn1;
81 
82  childrenColumn1 << sourceModel()->index(sourceRow, 0, sourceParent);
83 
84  //descend through the generations.
85  for (int i = 0; i < childrenColumn1.size(); ++i)
86  {
87  for (int j = 0; j < sourceModel()->rowCount(childrenColumn1[i]); ++j)
88  {
89  childrenColumn1 << childrenColumn1[i].child(j, 0);
90  }
91  }
92 
93  bool result = false;
94  for (int i = 0; i < childrenColumn1.size(); ++i)
95  {
96  if (sourceModel()->data(childrenColumn1[i]).toString().contains(filterRegExp()))
97  {
98  result = true;
99  break;
100  }
101  }
102 
103  if (sourceModel()->columnCount() > 1)
104  {
105  QModelIndexList childrenColumn2;
106 
107  childrenColumn2 << sourceModel()->index(sourceRow, 1, sourceParent);
108 
109  //descend through the generations.
110  for (int i = 0; i < childrenColumn2.size(); ++i)
111  {
112  for (int j = 0; j < sourceModel()->rowCount(childrenColumn2[i]); ++j)
113  {
114  childrenColumn2 << childrenColumn2[i].child(j, 1);
115  }
116  }
117 
118  for (int i = 0; i < childrenColumn2.size(); ++i)
119  {
120  if (sourceModel()->data(childrenColumn2[i]).toString().contains(filterRegExp()))
121  {
122  result = true;
123  break;
124  }
125  }
126  }
127 
128  return result;
129 }
ScenarioItem
TreeItem representing data contained in a Scenario or an Application.
Definition: scenarioitem.h:40
treeitem.h
FilterableTreeModelSortFilterProxyModel::filterAcceptsRow
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Returns whether the filter accepts a row.
Definition: filterabletreemodelsortfilterproxymodel.cpp:77
filterabletreemodelsortfilterproxymodel.h
SCENARIOITEMSOURCE
@ SCENARIOITEMSOURCE
Definition: treeitem.h:37
OPENSCENARIOITEMSOURCE
@ OPENSCENARIOITEMSOURCE
Definition: treeitem.h:43
SETTINGSITEMSOURCE
@ SETTINGSITEMSOURCE
Definition: treeitem.h:39
FilterableTreeModelSortFilterProxyModel::FilterableTreeModelSortFilterProxyModel
FilterableTreeModelSortFilterProxyModel()
Constructor that registers the used meta-types.
Definition: filterabletreemodelsortfilterproxymodel.cpp:36
ApplicationDatabaseItem
This class represents an item in the ApplicationDatabaseView.
Definition: applicationdatabaseitem.h:36
APPLICATIONITEMSOURCE
@ APPLICATIONITEMSOURCE
Definition: treeitem.h:42
SETTINGSITEMPROXY
@ SETTINGSITEMPROXY
Definition: treeitem.h:40
APPLICATIONITEMPROXY
@ APPLICATIONITEMPROXY
Definition: treeitem.h:41
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
OPENSCENARIOITEMPROXY
@ OPENSCENARIOITEMPROXY
Definition: treeitem.h:44
SCENARIOITEMPROXY
@ SCENARIOITEMPROXY
Definition: treeitem.h:38
FilterableTreeModelSortFilterProxyModel::data
QVariant data(const QModelIndex &proxy_index, int role) const override
Returns the data stored at the specified location, based on the given role.
Definition: filterabletreemodelsortfilterproxymodel.cpp:46
Logging.h
SettingsItem
Definition: settingsitem.h:32
OpenScenarioItem
Item in the TreeItemView. Every item represents a Scenario.
Definition: openscenarioitem.h:38