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

kdgantt

kdganttforwardingproxymodel.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002  ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB.  All rights reserved.
00003  **
00004  ** This file is part of the KD Gantt library.
00005  **
00006  ** This file may be used under the terms of the GNU General Public
00007  ** License versions 2.0 or 3.0 as published by the Free Software
00008  ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
00009  ** included in the packaging of this file.  Alternatively you may (at
00010  ** your option) use any later version of the GNU General Public
00011  ** License if such license has been publicly approved by
00012  ** Klarälvdalens Datakonsult AB (or its successors, if any).
00013  ** 
00014  ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
00015  ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
00016  ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
00017  ** not expressly granted herein.
00018  ** 
00019  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021  **
00022  **********************************************************************/
00023 #include "kdganttforwardingproxymodel.h"
00024 
00025 #include <cassert>
00026 
00027 using namespace KDGantt;
00028 
00029 typedef QAbstractProxyModel BASE;
00030 
00034 ForwardingProxyModel::ForwardingProxyModel( QObject* parent )
00035     : BASE( parent )
00036 {
00037 }
00038 
00039 ForwardingProxyModel::~ForwardingProxyModel()
00040 {
00041 }
00042 
00044 QModelIndex ForwardingProxyModel::mapFromSource ( const QModelIndex & sourceIndex ) const
00045 {
00046     if ( !sourceIndex.isValid() )
00047         return QModelIndex();
00048     assert( sourceIndex.model() == sourceModel() );
00049 
00050     // Create an index that preserves the internal pointer from the source;
00051     // this way KDDataConverterProxyModel preserves the structure of the source model
00052     return createIndex( sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer() );
00053 }
00054 
00055 namespace {
00056     // Think this is ugly? Well, it's not from me, it comes from QProxyModel
00057     struct KDPrivateModelIndex {
00058         int r, c;
00059         void *p;
00060         const QAbstractItemModel *m;
00061     };
00062 }
00063 
00065 QModelIndex ForwardingProxyModel::mapToSource ( const QModelIndex & proxyIndex ) const
00066 {
00067     if ( !proxyIndex.isValid() )
00068         return QModelIndex();
00069     assert( proxyIndex.model() == this );
00070     // So here we need to create a source index which holds that internal pointer.
00071     // No way to pass it to sourceModel()->index... so we have to do the ugly way:
00072     QModelIndex sourceIndex;
00073     KDPrivateModelIndex* hack = reinterpret_cast<KDPrivateModelIndex*>(&sourceIndex);
00074     hack->r = proxyIndex.row();
00075     hack->c = proxyIndex.column();
00076     hack->p = proxyIndex.internalPointer();
00077     hack->m = sourceModel();
00078     assert( sourceIndex.isValid() );
00079     return sourceIndex;
00080 }
00081 
00086 void ForwardingProxyModel::setSourceModel( QAbstractItemModel* model )
00087 {
00088     if ( sourceModel() ) sourceModel()->disconnect( this );
00089     BASE::setSourceModel( model );
00090 
00091     if(!model) return;
00092 
00093     connect( model, SIGNAL(modelAboutToBeReset()), this, SLOT(sourceModelAboutToBeReset()) );
00094     connect( model, SIGNAL(modelReset()), this, SLOT(sourceModelReset()) );
00095     connect( model, SIGNAL(layoutAboutToBeChanged()), this, SLOT(sourceLayoutAboutToBeChanged()) );
00096     connect( model, SIGNAL(layoutChanged()), this, SLOT(sourceLayoutChanged()) );
00097 
00098     connect( model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)),
00099              this, SLOT(sourceDataChanged(const QModelIndex&,const QModelIndex&)) );
00100 
00101 
00102     connect( model,  SIGNAL(columnsAboutToBeInserted(const QModelIndex&, int,int)),
00103              this, SLOT(sourceColumnsAboutToBeInserted(const QModelIndex&,int,int)) );
00104     connect( model,  SIGNAL(columnsInserted(const QModelIndex&, int,int)),
00105              this, SLOT(sourceColumnsInserted(const QModelIndex&,int,int)) );
00106     connect( model,  SIGNAL(columnsAboutToBeRemoved(const QModelIndex&, int,int)),
00107              this, SLOT(sourceColumnsAboutToBeRemoved(const QModelIndex&,int,int)) );
00108     connect( model,  SIGNAL(columnsRemoved(const QModelIndex&, int,int)),
00109              this, SLOT(sourceColumnsRemoved(const QModelIndex&,int,int)) );
00110 
00111     connect( model,  SIGNAL(rowsAboutToBeInserted(const QModelIndex&, int,int)),
00112              this, SLOT(sourceRowsAboutToBeInserted(const QModelIndex&,int,int)) );
00113     connect( model,  SIGNAL(rowsInserted(const QModelIndex&, int,int)),
00114              this, SLOT(sourceRowsInserted(const QModelIndex&,int,int)) );
00115     connect( model,  SIGNAL(rowsAboutToBeRemoved(const QModelIndex&, int,int)),
00116              this, SLOT(sourceRowsAboutToBeRemoved(const QModelIndex&,int,int)) );
00117     connect( model,  SIGNAL(rowsRemoved(const QModelIndex&, int,int)),
00118              this, SLOT(sourceRowsRemoved(const QModelIndex&,int,int)) );
00119 }
00120 
00124 void ForwardingProxyModel::sourceModelAboutToBeReset()
00125 {
00126     // The matching signal is emitted be reset()
00127 }
00128 
00132 void ForwardingProxyModel::sourceModelReset()
00133 {
00134   //qDebug() << "ForwardingProxyModel::sourceModelReset()";
00135     reset();
00136 }
00137 
00142 void ForwardingProxyModel::sourceLayoutAboutToBeChanged()
00143 {
00144   //qDebug() << "ForwardingProxyModel::sourceLayoutAboutToBeChanged()";
00145     emit layoutAboutToBeChanged();
00146 }
00147 
00151 void ForwardingProxyModel::sourceLayoutChanged()
00152 {
00153   //qDebug() << "ForwardingProxyModel::sourceLayoutChanged()";
00154     reset();
00155 }
00156 
00160 void ForwardingProxyModel::sourceDataChanged( const QModelIndex& from, const QModelIndex& to )
00161 {
00162   //qDebug() << "ForwardingProxyModel::sourceDataChanged("<<from<<to<<")";
00163     emit dataChanged( mapFromSource( from ), mapFromSource( to ) );
00164 }
00165 
00169 void ForwardingProxyModel::sourceColumnsAboutToBeInserted( const QModelIndex& parentIdx,
00170                                                                     int start,
00171                                                                     int end )
00172 {
00173     beginInsertColumns( mapFromSource( parentIdx ), start, end );
00174 }
00175 
00179 void ForwardingProxyModel::sourceColumnsInserted( const QModelIndex& parentIdx, int start, int end )
00180 {
00181     Q_UNUSED( parentIdx );
00182     Q_UNUSED( start );
00183     Q_UNUSED( end );
00184     endInsertColumns();
00185 }
00186 
00190 void ForwardingProxyModel::sourceColumnsAboutToBeRemoved( const QModelIndex& parentIdx,
00191                                                                     int start,
00192                                                                     int end )
00193 {
00194     beginRemoveColumns( mapFromSource( parentIdx ), start, end );
00195 }
00196 
00200 void ForwardingProxyModel::sourceColumnsRemoved( const QModelIndex& parentIdx, int start, int end )
00201 {
00202     Q_UNUSED( parentIdx );
00203     Q_UNUSED( start );
00204     Q_UNUSED( end );
00205     endRemoveColumns();
00206 }
00207 
00211 void ForwardingProxyModel::sourceRowsAboutToBeInserted( const QModelIndex & parentIdx, int start, int end )
00212 {
00213     beginInsertRows( mapFromSource( parentIdx ), start, end );
00214 }
00215 
00219 void ForwardingProxyModel::sourceRowsInserted( const QModelIndex& parentIdx, int start, int end )
00220 {
00221     Q_UNUSED( parentIdx );
00222     Q_UNUSED( start );
00223     Q_UNUSED( end );
00224     endInsertRows();
00225 }
00226 
00230 void ForwardingProxyModel::sourceRowsAboutToBeRemoved( const QModelIndex & parentIdx, int start, int end )
00231 {
00232     beginRemoveRows( mapFromSource( parentIdx ), start, end );
00233 }
00234 
00238 void ForwardingProxyModel::sourceRowsRemoved( const QModelIndex& parentIdx, int start, int end )
00239 {
00240     Q_UNUSED( parentIdx );
00241     Q_UNUSED( start );
00242     Q_UNUSED( end );
00243     endRemoveRows();
00244 }
00245 
00247 int ForwardingProxyModel::rowCount( const QModelIndex& idx ) const
00248 {
00249     return sourceModel()->rowCount( mapToSource( idx ) );
00250 }
00251 
00253 int ForwardingProxyModel::columnCount( const QModelIndex& idx ) const
00254 {
00255     return sourceModel()->columnCount( mapToSource( idx ) );
00256 }
00257 
00259 QModelIndex ForwardingProxyModel::index( int row, int column, const QModelIndex& parent ) const
00260 {
00261     return mapFromSource( sourceModel()->index( row, column, mapToSource( parent ) ) );
00262 }
00263 
00265 QModelIndex ForwardingProxyModel::parent( const QModelIndex& idx ) const
00266 {
00267     return mapFromSource( sourceModel()->parent( mapToSource( idx ) ) );
00268 }
00269 
00271 bool ForwardingProxyModel::setData( const QModelIndex& index, const QVariant& value, int role )
00272 {
00273   //qDebug() << "ForwardingProxyModel::setData( " << index<<value<< role<<")";
00274     return sourceModel()->setData( mapToSource( index ), value, role );
00275 }
00276 
00277 #include "moc_kdganttforwardingproxymodel.cpp"
00278 

kdgantt

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

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal