KWidgetsAddons

kviewstateserializer.h
1 /*
2  SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
3  SPDX-FileContributor: Stephen Kelly <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef KVIEWSTATESERIALIZER_H
9 #define KVIEWSTATESERIALIZER_H
10 
11 #include <QObject>
12 #include <QPair>
13 
14 #include "kwidgetsaddons_export.h"
15 
16 class QAbstractItemView;
18 class QAbstractItemModel;
20 class QModelIndex;
21 class QStringList;
22 
23 class KViewStateSerializerPrivate;
24 
154 class KWIDGETSADDONS_EXPORT KViewStateSerializer : public QObject
155 {
156  Q_OBJECT
157 public:
161  explicit KViewStateSerializer(QObject *parent = nullptr);
162 
167 
171  QAbstractItemView *view() const;
172 
176  void setView(QAbstractItemView *view);
177 
181  QItemSelectionModel *selectionModel() const;
182 
186  void setSelectionModel(QItemSelectionModel *selectionModel);
187 
191  QStringList selectionKeys() const;
192 
196  QStringList expansionKeys() const;
197 
201  QString currentIndexKey() const;
202 
206  QPair<int, int> scrollState() const;
207 
211  void restoreSelection(const QStringList &indexStrings);
212 
216  void restoreCurrentItem(const QString &indexString);
217 
221  void restoreExpanded(const QStringList &indexStrings);
222 
227  void restoreScrollState(int verticalScoll, int horizontalScroll);
228 
229 protected:
233  virtual QModelIndex indexFromConfigString(const QAbstractItemModel *model, const QString &key) const = 0;
234 
238  virtual QString indexToConfigString(const QModelIndex &index) const = 0;
239 
240  void restoreState();
241 
242 private:
243  //@cond PRIVATE
244  Q_DECLARE_PRIVATE(KViewStateSerializer)
245  KViewStateSerializerPrivate *const d_ptr;
246  Q_PRIVATE_SLOT(d_func(), void rowsInserted(const QModelIndex &, int, int))
247  Q_PRIVATE_SLOT(d_func(), void restoreScrollBarState())
248  //@endcond
249 };
250 
251 #endif
Object for saving and restoring state in QTreeViews and QItemSelectionModels.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Sep 25 2020 22:44:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.