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

KDEUI

  • sources
  • kde-4.12
  • kdelibs
  • kdeui
  • itemviews
kviewstatemaintainer.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Klarälvdalens Datakonsult AB,
3  a KDAB Group company, info@kdab.net,
4  author Stephen Kelly <stephen@kdab.com>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "kviewstatemaintainer.h"
23 
24 #include <QtCore/QWeakPointer>
25 
26 class KViewStateMaintainerBasePrivate
27 {
28  KViewStateMaintainerBasePrivate(KConfigGroup configGroup, KViewStateMaintainerBase *qq)
29  : q_ptr(qq), m_configGroup(configGroup)
30  {
31 
32  }
33 
34  Q_DECLARE_PUBLIC(KViewStateMaintainerBase)
35  KViewStateMaintainerBase * const q_ptr;
36 
37  void _k_modelAboutToBeReset();
38  void _k_modelReset();
39 
40  QWeakPointer<QAbstractItemView> m_view;
41  QWeakPointer<QItemSelectionModel> m_selectionModel;
42 
43  const KConfigGroup m_configGroup;
44 };
45 
46 void KViewStateMaintainerBasePrivate::_k_modelAboutToBeReset()
47 {
48  Q_Q(KViewStateMaintainerBase);
49  q->saveState();
50 }
51 
52 void KViewStateMaintainerBasePrivate::_k_modelReset()
53 {
54  Q_Q(KViewStateMaintainerBase);
55  q->restoreState();
56 }
57 
58 KViewStateMaintainerBase::KViewStateMaintainerBase(KConfigGroup configPtr, QObject* parent)
59  : QObject(parent), d_ptr(new KViewStateMaintainerBasePrivate(configPtr, this))
60 {
61 
62 }
63 
64 KViewStateMaintainerBase::~KViewStateMaintainerBase()
65 {
66  delete d_ptr;
67 }
68 
69 KConfigGroup KViewStateMaintainerBase::configGroup() const
70 {
71  Q_D(const KViewStateMaintainerBase);
72  return d->m_configGroup;
73 }
74 
75 QItemSelectionModel* KViewStateMaintainerBase::selectionModel() const
76 {
77  Q_D(const KViewStateMaintainerBase);
78  if (d->m_selectionModel.isNull())
79  return 0;
80  return d->m_selectionModel.data();
81 }
82 
83 void KViewStateMaintainerBase::setSelectionModel(QItemSelectionModel* selectionModel)
84 {
85  Q_D(KViewStateMaintainerBase);
86  d->m_selectionModel = selectionModel;
87 
88  if (d->m_view && d->m_view.data()->model()) {
89  disconnect(d->m_view.data()->model(), SIGNAL(modelAboutToBeReset()), this, SLOT(_k_modelAboutToBeReset()));
90  disconnect(d->m_view.data()->model(), SIGNAL(modelReset()), this, SLOT(_k_modelReset()));
91  }
92  connect(d->m_selectionModel.data()->model(), SIGNAL(modelAboutToBeReset()), SLOT(_k_modelAboutToBeReset()), Qt::UniqueConnection);
93  connect(d->m_selectionModel.data()->model(), SIGNAL(modelReset()), SLOT(_k_modelReset()), Qt::UniqueConnection);
94 }
95 
96 QAbstractItemView* KViewStateMaintainerBase::view() const
97 {
98  Q_D(const KViewStateMaintainerBase);
99  if (d->m_view.isNull())
100  return 0;
101  return d->m_view.data();
102 }
103 
104 void KViewStateMaintainerBase::setView(QAbstractItemView* view)
105 {
106  Q_D(KViewStateMaintainerBase);
107  d->m_view = view;
108 
109  if (d->m_selectionModel && d->m_selectionModel.data()->model()) {
110  disconnect(d->m_selectionModel.data()->model(), SIGNAL(modelAboutToBeReset()), this, SLOT(_k_modelAboutToBeReset()));
111  disconnect(d->m_selectionModel.data()->model(), SIGNAL(modelReset()), this, SLOT(_k_modelReset()));
112  }
113  if (d->m_view && d->m_view.data()->model()) {
114  connect(d->m_view.data()->model(), SIGNAL(modelAboutToBeReset()), SLOT(_k_modelAboutToBeReset()), Qt::UniqueConnection);
115  connect(d->m_view.data()->model(), SIGNAL(modelReset()), SLOT(_k_modelReset()), Qt::UniqueConnection);
116  }
117 }
118 
119 #include "kviewstatemaintainer.moc"
KViewStateMaintainerBase::selectionModel
QItemSelectionModel * selectionModel() const
Definition: kviewstatemaintainer.cpp:75
QItemSelectionModel
KViewStateMaintainerBase::KViewStateMaintainerBase
KViewStateMaintainerBase(KConfigGroup configGroup, QObject *parent=0)
Definition: kviewstatemaintainer.cpp:58
KViewStateMaintainerBase::setView
void setView(QAbstractItemView *view)
Definition: kviewstatemaintainer.cpp:104
kviewstatemaintainer.h
QObject
KViewStateMaintainerBase::view
QAbstractItemView * view() const
Definition: kviewstatemaintainer.cpp:96
KViewStateMaintainerBase::configGroup
KConfigGroup configGroup() const
Definition: kviewstatemaintainer.cpp:69
KViewStateMaintainerBase::setSelectionModel
void setSelectionModel(QItemSelectionModel *selectionModel)
Definition: kviewstatemaintainer.cpp:83
KConfigGroup
KViewStateMaintainerBase::~KViewStateMaintainerBase
~KViewStateMaintainerBase()
Definition: kviewstatemaintainer.cpp:64
KViewStateMaintainerBase
Definition: kviewstatemaintainer.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:16 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

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