KConfigWidgets

kconfigviewstatesaver.cpp
1 
2 #include "kconfigviewstatesaver.h"
3 
4 #include <KConfigGroup>
5 
6 static const char selectionKey[] = "Selection";
7 static const char expansionKey[] = "Expansion";
8 static const char currentKey[] = "Current";
9 static const char scrollStateHorizontalKey[] = "HorizontalScroll";
10 static const char scrollStateVerticalKey[] = "VerticalScroll";
11 
12 KConfigViewStateSaver::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"
QString readEntry(const char *key, const char *aDefault=nullptr) const
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QStringList expansionKeys() const
QAbstractItemView * view() const
void restoreScrollState(int verticalScoll, int horizontalScroll)
QString currentIndexKey() const
QItemSelectionModel * selectionModel() const
void restoreExpanded(const QStringList &indexStrings)
void restoreSelection(const QStringList &indexStrings)
QPair< int, int > scrollState() const
QStringList selectionKeys() const
void restoreState(const KConfigGroup &configGroup)
Restores the state from the configGroup.
void saveState(KConfigGroup &configGroup)
Saves the state to the configGroup.
void restoreCurrentItem(const QString &indexString)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Sep 22 2023 03:48:42 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.