KConfigWidgets

kviewstatemaintainer.h
1/*
2 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
3 SPDX-FileContributor: Stephen Kelly <stephen@kdab.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KVIEWSTATEMAINTAINER_H
9#define KVIEWSTATEMAINTAINER_H
10
11#include <KViewStateMaintainerBase>
12
13#include <QAbstractItemView>
14
15#include <KConfigGroup>
16
17/**
18 * @class KViewStateMaintainer kviewstatemaintainer.h KViewStateMaintainer
19 *
20 * @brief Encapsulates the maintenance of state between resets of QAbstractItemModel
21 *
22 * @code
23 * m_collectionViewStateMaintainer = new KViewStateMaintainer<Akonadi::ETMViewStateSaver>(KSharedConfig::openConfig()->group("collectionView"));
24 * m_collectionViewStateMaintainer->setView(m_collectionView);
25 *
26 * m_collectionCheckStateMaintainer = new KViewStateMaintainer<Akonadi::ETMViewStateSaver>(KSharedConfig::openConfig()->group("collectionCheckState"));
27 * m_collectionCheckStateMaintainer->setSelectionModel(m_checkableProxy->selectionModel());
28 * @endcode
29 *
30 * @see KConfigViewStateSaver
31 */
32template<typename StateSaver>
33class KViewStateMaintainer : public KViewStateMaintainerBase
34{
35 typedef StateSaver StateRestorer;
36
37public:
38 KViewStateMaintainer(const KConfigGroup &configGroup, QObject *parent = nullptr)
39 : KViewStateMaintainerBase(parent)
40 , m_configGroup(configGroup)
41 {
42 }
43
44 /* reimp */ void saveState()
45 {
46 StateSaver saver;
47 saver.setView(view());
48 saver.setSelectionModel(selectionModel());
49 saver.saveState(m_configGroup);
50 m_configGroup.sync();
51 }
52
53 /* reimp */ void restoreState()
54 {
55 StateRestorer *restorer = new StateRestorer;
56 restorer->setView(view());
57 restorer->setSelectionModel(selectionModel());
58 restorer->restoreState(m_configGroup);
59 }
60
61private:
62 KConfigGroup m_configGroup;
63};
64
65#endif
bool sync() override
Encapsulates the maintenance of state between resets of QAbstractItemModel.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:37:51 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.