d/control: Recommend gdb
[gammaray-debian.git] / proxydetacher.cpp
blob9e88cce8e019a6a549354c0c95b801811ad2ca3a
1 /*
2 proxydetacher.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: Milian Wolff <milian.wolff@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 "proxydetacher.h"
26 #include <QWidget>
27 #include <QAbstractProxyModel>
28 #include <QHideEvent>
29 #include <QDebug>
31 using namespace GammaRay;
33 ProxyDetacher::ProxyDetacher(QWidget *widget,
34 QAbstractProxyModel *proxyModel,
35 QAbstractItemModel *sourceModel)
36 : QObject(widget),
37 m_widget(widget),
38 m_proxy(proxyModel),
39 m_source(sourceModel)
41 widget->installEventFilter(this);
44 bool ProxyDetacher::eventFilter(QObject *obj, QEvent *e)
46 Q_ASSERT(obj == m_widget);
48 if (dynamic_cast<QHideEvent*>(e)) {
49 Q_ASSERT(m_proxy->sourceModel() == m_source);
50 m_proxy->setSourceModel(0);
51 } else if (dynamic_cast<QShowEvent*>(e)) {
52 Q_ASSERT(!m_proxy->sourceModel());
53 m_proxy->setSourceModel(m_source);
56 return QObject::eventFilter(obj, e);
59 #include "proxydetacher.moc"