~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/dataengines/calendar/akonadi/collectionselection.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2009 KDAB
 
3
  Author: Frank Osterfeld <frank@kdab.net>
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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.
 
18
 
 
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.
 
22
*/
 
23
 
 
24
#include "collectionselection.h"
 
25
#include "utils.h"
 
26
 
 
27
#include <QItemSelectionModel>
 
28
 
 
29
using namespace CalendarSupport;
 
30
 
 
31
class CollectionSelection::Private
 
32
{
 
33
  public:
 
34
    explicit Private( QItemSelectionModel *model_ ) : model( model_ )
 
35
    {
 
36
    }
 
37
 
 
38
    QItemSelectionModel *model;
 
39
};
 
40
 
 
41
CollectionSelection::CollectionSelection( QItemSelectionModel *selectionModel, QObject *parent )
 
42
  : QObject( parent ), d( new Private ( selectionModel ) )
 
43
{
 
44
  connect( selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
 
45
           this, SLOT(slotSelectionChanged(QItemSelection,QItemSelection)) );
 
46
}
 
47
 
 
48
CollectionSelection::~CollectionSelection()
 
49
{
 
50
  delete d;
 
51
}
 
52
 
 
53
QItemSelectionModel *CollectionSelection::model() const
 
54
{
 
55
  return d->model;
 
56
}
 
57
 
 
58
bool CollectionSelection::hasSelection() const
 
59
{
 
60
  return d->model->hasSelection();
 
61
}
 
62
 
 
63
bool CollectionSelection::contains( const Akonadi::Collection &c ) const
 
64
{
 
65
  return selectedCollectionIds().contains( c.id() );
 
66
}
 
67
 
 
68
bool CollectionSelection::contains( const Akonadi::Collection::Id &id ) const
 
69
{
 
70
  return selectedCollectionIds().contains( id );
 
71
}
 
72
 
 
73
Akonadi::Collection::List CollectionSelection::selectedCollections() const
 
74
{
 
75
  Akonadi::Collection::List selected;
 
76
  Q_FOREACH ( const QModelIndex &idx, d->model->selectedIndexes() ) {
 
77
    selected.append( collectionFromIndex( idx ) );
 
78
  }
 
79
  return selected;
 
80
}
 
81
 
 
82
QList<Akonadi::Collection::Id> CollectionSelection::selectedCollectionIds() const
 
83
{
 
84
  QList<Akonadi::Collection::Id> selected;
 
85
  Q_FOREACH ( const QModelIndex &idx, d->model->selectedIndexes() ) {
 
86
    selected.append( collectionIdFromIndex( idx ) );
 
87
  }
 
88
  return selected;
 
89
}
 
90
 
 
91
void CollectionSelection::slotSelectionChanged( const QItemSelection &selectedIndexes,
 
92
                                                const QItemSelection &deselIndexes )
 
93
{
 
94
  const Akonadi::Collection::List selected = collectionsFromIndexes( selectedIndexes.indexes() );
 
95
  const Akonadi::Collection::List deselected = collectionsFromIndexes( deselIndexes.indexes() );
 
96
 
 
97
  emit selectionChanged( selected, deselected );
 
98
  Q_FOREACH ( const Akonadi::Collection &c, deselected ) {
 
99
    emit collectionDeselected( c );
 
100
  }
 
101
  Q_FOREACH ( const Akonadi::Collection &c, selected ) {
 
102
    emit collectionSelected( c );
 
103
  }
 
104
}