CalendarSupport

collectionselection.cpp
1/*
2 SPDX-FileCopyrightText: 2009 KDAB
3 SPDX-FileContributor: Frank Osterfeld <frank@kdab.net>
4
5 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
6*/
7
8#include "collectionselection.h"
9#include "utils.h"
10
11#include <Akonadi/CollectionUtils>
12
13#include <QItemSelectionModel>
14
15using namespace CalendarSupport;
16
17class CalendarSupport::CollectionSelectionPrivate
18{
19public:
20 explicit CollectionSelectionPrivate(QItemSelectionModel *model_)
21 : model(model_)
22 {
23 }
24
25 QItemSelectionModel *const model;
26};
27
28CollectionSelection::CollectionSelection(QItemSelectionModel *selectionModel, QObject *parent)
29 : QObject(parent)
30 , d(new CollectionSelectionPrivate(selectionModel))
31{
32 connect(selectionModel, &QItemSelectionModel::selectionChanged, this, &CollectionSelection::slotSelectionChanged);
33}
34
35CollectionSelection::~CollectionSelection() = default;
36
37QItemSelectionModel *CollectionSelection::model() const
38{
39 return d->model;
40}
41
42bool CollectionSelection::hasSelection() const
43{
44 return d->model->hasSelection();
45}
46
47bool CollectionSelection::contains(const Akonadi::Collection &c) const
48{
49 return selectedCollectionIds().contains(c.id());
50}
51
52bool CollectionSelection::contains(Akonadi::Collection::Id id) const
53{
54 return selectedCollectionIds().contains(id);
55}
56
57Akonadi::Collection::List CollectionSelection::selectedCollections() const
58{
60 const QModelIndexList selectedIndexes = d->model->selectedIndexes();
61 selected.reserve(selectedIndexes.count());
62 for (const QModelIndex &idx : selectedIndexes) {
64 }
65 return selected;
66}
67
68QList<Akonadi::Collection::Id> CollectionSelection::selectedCollectionIds() const
69{
71 const QModelIndexList selectedIndexes = d->model->selectedIndexes();
72 selected.reserve(selectedIndexes.count());
73 for (const QModelIndex &idx : selectedIndexes) {
74 selected.append(collectionIdFromIndex(idx));
75 }
76 return selected;
77}
78
79void CollectionSelection::slotSelectionChanged(const QItemSelection &selectedIndexes, const QItemSelection &deselIndexes)
80{
81 const Akonadi::Collection::List selected = collectionsFromIndexes(selectedIndexes.indexes());
82 const Akonadi::Collection::List deselected = collectionsFromIndexes(deselIndexes.indexes());
83
84 Q_EMIT selectionChanged(selected, deselected);
85 for (const Akonadi::Collection &c : deselected) {
86 Q_EMIT collectionDeselected(c);
87 }
88 for (const Akonadi::Collection &c : selected) {
89 Q_EMIT collectionSelected(c);
90 }
91}
92
93#include "moc_collectionselection.cpp"
AKONADICORE_EXPORT Collection fromIndex(const QModelIndex &index)
QModelIndexList indexes() const const
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
void append(QList< T > &&value)
void reserve(qsizetype size)
Q_EMITQ_EMIT
T qobject_cast(QObject *object)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:31 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.