d/control: Recommend gdb
[gammaray-debian.git] / connectionfilterproxymodel.cpp
blobaf50b96a07732b4efc13c31c9d58e62f6fb7e514
1 /*
2 connectionfilterproxymodel.cpp
4 This file is part of GammaRay, the Qt application inspection and
5 manipulation tool.
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),
31 m_receiver(0),
32 m_sender(0)
34 setDynamicSortFilter(true);
37 void ConnectionFilterProxyModel::filterReceiver(QObject *receiver)
39 m_receiver = receiver;
40 invalidateFilter();
43 void ConnectionFilterProxyModel::filterSender(QObject *sender)
45 m_sender = sender;
46 invalidateFilter();
49 bool ConnectionFilterProxyModel::filterAcceptsRow(int source_row,
50 const QModelIndex &source_parent) const
52 const QModelIndex sourceIndex = sourceModel()->index(source_row, 0, source_parent);
53 if (m_sender &&
54 sourceIndex.data(ConnectionModel::SenderRole).value<QObject*>() != m_sender) {
55 return false;
57 if (m_receiver &&
58 sourceIndex.data(ConnectionModel::ReceiverRole).value<QObject*>() != m_receiver) {
59 return false;
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) {
68 return false;
70 if (m_receiver && source_column == 2) {
71 return false;
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);
82 } else {
83 return rightValid;
87 #include "connectionfilterproxymodel.moc"