2
Copyright (c) 2009 KDAB
3
Author: Frank Osterfeld <frank@kdab.net>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License along
16
with this program; if not, write to the Free Software Foundation, Inc.,
17
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
As a special exception, permission is given to link this program
20
with any edition of Qt, and distribute the resulting executable,
21
without including the source code for Qt in the source distribution.
24
#include "collectionselection.h"
27
#include <QItemSelectionModel>
29
using namespace CalendarSupport;
31
class CollectionSelection::Private
34
explicit Private( QItemSelectionModel *model_ ) : model( model_ )
38
QItemSelectionModel *model;
41
CollectionSelection::CollectionSelection( QItemSelectionModel *selectionModel, QObject *parent )
42
: QObject( parent ), d( new Private ( selectionModel ) )
44
connect( selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
45
this, SLOT(slotSelectionChanged(QItemSelection,QItemSelection)) );
48
CollectionSelection::~CollectionSelection()
53
QItemSelectionModel *CollectionSelection::model() const
58
bool CollectionSelection::hasSelection() const
60
return d->model->hasSelection();
63
bool CollectionSelection::contains( const Akonadi::Collection &c ) const
65
return selectedCollectionIds().contains( c.id() );
68
bool CollectionSelection::contains( const Akonadi::Collection::Id &id ) const
70
return selectedCollectionIds().contains( id );
73
Akonadi::Collection::List CollectionSelection::selectedCollections() const
75
Akonadi::Collection::List selected;
76
Q_FOREACH ( const QModelIndex &idx, d->model->selectedIndexes() ) {
77
selected.append( collectionFromIndex( idx ) );
82
QList<Akonadi::Collection::Id> CollectionSelection::selectedCollectionIds() const
84
QList<Akonadi::Collection::Id> selected;
85
Q_FOREACH ( const QModelIndex &idx, d->model->selectedIndexes() ) {
86
selected.append( collectionIdFromIndex( idx ) );
91
void CollectionSelection::slotSelectionChanged( const QItemSelection &selectedIndexes,
92
const QItemSelection &deselIndexes )
94
const Akonadi::Collection::List selected = collectionsFromIndexes( selectedIndexes.indexes() );
95
const Akonadi::Collection::List deselected = collectionsFromIndexes( deselIndexes.indexes() );
97
emit selectionChanged( selected, deselected );
98
Q_FOREACH ( const Akonadi::Collection &c, deselected ) {
99
emit collectionDeselected( c );
101
Q_FOREACH ( const Akonadi::Collection &c, selected ) {
102
emit collectionSelected( c );