2 connectionfilterproxymodel.cpp
4 This file is part of GammaRay, the Qt application inspection and
7 Copyright (C) 2010-2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8 Author: Volker Krause <volker.krause@kdab.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "connectionfilterproxymodel.h"
25 #include "connectionmodel.h"
27 using namespace GammaRay
;
29 ConnectionFilterProxyModel::ConnectionFilterProxyModel(QObject
*parent
)
30 : QSortFilterProxyModel(parent
),
34 setDynamicSortFilter(true);
37 void ConnectionFilterProxyModel::filterReceiver(QObject
*receiver
)
39 m_receiver
= receiver
;
43 void ConnectionFilterProxyModel::filterSender(QObject
*sender
)
49 bool ConnectionFilterProxyModel::filterAcceptsRow(int source_row
,
50 const QModelIndex
&source_parent
) const
52 const QModelIndex sourceIndex
= sourceModel()->index(source_row
, 0, source_parent
);
54 sourceIndex
.data(ConnectionModel::SenderRole
).value
<QObject
*>() != m_sender
) {
58 sourceIndex
.data(ConnectionModel::ReceiverRole
).value
<QObject
*>() != m_receiver
) {
61 return QSortFilterProxyModel::filterAcceptsRow(source_row
, source_parent
);
64 bool ConnectionFilterProxyModel::filterAcceptsColumn(int source_column
,
65 const QModelIndex
&source_parent
) const
67 if (m_sender
&& source_column
== 0) {
70 if (m_receiver
&& source_column
== 2) {
73 return QSortFilterProxyModel::filterAcceptsColumn(source_column
, source_parent
);
76 bool ConnectionFilterProxyModel::lessThan(const QModelIndex
&left
, const QModelIndex
&right
) const
78 const bool leftValid
= left
.data(ConnectionModel::ConnectionValidRole
).toBool();
79 const bool rightValid
= right
.data(ConnectionModel::ConnectionValidRole
).toBool();
80 if (leftValid
== rightValid
) {
81 return QSortFilterProxyModel::lessThan(left
, right
);
87 #include "connectionfilterproxymodel.moc"