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
17void KConfigViewStateSaver::restoreState(const KConfigGroup &configGroup)
18{
19 restoreSelection(indexStrings: configGroup.readEntry(key: selectionKey, aDefault: QStringList()));
20 restoreCurrentItem(indexString: configGroup.readEntry(key: currentKey, aDefault: QString()));
21 restoreExpanded(indexStrings: configGroup.readEntry(key: expansionKey, aDefault: QStringList()));
22 restoreScrollState(verticalScoll: configGroup.readEntry(key: scrollStateVerticalKey, defaultValue: -1), horizontalScroll: configGroup.readEntry(key: scrollStateHorizontalKey, defaultValue: -1));
23
24 KViewStateSerializer::restoreState();
25}
26
27void KConfigViewStateSaver::saveState(KConfigGroup &configGroup)
28{
29 if (selectionModel()) {
30 configGroup.writeEntry(key: selectionKey, value: selectionKeys());
31 configGroup.writeEntry(key: currentKey, value: currentIndexKey());
32 }
33
34 if (view()) {
35 QStringList expansion = expansionKeys();
36
37 configGroup.writeEntry(key: expansionKey, value: expansion);
38 }
39
40 if (view()) {
41 QPair<int, int> _scrollState = scrollState();
42 configGroup.writeEntry(key: scrollStateVerticalKey, value: _scrollState.first);
43 configGroup.writeEntry(key: scrollStateHorizontalKey, value: _scrollState.second);
44 }
45}
46
47#include "moc_kconfigviewstatesaver.cpp"
48

source code of kconfigwidgets/src/kconfigviewstatesaver.cpp