KDEUI
kviewstatemaintainer.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 2010 Klarälvdalens Datakonsult AB, 00003 a KDAB Group company, info@kdab.net, 00004 author Stephen Kelly <stephen@kdab.com> 00005 00006 This library is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU Library General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or (at your 00009 option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, but WITHOUT 00012 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to the 00018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00019 02110-1301, USA. 00020 */ 00021 00022 #include "kviewstatemaintainer.h" 00023 00024 #include <QtCore/QWeakPointer> 00025 00026 class KViewStateMaintainerBasePrivate 00027 { 00028 KViewStateMaintainerBasePrivate(KConfigGroup configGroup, KViewStateMaintainerBase *qq) 00029 : q_ptr(qq), m_configGroup(configGroup) 00030 { 00031 00032 } 00033 00034 Q_DECLARE_PUBLIC(KViewStateMaintainerBase) 00035 KViewStateMaintainerBase * const q_ptr; 00036 00037 void _k_modelAboutToBeReset(); 00038 void _k_modelReset(); 00039 00040 QWeakPointer<QAbstractItemView> m_view; 00041 QWeakPointer<QItemSelectionModel> m_selectionModel; 00042 00043 const KConfigGroup m_configGroup; 00044 }; 00045 00046 void KViewStateMaintainerBasePrivate::_k_modelAboutToBeReset() 00047 { 00048 Q_Q(KViewStateMaintainerBase); 00049 q->saveState(); 00050 } 00051 00052 void KViewStateMaintainerBasePrivate::_k_modelReset() 00053 { 00054 Q_Q(KViewStateMaintainerBase); 00055 q->restoreState(); 00056 } 00057 00058 KViewStateMaintainerBase::KViewStateMaintainerBase(KConfigGroup configPtr, QObject* parent) 00059 : QObject(parent), d_ptr(new KViewStateMaintainerBasePrivate(configPtr, this)) 00060 { 00061 00062 } 00063 00064 KViewStateMaintainerBase::~KViewStateMaintainerBase() 00065 { 00066 delete d_ptr; 00067 } 00068 00069 KConfigGroup KViewStateMaintainerBase::configGroup() const 00070 { 00071 Q_D(const KViewStateMaintainerBase); 00072 return d->m_configGroup; 00073 } 00074 00075 QItemSelectionModel* KViewStateMaintainerBase::selectionModel() const 00076 { 00077 Q_D(const KViewStateMaintainerBase); 00078 if (d->m_selectionModel.isNull()) 00079 return 0; 00080 return d->m_selectionModel.data(); 00081 } 00082 00083 void KViewStateMaintainerBase::setSelectionModel(QItemSelectionModel* selectionModel) 00084 { 00085 Q_D(KViewStateMaintainerBase); 00086 d->m_selectionModel = selectionModel; 00087 00088 if (d->m_view && d->m_view.data()->model()) { 00089 disconnect(d->m_view.data()->model(), SIGNAL(modelAboutToBeReset()), this, SLOT(_k_modelAboutToBeReset())); 00090 disconnect(d->m_view.data()->model(), SIGNAL(modelReset()), this, SLOT(_k_modelReset())); 00091 } 00092 connect(d->m_selectionModel.data()->model(), SIGNAL(modelAboutToBeReset()), SLOT(_k_modelAboutToBeReset()), Qt::UniqueConnection); 00093 connect(d->m_selectionModel.data()->model(), SIGNAL(modelReset()), SLOT(_k_modelReset()), Qt::UniqueConnection); 00094 } 00095 00096 QAbstractItemView* KViewStateMaintainerBase::view() const 00097 { 00098 Q_D(const KViewStateMaintainerBase); 00099 if (d->m_view.isNull()) 00100 return 0; 00101 return d->m_view.data(); 00102 } 00103 00104 void KViewStateMaintainerBase::setView(QAbstractItemView* view) 00105 { 00106 Q_D(KViewStateMaintainerBase); 00107 d->m_view = view; 00108 00109 if (d->m_selectionModel && d->m_selectionModel.data()->model()) { 00110 disconnect(d->m_selectionModel.data()->model(), SIGNAL(modelAboutToBeReset()), this, SLOT(_k_modelAboutToBeReset())); 00111 disconnect(d->m_selectionModel.data()->model(), SIGNAL(modelReset()), this, SLOT(_k_modelReset())); 00112 } 00113 if (d->m_view && d->m_view.data()->model()) { 00114 connect(d->m_view.data()->model(), SIGNAL(modelAboutToBeReset()), SLOT(_k_modelAboutToBeReset()), Qt::UniqueConnection); 00115 connect(d->m_view.data()->model(), SIGNAL(modelReset()), SLOT(_k_modelReset()), Qt::UniqueConnection); 00116 } 00117 } 00118 00119 #include "kviewstatemaintainer.moc"
KDE 4.6 API Reference