~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to mobile/lib/modelselectiontransition.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2010 Klarälvdalens Datakonsult AB,
 
3
        a KDAB Group company, info@kdab.net,
 
4
        author Stephen Kelly <stephen@kdab.com>
 
5
 
 
6
    This library is free software; you can redistribute it and/or modify it
 
7
    under the terms of the GNU Library General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or (at your
 
9
    option) any later version.
 
10
 
 
11
    This library is distributed in the hope that it will be useful, but WITHOUT
 
12
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 
14
    License for more details.
 
15
 
 
16
    You should have received a copy of the GNU Library General Public License
 
17
    along with this library; see the file COPYING.LIB.  If not, write to the
 
18
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
19
    02110-1301, USA.
 
20
*/
 
21
 
 
22
#include "modelselectiontransition.h"
 
23
 
 
24
class ModelSelectionTransitionPrivate
 
25
{
 
26
  ModelSelectionTransitionPrivate(ModelSelectionTransition *qq, QItemSelectionModel *selectionModel, ModelSelectionTransition::Type type)
 
27
    : q_ptr(qq), m_selectionModel(selectionModel), m_type(type)
 
28
  {
 
29
 
 
30
  }
 
31
  Q_DECLARE_PUBLIC(ModelSelectionTransition)
 
32
  ModelSelectionTransition * const q_ptr;
 
33
 
 
34
  QItemSelectionModel * const m_selectionModel;
 
35
  ModelSelectionTransition::Type m_type;
 
36
};
 
37
 
 
38
ModelSelectionTransition::ModelSelectionTransition(QItemSelectionModel* selectionModel, ModelSelectionTransition::Type type, QState* sourceState)
 
39
  : QSignalTransition(selectionModel,
 
40
                      SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
 
41
                      sourceState),
 
42
    d_ptr(new ModelSelectionTransitionPrivate(this, selectionModel, type))
 
43
{
 
44
 
 
45
}
 
46
 
 
47
ModelSelectionTransition::~ModelSelectionTransition()
 
48
{
 
49
    delete d_ptr;
 
50
}
 
51
 
 
52
bool ModelSelectionTransition::eventTest(QEvent* event)
 
53
{
 
54
  Q_D(ModelSelectionTransition);
 
55
  if (!QSignalTransition::eventTest(event))
 
56
    return false;
 
57
 
 
58
  // Yes, it does feel wrong to use a switch statement in a state machine.
 
59
  // Oh well.
 
60
  switch (d->m_type) {
 
61
  case AcceptNoSelection:
 
62
    return !d->m_selectionModel->hasSelection();
 
63
  case AcceptMultiSelection:
 
64
    return d->m_selectionModel->selectedRows().size() > 1;
 
65
  case AcceptSingleSelection:
 
66
    return d->m_selectionModel->selectedRows().size() == 1;
 
67
  case AcceptSingleTopLevelSelection: {
 
68
    const QModelIndexList list = d->m_selectionModel->selectedRows();
 
69
    return list.size() == 1 && !list.first().parent().isValid();
 
70
  }
 
71
  }
 
72
  Q_ASSERT(!"Unknown type");
 
73
  return false;
 
74
}
 
75