KDEUI
kviewstatemaintainer.h
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 #ifndef KVIEWSTATEMAINTAINER_H 00023 #define KVIEWSTATEMAINTAINER_H 00024 00025 #include "kdeui_export.h" 00026 00027 #include <QtGui/QItemSelectionModel> 00028 #include <QtGui/QAbstractItemView> 00029 00030 #include "kconfiggroup.h" 00031 #include "ksharedconfig.h" 00032 00033 class KViewStateMaintainerBasePrivate; 00034 00035 class KDEUI_EXPORT KViewStateMaintainerBase : public QObject 00036 { 00037 Q_OBJECT 00038 public: 00039 KViewStateMaintainerBase(KConfigGroup configGroup, QObject* parent = 0); 00040 ~KViewStateMaintainerBase(); 00041 00042 void setSelectionModel(QItemSelectionModel *selectionModel); 00043 QItemSelectionModel *selectionModel() const; 00044 00045 void setView(QAbstractItemView *view); 00046 QAbstractItemView *view() const; 00047 00048 virtual void saveState() = 0; 00049 virtual void restoreState() = 0; 00050 00051 protected: 00052 KConfigGroup configGroup() const; 00053 00054 private: 00055 Q_DECLARE_PRIVATE(KViewStateMaintainerBase) 00056 KViewStateMaintainerBasePrivate * const d_ptr; 00057 00058 Q_PRIVATE_SLOT( d_func(), void _k_modelAboutToBeReset() ) 00059 Q_PRIVATE_SLOT( d_func(), void _k_modelReset() ) 00060 }; 00061 00075 template<typename StateSaver> 00076 class KViewStateMaintainer : public KViewStateMaintainerBase 00077 { 00078 typedef StateSaver StateRestorer; 00079 public: 00080 KViewStateMaintainer(KConfigGroup configGroup, QObject* parent = 0) 00081 : KViewStateMaintainerBase(configGroup, parent) 00082 { 00083 00084 } 00085 00086 /* reimp */ void saveState() 00087 { 00088 StateSaver saver; 00089 saver.setView(view()); 00090 saver.setSelectionModel(selectionModel()); 00091 KConfigGroup cfg = configGroup(); 00092 saver.saveState(cfg); 00093 cfg.sync(); 00094 } 00095 00096 /* reimp */ void restoreState() 00097 { 00098 StateRestorer *restorer = new StateRestorer; 00099 restorer->setView(view()); 00100 restorer->setSelectionModel(selectionModel()); 00101 restorer->restoreState(configGroup()); 00102 } 00103 00104 }; 00105 00106 #endif
KDE 4.6 API Reference