Akonadi

etmviewstatesaver.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB,
3 a KDAB Group company, info@kdab.net
4 SPDX-FileContributor: Stephen Kelly <stephen@kdab.com>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "etmviewstatesaver.h"
10
11#include <QModelIndex>
12
13#include "entitytreemodel.h"
14
15using namespace Akonadi;
16
17ETMViewStateSaver::ETMViewStateSaver(QObject *parent)
18 : KConfigViewStateSaver(parent)
19{
20}
21
22QModelIndex ETMViewStateSaver::indexFromConfigString(const QAbstractItemModel *model, const QString &key) const
23{
24 if (key.startsWith(QLatin1Char('x'))) {
25 return QModelIndex();
26 }
27
28 Item::Id id = key.mid(1).toLongLong();
29 if (id < 0) {
30 return QModelIndex();
31 }
32
33 if (key.startsWith(QLatin1Char('c'))) {
35 if (!idx.isValid()) {
36 return QModelIndex();
37 }
38 return idx;
39 } else if (key.startsWith(QLatin1Char('i'))) {
40 const QModelIndexList list = EntityTreeModel::modelIndexesForItem(model, Item(id));
41 if (list.isEmpty()) {
42 return QModelIndex();
43 }
44 return list.first();
45 }
46 return QModelIndex();
47}
48
49QString ETMViewStateSaver::indexToConfigString(const QModelIndex &index) const
50{
51 if (!index.isValid()) {
52 return QStringLiteral("x-1");
53 }
55 if (c.isValid()) {
56 return QStringLiteral("c%1").arg(c.id());
57 }
59 if (id >= 0) {
60 return QStringLiteral("i%1").arg(id);
61 }
62 return QString();
63}
64
65void ETMViewStateSaver::selectCollections(const Akonadi::Collection::List &list)
66{
67 QStringList colStrings;
68 colStrings.reserve(list.count());
69 for (const Collection &col : list) {
70 colStrings << QStringLiteral("c%1").arg(col.id());
71 }
72 restoreSelection(colStrings);
73}
74
75void ETMViewStateSaver::selectCollections(const QList<Collection::Id> &list)
76{
77 QStringList colStrings;
78 colStrings.reserve(list.count());
79 for (const Collection::Id &colId : list) {
80 colStrings << QStringLiteral("c%1").arg(colId);
81 }
82 restoreSelection(colStrings);
83}
84
85void ETMViewStateSaver::selectItems(const Akonadi::Item::List &list)
86{
87 QStringList itemStrings;
88 itemStrings.reserve(list.count());
89 for (const Item &item : list) {
90 itemStrings << QStringLiteral("i%1").arg(item.id());
91 }
92 restoreSelection(itemStrings);
93}
94
95void ETMViewStateSaver::selectItems(const QList<Item::Id> &list)
96{
97 QStringList itemStrings;
98 itemStrings.reserve(list.count());
99 for (const Item::Id &itemId : list) {
100 itemStrings << QStringLiteral("i%1").arg(itemId);
101 }
102 restoreSelection(itemStrings);
103}
104
105void ETMViewStateSaver::setCurrentItem(const Akonadi::Item &item)
106{
107 restoreCurrentItem(QStringLiteral("i%1").arg(item.id()));
108}
109
110void ETMViewStateSaver::setCurrentCollection(const Akonadi::Collection &col)
111{
112 restoreCurrentItem(QStringLiteral("c%1").arg(col.id()));
113}
114
115#include "moc_etmviewstatesaver.cpp"
Represents a collection of PIM items.
Definition collection.h:62
qint64 Id
Describes the unique id type.
Definition collection.h:79
static QModelIndexList modelIndexesForItem(const QAbstractItemModel *model, const Item &item)
Returns a QModelIndex in model which points to item.
static QModelIndex modelIndexForCollection(const QAbstractItemModel *model, const Collection &collection)
Returns a QModelIndex in model which points to collection.
@ CollectionRole
The collection.
Represents a PIM item stored in Akonadi storage.
Definition item.h:101
qint64 Id
Describes the unique id type.
Definition item.h:106
Id id() const
Returns the unique identifier of the item.
Definition item.cpp:63
Helper integration between Akonadi and Qt.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
qsizetype count() const const
T & first()
bool isEmpty() const const
void reserve(qsizetype size)
QVariant data(int role) const const
bool isValid() const const
QString mid(qsizetype position, qsizetype n) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
qlonglong toLongLong(bool *ok, int base) const const
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:51:45 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.