QAdvanced Item View  0.4
The QAIV (Qt Advanced Item Views) library provides GUI and utility classes extending the capabilities of the Qt item views.
 All Classes Functions Variables Enumerations Enumerator Properties Groups Pages
qaiv.h
1 /******************************************************************************
2 ** This file is part of qadvanceditemviews.
3 **
4 ** Copyright (c) 2011-2013 Martin Hoppe martin@2x2hoppe.de
5 **
6 ** qadvanceditemviews is free software: you can redistribute it
7 ** and/or modify it under the terms of the GNU Lesser General
8 ** Public License as published by the Free Software Foundation,
9 ** either version 3 of the License, or (at your option) any
10 ** later version.
11 **
12 ** qadvanceditemviews is distributed in the hope that it will be
13 ** useful, but WITHOUT ANY WARRANTY; without even the implied
14 ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 ** See the GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU Lesser General Public
18 ** License along with qadvanceditemviews.
19 ** If not, see <http://www.gnu.org/licenses/>.
20 ******************************************************************************/
21 #ifndef QAVI_H
22 #define QAVI_H
23 
24 #include <qaivlib_global.h>
25 
26 #include <QAbstractProxyModel>
27 
73 class QAIVLIBSHARED_EXPORT QAdvancedItemViews
75 {
76 public:
80  FilterMode,
81  HighlightMode
82  };
85  MatchNormal, /*<! The filter matches if the condition is fullfilled */
86  MatchInverted /*<! The filter matches if the condition is not fullfilled */
87  };
89  enum ItemDataRole {
90  AutoFilterRole = Qt::UserRole + 42101,
91  ValueFilterTypeRole,
92  DefaultFilterTypeRole,
93  ColumnFilterTypesRole,
94  ConditionalDecorationRole,
95  SelectionListFilterDataRole,
96  SelectionFilterRole,
97  ValueRole,
98  IconSetsRole
99  };
100 
101 };
102 
103 QAIVLIBSHARED_EXPORT QModelIndex qSourceIndex(const QModelIndex & index);
104 QAIVLIBSHARED_EXPORT const QAbstractItemModel* qSourceModel(const QModelIndex & index);
105 QAIVLIBSHARED_EXPORT QAbstractItemModel* qSourceModel(QAbstractItemModel* model);
106 
111 template <class T>
112 inline T qsourcemodel_cast(const QModelIndex & index)
113 {
114  QModelIndex i(index);
115  T s = qobject_cast<T>(i.model());
116  if (s){
117  return s;
118  }
119  QAbstractProxyModel* p;
120  while((p = qobject_cast<QAbstractProxyModel*>((QAbstractProxyModel*)i.model()))){
121  T s = qobject_cast<T>(p);
122  if (s){
123  return s;
124  }
125  i = p->mapToSource(i);
126  }
127  return 0;
128 }
129 
134 template <class T> inline T qsourcemodel_cast(QAbstractItemModel* model)
135 {
136  QAbstractItemModel* m = model;
137  T s = qobject_cast<T>(m);
138  if (s){
139  return s;
140  }
141  QAbstractProxyModel* p;
142  while((p = qobject_cast<QAbstractProxyModel*>(m))){
143  T s = qobject_cast<T>(p->sourceModel());
144  if (s){
145  return s;
146  }
147  m = p->sourceModel();
148  }
149  return 0;
150 }
151 
156 template <class T>
157 inline T qsourcemodel_cast(const QAbstractItemModel* model)
158 {
159  const QAbstractItemModel* m = model;
160  T s = qobject_cast<T>(m);
161  if (s){
162  return s;
163  }
164  QAbstractProxyModel* p;
165  while((p = qobject_cast<QAbstractProxyModel*>(m))){
166  T s = qobject_cast<T>(p->sourceModel());
167  if (s){
168  return s;
169  }
170  m = p->sourceModel();
171  }
172  return 0;
173 }
174 
175 #endif // QADVANCEDITEMVIEWS_H
ItemDataRole
This enum decribes additional item data roles.
Definition: qaiv.h:89
T qsourcemodel_cast(const QModelIndex &index)
Definition: qaiv.h:112
FilterProxyMode
This enum describes the modes of a filter proxy.
Definition: qaiv.h:79
QAdvancedItemViews.
Definition: qaiv.h:74
FilterMatchMode
This enumj describes the filter match mode.
Definition: qaiv.h:84