2
Copyright (C) 2010 Klarälvdalens Datakonsult AB,
3
a KDAB Group company, info@kdab.net,
4
author Stephen Kelly <stephen@kdab.com>
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.
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.
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
22
#include "modelselectiontransition.h"
24
class ModelSelectionTransitionPrivate
26
ModelSelectionTransitionPrivate(ModelSelectionTransition *qq, QItemSelectionModel *selectionModel, ModelSelectionTransition::Type type)
27
: q_ptr(qq), m_selectionModel(selectionModel), m_type(type)
31
Q_DECLARE_PUBLIC(ModelSelectionTransition)
32
ModelSelectionTransition * const q_ptr;
34
QItemSelectionModel * const m_selectionModel;
35
ModelSelectionTransition::Type m_type;
38
ModelSelectionTransition::ModelSelectionTransition(QItemSelectionModel* selectionModel, ModelSelectionTransition::Type type, QState* sourceState)
39
: QSignalTransition(selectionModel,
40
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
42
d_ptr(new ModelSelectionTransitionPrivate(this, selectionModel, type))
47
ModelSelectionTransition::~ModelSelectionTransition()
52
bool ModelSelectionTransition::eventTest(QEvent* event)
54
Q_D(ModelSelectionTransition);
55
if (!QSignalTransition::eventTest(event))
58
// Yes, it does feel wrong to use a switch statement in a state machine.
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();
72
Q_ASSERT(!"Unknown type");