~ubuntu-branches/ubuntu/natty/kde4libs/natty-proposed

« back to all changes in this revision

Viewing changes to kdeui/itemviews/kcheckableproxymodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell, Scott Kitterman, Jonathan Riddell
  • Date: 2010-11-22 17:59:02 UTC
  • mfrom: (1.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101122175902-yubxubd0pg6hn11z
Tags: 4:4.5.80a-0ubuntu1
[ Scott Kitterman ]
* New upstream beta release
  - Refreshed all patches
  - Updated debian/patches/10_make_libkdeinit4_private.diff to use Qfile
    instead of Qstring in kdecore/kernel/kstandarddirs_unix.cpp
  - Updated debian/patches/kubuntu_01_kubuntu_useragent.diff to provide
    Kubuntu in the Konqueror user agen string with the changes in
    kio/kio/kprotocolmanager.cpp
  - Partially updated debian/patches/kubuntu_05_langpack_desktop_files.diff
    and left the balance in kdecore/localization/klocale.cpp.rej for later
    revision
  - Update debian/patches/kubuntu_06_user_disk_mounting.diff for changes in
    solid/solid/backends/hal/halstorageaccess.cpp
  - Remove debian/patches/kubuntu_71_backport_plasma_webview_changes.diff
    (backported from upstream, so already present now)
  - Add minimum version for libattica-dev of 0.1.90 to build-depends
  - Bump minimum version for libsoprano-dev build-depend to 2.5.60
  - Add minimum version for shared-desktop-ontologies of 0.5 in build-dep

[ Jonathan Riddell ]
* Add build-depends on grantlee, libudev-dev, hupnp (FIXME needs packaging fixes)
* Update kubuntu_04_add_langpack_path.diff 28_find_old_kde4_html_documentation.diff
  22_hack_in_etc_kde4_in_kstandarddirs.diff for QT_NO_CAST_FROM_ASCII
* Update kubuntu_05_langpack_desktop_files.diff for new upstream code
* Add kubuntu_78_solid_trunk.diff to fix solid linking
* Add libnepomukutils4 package for new library
* Don't install kcm_ssl for now, e-mailed upstream to suggest moving to kdebase
* Add kubuntu_79_knewstuff_fix.diff to fix compile broken by non-trunk commit
  http://websvn.kde.org/?view=revision&revision=1199825
* kdelibs5-data replaces old kdebase-runtime-data due to moved file
* Add kubuntu_80_find_hupnp.diff to find hupnp include files, committed upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of KDE.
 
3
 
 
4
    Copyright (c) 2010 Stephen Kelly <steveire@gmail.com>
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along with this program; if not, write to the Free Software
 
18
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
 
19
    USA.
 
20
*/
 
21
 
 
22
 
 
23
#include "kcheckableproxymodel.h"
 
24
 
 
25
#include <QItemSelectionModel>
 
26
 
 
27
class KCheckableProxyModelPrivate
 
28
{
 
29
  Q_DECLARE_PUBLIC(KCheckableProxyModel)
 
30
  KCheckableProxyModel *q_ptr;
 
31
 
 
32
  KCheckableProxyModelPrivate(KCheckableProxyModel *checkableModel)
 
33
    : q_ptr(checkableModel),
 
34
      m_itemSelectionModel(0)
 
35
  {
 
36
 
 
37
  }
 
38
 
 
39
  QItemSelectionModel *m_itemSelectionModel;
 
40
 
 
41
  void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
 
42
 
 
43
};
 
44
 
 
45
KCheckableProxyModel::KCheckableProxyModel(QObject* parent)
 
46
  : KIdentityProxyModel(parent), d_ptr(new KCheckableProxyModelPrivate(this))
 
47
{
 
48
 
 
49
}
 
50
 
 
51
KCheckableProxyModel::~KCheckableProxyModel()
 
52
{
 
53
  delete d_ptr;
 
54
}
 
55
 
 
56
void KCheckableProxyModel::setSelectionModel(QItemSelectionModel* itemSelectionModel)
 
57
{
 
58
  Q_D(KCheckableProxyModel);
 
59
  d->m_itemSelectionModel = itemSelectionModel;
 
60
  Q_ASSERT(sourceModel() ? d->m_itemSelectionModel->model() == sourceModel() : true);
 
61
  connect(itemSelectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(selectionChanged(QItemSelection,QItemSelection)));
 
62
}
 
63
 
 
64
QItemSelectionModel *KCheckableProxyModel::selectionModel() const
 
65
{
 
66
  Q_D(const KCheckableProxyModel);
 
67
  return d->m_itemSelectionModel;
 
68
}
 
69
 
 
70
Qt::ItemFlags KCheckableProxyModel::flags(const QModelIndex& index) const
 
71
{
 
72
  if (!index.isValid())
 
73
    return KIdentityProxyModel::flags(index);
 
74
  return KIdentityProxyModel::flags(index) | Qt::ItemIsUserCheckable;
 
75
}
 
76
 
 
77
QVariant KCheckableProxyModel::data(const QModelIndex& index, int role) const
 
78
{
 
79
  Q_D(const KCheckableProxyModel);
 
80
 
 
81
  if (role == Qt::CheckStateRole)
 
82
  {
 
83
    if (!d->m_itemSelectionModel)
 
84
      return Qt::Unchecked;
 
85
 
 
86
    return d->m_itemSelectionModel->selection().contains(mapToSource(index)) ? Qt::Checked : Qt::Unchecked;
 
87
  }
 
88
  return KIdentityProxyModel::data(index, role);
 
89
}
 
90
 
 
91
bool KCheckableProxyModel::setData(const QModelIndex& index, const QVariant& value, int role)
 
92
{
 
93
  Q_D(KCheckableProxyModel);
 
94
  if (role == Qt::CheckStateRole)
 
95
  {
 
96
    if (!d->m_itemSelectionModel)
 
97
      return false;
 
98
 
 
99
    Qt::CheckState state = static_cast<Qt::CheckState>(value.toInt());
 
100
    const QModelIndex srcIndex = mapToSource(index);
 
101
    bool result = select(QItemSelection(srcIndex, srcIndex), state == Qt::Checked ? QItemSelectionModel::Select : QItemSelectionModel::Deselect);
 
102
    emit dataChanged(index, index);
 
103
    return result;
 
104
  }
 
105
  return KIdentityProxyModel::setData(index, value, role);
 
106
}
 
107
 
 
108
void KCheckableProxyModel::setSourceModel(QAbstractItemModel* sourceModel)
 
109
{
 
110
  KIdentityProxyModel::setSourceModel(sourceModel);
 
111
  Q_ASSERT(d_ptr->m_itemSelectionModel ? d_ptr->m_itemSelectionModel->model() == sourceModel : true);
 
112
}
 
113
 
 
114
void KCheckableProxyModelPrivate::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
 
115
{
 
116
  Q_Q(KCheckableProxyModel);
 
117
  foreach (const QItemSelectionRange &range, q->mapSelectionFromSource(selected))
 
118
    q->dataChanged(range.topLeft(), range.bottomRight());
 
119
  foreach (const QItemSelectionRange &range, q->mapSelectionFromSource(deselected))
 
120
    q->dataChanged(range.topLeft(), range.bottomRight());
 
121
}
 
122
 
 
123
bool KCheckableProxyModel::select(const QItemSelection& selection, QItemSelectionModel::SelectionFlags command)
 
124
{
 
125
  Q_D(KCheckableProxyModel);
 
126
  d->m_itemSelectionModel->select(selection, command);
 
127
  return true;
 
128
}
 
129
 
 
130
 
 
131
#include "kcheckableproxymodel.moc"
 
132