• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkdepim

  • sources
  • kde-4.12
  • kdepim
  • libkdepim
  • misc
uistatesaver.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2008 Volker Krause <vkrause@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "uistatesaver.h"
21 
22 #include <KConfigGroup>
23 
24 #include <QComboBox>
25 #include <QHeaderView>
26 #include <QSplitter>
27 #include <QTabWidget>
28 #include <QTreeView>
29 
30 using namespace KPIM;
31 
32 struct Saver {
33  static void process( QSplitter *splitter, KConfigGroup &config )
34  {
35  if ( splitter->sizes().count( 0 ) == splitter->sizes().count() )
36  return;
37  config.writeEntry( splitter->objectName(), splitter->sizes() );
38  }
39 
40  static void process( QTabWidget *tab, KConfigGroup &config )
41  {
42  config.writeEntry( tab->objectName(), tab->currentIndex() );
43  }
44 
45  static void process( QTreeView *tv, KConfigGroup &config )
46  {
47  config.writeEntry( tv->objectName(), tv->header()->saveState() );
48  }
49 
50  static void process( QComboBox *cb, KConfigGroup &config )
51  {
52  config.writeEntry( cb->objectName(), cb->currentIndex() );
53  }
54 };
55 
56 struct Restorer {
57  static void process( QSplitter *splitter, const KConfigGroup &config )
58  {
59  const QList<int> sizes = config.readEntry( splitter->objectName(), QList<int>() );
60  if ( !sizes.isEmpty() && splitter->count() == sizes.count() && sizes.count() != sizes.count( 0 ) )
61  splitter->setSizes( sizes );
62  }
63 
64  static void process( QTabWidget *tab, const KConfigGroup &config )
65  {
66  const int index = config.readEntry( tab->objectName(), -1 );
67  if ( index >= 0 && index < tab->count() )
68  tab->setCurrentIndex( index );
69  }
70 
71  static void process( QTreeView *tv, const KConfigGroup &config )
72  {
73  const QByteArray state = config.readEntry( tv->objectName(), QByteArray() );
74  if ( !state.isEmpty() )
75  tv->header()->restoreState( state );
76  }
77 
78  static void process( QComboBox *cb, const KConfigGroup &config )
79  {
80  const int index = config.readEntry( cb->objectName(), -1 );
81  if ( index >= 0 && index < cb->count() )
82  cb->setCurrentIndex( index );
83  }
84 };
85 
86 #define PROCESS_TYPE( T ) \
87 { \
88  T *obj = qobject_cast<T*>( w ); \
89  if ( obj ) { \
90  Op::process( obj, config ); \
91  continue; \
92  } \
93 }
94 
95 template <typename Op, typename Config> static void processWidgets( QWidget *widget, Config config )
96 {
97  QList<QWidget*> widgets = widget->findChildren<QWidget*>();
98  widgets << widget;
99  foreach ( QWidget* w, widgets ) {
100  if ( w->objectName().isEmpty() )
101  continue;
102  PROCESS_TYPE( QSplitter );
103  PROCESS_TYPE( QTabWidget );
104  PROCESS_TYPE( QTreeView );
105  PROCESS_TYPE( QComboBox );
106  }
107 }
108 
109 #undef PROCESS_TYPE
110 
111 void UiStateSaver::saveState(QWidget * widget, KConfigGroup & config)
112 {
113  processWidgets<Saver, KConfigGroup&>( widget, config );
114 }
115 
116 void UiStateSaver::restoreState(QWidget * widget, const KConfigGroup & config)
117 {
118  processWidgets<Restorer, const KConfigGroup&>( widget, config );
119 }
KPIM::UiStateSaver::saveState
KDEPIM_EXPORT void saveState(QWidget *widget, KConfigGroup &config)
Saves the state of widget and all its sub-widgets to config.
Definition: uistatesaver.cpp:111
QWidget
PROCESS_TYPE
#define PROCESS_TYPE(T)
Definition: uistatesaver.cpp:86
processWidgets
static void processWidgets(QWidget *widget, Config config)
Definition: uistatesaver.cpp:95
uistatesaver.h
KPIM::UiStateSaver::restoreState
KDEPIM_EXPORT void restoreState(QWidget *widget, const KConfigGroup &config)
Restores the UI state of widget and all its sub-widgets from config.
Definition: uistatesaver.cpp:116
QList
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

Skip menu "libkdepim"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal