KConfigWidgets

kconfigviewstatesaver.cpp
1
2#include "kconfigviewstatesaver.h"
3
4#include <KConfigGroup>
5
6static const char selectionKey[] = "Selection";
7static const char expansionKey[] = "Expansion";
8static const char currentKey[] = "Current";
9static const char scrollStateHorizontalKey[] = "HorizontalScroll";
10static const char scrollStateVerticalKey[] = "VerticalScroll";
11
12KConfigViewStateSaver::KConfigViewStateSaver(QObject *parent)
13 : KViewStateSerializer(parent)
14{
15}
16
18{
19 restoreSelection(configGroup.readEntry(selectionKey, QStringList()));
20 restoreCurrentItem(configGroup.readEntry(currentKey, QString()));
21 restoreExpanded(configGroup.readEntry(expansionKey, QStringList()));
22 restoreScrollState(configGroup.readEntry(scrollStateVerticalKey, -1), configGroup.readEntry(scrollStateHorizontalKey, -1));
23
24 KViewStateSerializer::restoreState();
25}
26
28{
29 if (selectionModel()) {
30 configGroup.writeEntry(selectionKey, selectionKeys());
31 configGroup.writeEntry(currentKey, currentIndexKey());
32 }
33
34 if (view()) {
35 QStringList expansion = expansionKeys();
36
37 configGroup.writeEntry(expansionKey, expansion);
38 }
39
40 if (view()) {
41 QPair<int, int> _scrollState = scrollState();
42 configGroup.writeEntry(scrollStateVerticalKey, _scrollState.first);
43 configGroup.writeEntry(scrollStateHorizontalKey, _scrollState.second);
44 }
45}
46
47#include "moc_kconfigviewstatesaver.cpp"
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QString readEntry(const char *key, const char *aDefault=nullptr) const
void saveState(KConfigGroup &configGroup)
Saves the state to the configGroup.
void restoreState(const KConfigGroup &configGroup)
Restores the state from the configGroup.
QStringList selectionKeys() const
QPair< int, int > scrollState() const
void restoreSelection(const QStringList &indexStrings)
QString currentIndexKey() const
void restoreCurrentItem(const QString &indexString)
void restoreExpanded(const QStringList &indexStrings)
void restoreScrollState(int verticalScoll, int horizontalScroll)
QStringList expansionKeys() const
QAbstractItemView * view() const
QItemSelectionModel * selectionModel() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.