• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kdgantt2

  • sources
  • kde-4.12
  • kdepim
  • kdgantt2
kdganttforwardingproxymodel.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB. All rights reserved.
3  **
4  ** This file is part of the KD Gantt library.
5  **
6  ** This file may be distributed and/or modified under the terms of the
7  ** GNU General Public License version 2 as published by the Free Software
8  ** Foundation and appearing in the file LICENSE.GPL included in the
9  ** packaging of this file.
10  **
11  ** Licensees holding valid commercial KD Gantt licenses may use this file in
12  ** accordance with the KD Gantt Commercial License Agreement provided with
13  ** the Software.
14  **
15  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17  **
18  ** See http://www.kdab.net/kdgantt for
19  ** information about KD Gantt Commercial License Agreements.
20  **
21  ** Contact info@kdab.net if any conditions of this
22  ** licensing are not clear to you.
23  **
24  **********************************************************************/
25 #include "kdganttforwardingproxymodel.h"
26 
27 #include <cassert>
28 
29 using namespace KDGantt;
30 
31 typedef QAbstractProxyModel BASE;
32 
36 ForwardingProxyModel::ForwardingProxyModel( QObject* parent )
37  : BASE( parent )
38 {
39 }
40 
41 ForwardingProxyModel::~ForwardingProxyModel()
42 {
43 }
44 
46 QModelIndex ForwardingProxyModel::mapFromSource ( const QModelIndex & sourceIndex ) const
47 {
48  if ( !sourceIndex.isValid() )
49  return QModelIndex();
50  assert( sourceIndex.model() == sourceModel() );
51 
52  // Create an index that preserves the internal pointer from the source;
53  // this way KDDataConverterProxyModel preserves the structure of the source model
54  return createIndex( sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer() );
55 }
56 
57 namespace {
58  // Think this is ugly? Well, it's not from me, it comes from QProxyModel
59  struct KDPrivateModelIndex {
60  int r, c;
61  void *p;
62  const QAbstractItemModel *m;
63  };
64 }
65 
67 QModelIndex ForwardingProxyModel::mapToSource ( const QModelIndex & proxyIndex ) const
68 {
69  if ( !proxyIndex.isValid() )
70  return QModelIndex();
71  assert( proxyIndex.model() == this );
72  // So here we need to create a source index which holds that internal pointer.
73  // No way to pass it to sourceModel()->index... so we have to do the ugly way:
74  QModelIndex sourceIndex;
75  KDPrivateModelIndex* hack = reinterpret_cast<KDPrivateModelIndex*>(&sourceIndex);
76  hack->r = proxyIndex.row();
77  hack->c = proxyIndex.column();
78  hack->p = proxyIndex.internalPointer();
79  hack->m = sourceModel();
80  assert( sourceIndex.isValid() );
81  return sourceIndex;
82 }
83 
88 void ForwardingProxyModel::setSourceModel( QAbstractItemModel* model )
89 {
90  if ( sourceModel() ) sourceModel()->disconnect( this );
91  BASE::setSourceModel( model );
92 
93  if(!model) return;
94 
95  connect( model, SIGNAL(modelAboutToBeReset()), this, SLOT(sourceModelAboutToBeReset()) );
96  connect( model, SIGNAL(modelReset()), this, SLOT(sourceModelReset()) );
97  connect( model, SIGNAL(layoutAboutToBeChanged()), this, SLOT(sourceLayoutAboutToBeChanged()) );
98  connect( model, SIGNAL(layoutChanged()), this, SLOT(sourceLayoutChanged()) );
99 
100  connect( model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
101  this, SLOT(sourceDataChanged(QModelIndex,QModelIndex)) );
102 
103 
104  connect( model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
105  this, SLOT(sourceColumnsAboutToBeInserted(QModelIndex,int,int)) );
106  connect( model, SIGNAL(columnsInserted(QModelIndex,int,int)),
107  this, SLOT(sourceColumnsInserted(QModelIndex,int,int)) );
108  connect( model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
109  this, SLOT(sourceColumnsAboutToBeRemoved(QModelIndex,int,int)) );
110  connect( model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
111  this, SLOT(sourceColumnsRemoved(QModelIndex,int,int)) );
112 
113  connect( model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
114  this, SLOT(sourceRowsAboutToBeInserted(QModelIndex,int,int)) );
115  connect( model, SIGNAL(rowsInserted(QModelIndex,int,int)),
116  this, SLOT(sourceRowsInserted(QModelIndex,int,int)) );
117  connect( model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
118  this, SLOT(sourceRowsAboutToBeRemoved(QModelIndex,int,int)) );
119  connect( model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
120  this, SLOT(sourceRowsRemoved(QModelIndex,int,int)) );
121 }
122 
126 void ForwardingProxyModel::sourceModelAboutToBeReset()
127 {
128  // The matching signal is emitted be reset()
129 }
130 
134 void ForwardingProxyModel::sourceModelReset()
135 {
136  //qDebug() << "ForwardingProxyModel::sourceModelReset()";
137  reset();
138 }
139 
144 void ForwardingProxyModel::sourceLayoutAboutToBeChanged()
145 {
146  //qDebug() << "ForwardingProxyModel::sourceLayoutAboutToBeChanged()";
147  emit layoutAboutToBeChanged();
148 }
149 
153 void ForwardingProxyModel::sourceLayoutChanged()
154 {
155  //qDebug() << "ForwardingProxyModel::sourceLayoutChanged()";
156  reset();
157 }
158 
162 void ForwardingProxyModel::sourceDataChanged( const QModelIndex& from, const QModelIndex& to )
163 {
164  //qDebug() << "ForwardingProxyModel::sourceDataChanged("<<from<<to<<")";
165  emit dataChanged( mapFromSource( from ), mapFromSource( to ) );
166 }
167 
171 void ForwardingProxyModel::sourceColumnsAboutToBeInserted( const QModelIndex& parentIdx,
172  int start,
173  int end )
174 {
175  beginInsertColumns( mapFromSource( parentIdx ), start, end );
176 }
177 
181 void ForwardingProxyModel::sourceColumnsInserted( const QModelIndex& parentIdx, int start, int end )
182 {
183  Q_UNUSED( parentIdx );
184  Q_UNUSED( start );
185  Q_UNUSED( end );
186  endInsertColumns();
187 }
188 
192 void ForwardingProxyModel::sourceColumnsAboutToBeRemoved( const QModelIndex& parentIdx,
193  int start,
194  int end )
195 {
196  beginRemoveColumns( mapFromSource( parentIdx ), start, end );
197 }
198 
202 void ForwardingProxyModel::sourceColumnsRemoved( const QModelIndex& parentIdx, int start, int end )
203 {
204  Q_UNUSED( parentIdx );
205  Q_UNUSED( start );
206  Q_UNUSED( end );
207  endRemoveColumns();
208 }
209 
213 void ForwardingProxyModel::sourceRowsAboutToBeInserted( const QModelIndex & parentIdx, int start, int end )
214 {
215  beginInsertRows( mapFromSource( parentIdx ), start, end );
216 }
217 
221 void ForwardingProxyModel::sourceRowsInserted( const QModelIndex& parentIdx, int start, int end )
222 {
223  Q_UNUSED( parentIdx );
224  Q_UNUSED( start );
225  Q_UNUSED( end );
226  endInsertRows();
227 }
228 
232 void ForwardingProxyModel::sourceRowsAboutToBeRemoved( const QModelIndex & parentIdx, int start, int end )
233 {
234  beginRemoveRows( mapFromSource( parentIdx ), start, end );
235 }
236 
240 void ForwardingProxyModel::sourceRowsRemoved( const QModelIndex& parentIdx, int start, int end )
241 {
242  Q_UNUSED( parentIdx );
243  Q_UNUSED( start );
244  Q_UNUSED( end );
245  endRemoveRows();
246 }
247 
249 int ForwardingProxyModel::rowCount( const QModelIndex& idx ) const
250 {
251  return sourceModel()->rowCount( mapToSource( idx ) );
252 }
253 
255 int ForwardingProxyModel::columnCount( const QModelIndex& idx ) const
256 {
257  return sourceModel()->columnCount( mapToSource( idx ) );
258 }
259 
261 QModelIndex ForwardingProxyModel::index( int row, int column, const QModelIndex& parent ) const
262 {
263  return mapFromSource( sourceModel()->index( row, column, mapToSource( parent ) ) );
264 }
265 
267 QModelIndex ForwardingProxyModel::parent( const QModelIndex& idx ) const
268 {
269  return mapFromSource( sourceModel()->parent( mapToSource( idx ) ) );
270 }
271 
273 bool ForwardingProxyModel::setData( const QModelIndex& index, const QVariant& value, int role )
274 {
275  //qDebug() << "ForwardingProxyModel::setData( " << index<<value<< role<<")";
276  return sourceModel()->setData( mapToSource( index ), value, role );
277 }
278 
279 #include "moc_kdganttforwardingproxymodel.cpp"
280 
KDGantt::ForwardingProxyModel::ForwardingProxyModel
ForwardingProxyModel(QObject *parent=0)
Definition: kdganttforwardingproxymodel.cpp:36
KDGantt::ForwardingProxyModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Definition: kdganttforwardingproxymodel.cpp:273
KDGantt::ForwardingProxyModel::sourceModelAboutToBeReset
virtual void sourceModelAboutToBeReset()
Definition: kdganttforwardingproxymodel.cpp:126
KDGantt::ForwardingProxyModel::sourceDataChanged
virtual void sourceDataChanged(const QModelIndex &from, const QModelIndex &to)
Definition: kdganttforwardingproxymodel.cpp:162
KDGantt::ForwardingProxyModel::~ForwardingProxyModel
virtual ~ForwardingProxyModel()
Definition: kdganttforwardingproxymodel.cpp:41
BASE
QAbstractProxyModel BASE
Definition: kdganttforwardingproxymodel.cpp:31
KDGantt::ForwardingProxyModel::sourceLayoutAboutToBeChanged
virtual void sourceLayoutAboutToBeChanged()
Definition: kdganttforwardingproxymodel.cpp:144
KDGantt::ForwardingProxyModel::sourceLayoutChanged
virtual void sourceLayoutChanged()
Definition: kdganttforwardingproxymodel.cpp:153
KDGantt::ForwardingProxyModel::columnCount
int columnCount(const QModelIndex &idx=QModelIndex()) const
Definition: kdganttforwardingproxymodel.cpp:255
KDGantt::ForwardingProxyModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: kdganttforwardingproxymodel.cpp:261
KDGantt::ForwardingProxyModel::sourceRowsAboutToBeRemoved
virtual void sourceRowsAboutToBeRemoved(const QModelIndex &, int start, int end)
Definition: kdganttforwardingproxymodel.cpp:232
QObject
KDGantt::ForwardingProxyModel::sourceRowsInserted
virtual void sourceRowsInserted(const QModelIndex &idx, int start, int end)
Definition: kdganttforwardingproxymodel.cpp:221
KDGantt::ForwardingProxyModel::mapFromSource
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
Definition: kdganttforwardingproxymodel.cpp:46
kdganttforwardingproxymodel.h
KDGantt::ForwardingProxyModel::rowCount
int rowCount(const QModelIndex &idx=QModelIndex()) const
Definition: kdganttforwardingproxymodel.cpp:249
KDGantt::ForwardingProxyModel::setSourceModel
void setSourceModel(QAbstractItemModel *model)
Definition: kdganttforwardingproxymodel.cpp:88
KDGantt::ForwardingProxyModel::sourceColumnsAboutToBeRemoved
virtual void sourceColumnsAboutToBeRemoved(const QModelIndex &idx, int start, int end)
Definition: kdganttforwardingproxymodel.cpp:192
KDGantt::ForwardingProxyModel::sourceRowsAboutToBeInserted
virtual void sourceRowsAboutToBeInserted(const QModelIndex &idx, int start, int end)
Definition: kdganttforwardingproxymodel.cpp:213
KDGantt::ForwardingProxyModel::sourceColumnsAboutToBeInserted
virtual void sourceColumnsAboutToBeInserted(const QModelIndex &idx, int start, int end)
Definition: kdganttforwardingproxymodel.cpp:171
QAbstractProxyModel
KDGantt::ForwardingProxyModel::sourceColumnsInserted
virtual void sourceColumnsInserted(const QModelIndex &idx, int start, int end)
Definition: kdganttforwardingproxymodel.cpp:181
KDGantt::ForwardingProxyModel::mapToSource
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Definition: kdganttforwardingproxymodel.cpp:67
KDGantt::ForwardingProxyModel::parent
QModelIndex parent(const QModelIndex &idx) const
Definition: kdganttforwardingproxymodel.cpp:267
KDGantt::ForwardingProxyModel::sourceColumnsRemoved
virtual void sourceColumnsRemoved(const QModelIndex &idx, int start, int end)
Definition: kdganttforwardingproxymodel.cpp:202
KDGantt::ForwardingProxyModel::sourceModelReset
virtual void sourceModelReset()
Definition: kdganttforwardingproxymodel.cpp:134
KDGantt::ForwardingProxyModel::sourceRowsRemoved
virtual void sourceRowsRemoved(const QModelIndex &, int start, int end)
Definition: kdganttforwardingproxymodel.cpp:240
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:05 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdgantt2

Skip menu "kdgantt2"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal