File indexing completed on 2024-07-14 03:52:18

0001 
0002 #include "kconfigviewstatesaver.h"
0003 
0004 #include <KConfigGroup>
0005 
0006 static const char selectionKey[] = "Selection";
0007 static const char expansionKey[] = "Expansion";
0008 static const char currentKey[] = "Current";
0009 static const char scrollStateHorizontalKey[] = "HorizontalScroll";
0010 static const char scrollStateVerticalKey[] = "VerticalScroll";
0011 
0012 KConfigViewStateSaver::KConfigViewStateSaver(QObject *parent)
0013     : KViewStateSerializer(parent)
0014 {
0015 }
0016 
0017 void KConfigViewStateSaver::restoreState(const KConfigGroup &configGroup)
0018 {
0019     restoreSelection(configGroup.readEntry(selectionKey, QStringList()));
0020     restoreCurrentItem(configGroup.readEntry(currentKey, QString()));
0021     restoreExpanded(configGroup.readEntry(expansionKey, QStringList()));
0022     restoreScrollState(configGroup.readEntry(scrollStateVerticalKey, -1), configGroup.readEntry(scrollStateHorizontalKey, -1));
0023 
0024     KViewStateSerializer::restoreState();
0025 }
0026 
0027 void KConfigViewStateSaver::saveState(KConfigGroup &configGroup)
0028 {
0029     if (selectionModel()) {
0030         configGroup.writeEntry(selectionKey, selectionKeys());
0031         configGroup.writeEntry(currentKey, currentIndexKey());
0032     }
0033 
0034     if (view()) {
0035         QStringList expansion = expansionKeys();
0036 
0037         configGroup.writeEntry(expansionKey, expansion);
0038     }
0039 
0040     if (view()) {
0041         QPair<int, int> _scrollState = scrollState();
0042         configGroup.writeEntry(scrollStateVerticalKey, _scrollState.first);
0043         configGroup.writeEntry(scrollStateHorizontalKey, _scrollState.second);
0044     }
0045 }
0046 
0047 #include "moc_kconfigviewstatesaver.cpp"