KDGantt::ForwardingProxyModel Class Reference

#include <kdganttforwardingproxymodel.h>

Inheritance diagram for KDGantt::ForwardingProxyModel:

Inheritance graph
[legend]
Collaboration diagram for KDGantt::ForwardingProxyModel:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition at line 33 of file kdganttforwardingproxymodel.h.


Public Member Functions

int columnCount (const QModelIndex &idx=QModelIndex()) const
 ForwardingProxyModel (QObject *parent=0)
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
QModelIndex mapFromSource (const QModelIndex &sourceIndex) const
QModelIndex mapToSource (const QModelIndex &proxyIndex) const
QModelIndex parent (const QModelIndex &idx) const
int rowCount (const QModelIndex &idx=QModelIndex()) const
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
void setSourceModel (QAbstractItemModel *model)
virtual ~ForwardingProxyModel ()

Protected Slots

virtual void sourceColumnsAboutToBeInserted (const QModelIndex &idx, int start, int end)
virtual void sourceColumnsAboutToBeRemoved (const QModelIndex &idx, int start, int end)
virtual void sourceColumnsInserted (const QModelIndex &idx, int start, int end)
virtual void sourceColumnsRemoved (const QModelIndex &idx, int start, int end)
virtual void sourceDataChanged (const QModelIndex &from, const QModelIndex &to)
virtual void sourceLayoutAboutToBeChanged ()
virtual void sourceLayoutChanged ()
virtual void sourceModelAboutToBeReset ()
virtual void sourceModelReset ()
virtual void sourceRowsAboutToBeInserted (const QModelIndex &idx, int start, int end)
virtual void sourceRowsAboutToBeRemoved (const QModelIndex &, int start, int end)
virtual void sourceRowsInserted (const QModelIndex &idx, int start, int end)
virtual void sourceRowsRemoved (const QModelIndex &, int start, int end)

Constructor & Destructor Documentation

ForwardingProxyModel::ForwardingProxyModel ( QObject parent = 0  )  [explicit]

Constructor. Creates a new ForwardingProxyModel with parent parent

Definition at line 36 of file kdganttforwardingproxymodel.cpp.

00037     : BASE( parent )
00038 {
00039 }

ForwardingProxyModel::~ForwardingProxyModel (  )  [virtual]

Definition at line 41 of file kdganttforwardingproxymodel.cpp.

00042 {
00043 }


Member Function Documentation

int ForwardingProxyModel::columnCount ( const QModelIndex &  idx = QModelIndex()  )  const

See also:
QAbstractItemModel::columnCount

Reimplemented in KDGantt::ProxyModel.

Definition at line 255 of file kdganttforwardingproxymodel.cpp.

References mapToSource().

00256 {
00257     return sourceModel()->columnCount( mapToSource( idx ) );
00258 }

QModelIndex ForwardingProxyModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const

See also:
QAbstractItemModel::index

Definition at line 261 of file kdganttforwardingproxymodel.cpp.

References mapFromSource(), and mapToSource().

Referenced by KDGantt::ProxyModel::data(), and KDAB_SCOPED_UNITTEST_SIMPLE().

00262 {
00263     return mapFromSource( sourceModel()->index( row, column, mapToSource( parent ) ) );
00264 }

QModelIndex ForwardingProxyModel::mapFromSource ( const QModelIndex &  sourceIndex  )  const

Converts indexes in the source model to indexes in the proxy model

Reimplemented in KDGantt::ProxyModel.

Definition at line 46 of file kdganttforwardingproxymodel.cpp.

Referenced by index(), parent(), KDGantt::SummaryHandlingProxyModel::setData(), sourceColumnsAboutToBeInserted(), sourceColumnsAboutToBeRemoved(), KDGantt::SummaryHandlingProxyModel::sourceDataChanged(), sourceDataChanged(), sourceRowsAboutToBeInserted(), and sourceRowsAboutToBeRemoved().

00047 {
00048     if ( !sourceIndex.isValid() )
00049         return QModelIndex();
00050     assert( sourceIndex.model() == sourceModel() );
00051 
00052     // Create an index that preserves the internal pointer from the source;
00053     // this way KDDataConverterProxyModel preserves the structure of the source model
00054     return createIndex( sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer() );
00055 }

QModelIndex ForwardingProxyModel::mapToSource ( const QModelIndex &  proxyIndex  )  const

Converts indexes in the proxy model to indexes in the source model

Reimplemented in KDGantt::ProxyModel.

Definition at line 67 of file kdganttforwardingproxymodel.cpp.

Referenced by columnCount(), KDGantt::SummaryHandlingProxyModel::data(), KDGantt::SummaryHandlingProxyModel::flags(), index(), parent(), rowCount(), KDGantt::SummaryHandlingProxyModel::setData(), and setData().

00068 {
00069     if ( !proxyIndex.isValid() )
00070         return QModelIndex();
00071     assert( proxyIndex.model() == this );
00072     // So here we need to create a source index which holds that internal pointer.
00073     // No way to pass it to sourceModel()->index... so we have to do the ugly way:
00074     QModelIndex sourceIndex;
00075     KDPrivateModelIndex* hack = reinterpret_cast<KDPrivateModelIndex*>(&sourceIndex);
00076     hack->r = proxyIndex.row();
00077     hack->c = proxyIndex.column();
00078     hack->p = proxyIndex.internalPointer();
00079     hack->m = sourceModel();
00080     assert( sourceIndex.isValid() );
00081     return sourceIndex;
00082 }

QModelIndex ForwardingProxyModel::parent ( const QModelIndex &  idx  )  const

See also:
QAbstractItemModel::parent

Definition at line 267 of file kdganttforwardingproxymodel.cpp.

References mapFromSource(), and mapToSource().

00268 {
00269     return mapFromSource( sourceModel()->parent( mapToSource( idx ) ) );
00270 }

int ForwardingProxyModel::rowCount ( const QModelIndex &  idx = QModelIndex()  )  const

See also:
QAbstractItemModel::rowCount

Reimplemented in KDGantt::ProxyModel.

Definition at line 249 of file kdganttforwardingproxymodel.cpp.

References mapToSource().

00250 {
00251     return sourceModel()->rowCount( mapToSource( idx ) );
00252 }

bool ForwardingProxyModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)

See also:
QAbstractItemModel::setData

Reimplemented in KDGantt::ProxyModel, and KDGantt::SummaryHandlingProxyModel.

Definition at line 273 of file kdganttforwardingproxymodel.cpp.

References mapToSource().

00274 {
00275   //qDebug() << "ForwardingProxyModel::setData( " << index<<value<< role<<")";
00276     return sourceModel()->setData( mapToSource( index ), value, role );
00277 }

void ForwardingProxyModel::setSourceModel ( QAbstractItemModel *  model  ) 

Sets the model to be used as the source model for this proxy. The proxy does not take ownership of the model.

See also:
QAbstractProxyModel::setSourceModel

Reimplemented in KDGantt::SummaryHandlingProxyModel.

Definition at line 88 of file kdganttforwardingproxymodel.cpp.

References sourceColumnsAboutToBeInserted(), sourceColumnsAboutToBeRemoved(), sourceColumnsInserted(), sourceColumnsRemoved(), sourceDataChanged(), sourceLayoutAboutToBeChanged(), sourceLayoutChanged(), sourceModelAboutToBeReset(), sourceModelReset(), sourceRowsAboutToBeInserted(), sourceRowsAboutToBeRemoved(), sourceRowsInserted(), and sourceRowsRemoved().

00089 {
00090     if ( sourceModel() ) sourceModel()->disconnect( this );
00091     BASE::setSourceModel( model );
00092 
00093     if(!model) return;
00094 
00095     connect( model, SIGNAL(modelAboutToBeReset()), this, SLOT(sourceModelAboutToBeReset()) );
00096     connect( model, SIGNAL(modelReset()), this, SLOT(sourceModelReset()) );
00097     connect( model, SIGNAL(layoutAboutToBeChanged()), this, SLOT(sourceLayoutAboutToBeChanged()) );
00098     connect( model, SIGNAL(layoutChanged()), this, SLOT(sourceLayoutChanged()) );
00099 
00100     connect( model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)),
00101              this, SLOT(sourceDataChanged(const QModelIndex&,const QModelIndex&)) );
00102 
00103 
00104     connect( model,  SIGNAL(columnsAboutToBeInserted(const QModelIndex&, int,int)),
00105              this, SLOT(sourceColumnsAboutToBeInserted(const QModelIndex&,int,int)) );
00106     connect( model,  SIGNAL(columnsInserted(const QModelIndex&, int,int)),
00107              this, SLOT(sourceColumnsInserted(const QModelIndex&,int,int)) );
00108     connect( model,  SIGNAL(columnsAboutToBeRemoved(const QModelIndex&, int,int)),
00109              this, SLOT(sourceColumnsAboutToBeRemoved(const QModelIndex&,int,int)) );
00110     connect( model,  SIGNAL(columnsRemoved(const QModelIndex&, int,int)),
00111              this, SLOT(sourceColumnsRemoved(const QModelIndex&,int,int)) );
00112 
00113     connect( model,  SIGNAL(rowsAboutToBeInserted(const QModelIndex&, int,int)),
00114              this, SLOT(sourceRowsAboutToBeInserted(const QModelIndex&,int,int)) );
00115     connect( model,  SIGNAL(rowsInserted(const QModelIndex&, int,int)),
00116              this, SLOT(sourceRowsInserted(const QModelIndex&,int,int)) );
00117     connect( model,  SIGNAL(rowsAboutToBeRemoved(const QModelIndex&, int,int)),
00118              this, SLOT(sourceRowsAboutToBeRemoved(const QModelIndex&,int,int)) );
00119     connect( model,  SIGNAL(rowsRemoved(const QModelIndex&, int,int)),
00120              this, SLOT(sourceRowsRemoved(const QModelIndex&,int,int)) );
00121 }

void ForwardingProxyModel::sourceColumnsAboutToBeInserted ( const QModelIndex &  parentIdx,
int  start,
int  end 
) [protected, virtual, slot]

Called just before columns are inserted into the source model.

See also:
QAbstractItemModel::columnsAboutToBeInserted()

Reimplemented in KDGantt::SummaryHandlingProxyModel.

Definition at line 171 of file kdganttforwardingproxymodel.cpp.

References mapFromSource().

Referenced by setSourceModel().

00174 {
00175     beginInsertColumns( mapFromSource( parentIdx ), start, end );
00176 }

void ForwardingProxyModel::sourceColumnsAboutToBeRemoved ( const QModelIndex &  parentIdx,
int  start,
int  end 
) [protected, virtual, slot]

Called just before columns are removed from the source model.

See also:
QAbstractItemModel::columnsAboutToBeRemoved()

Reimplemented in KDGantt::SummaryHandlingProxyModel.

Definition at line 192 of file kdganttforwardingproxymodel.cpp.

References mapFromSource().

Referenced by setSourceModel().

00195 {
00196     beginRemoveColumns( mapFromSource( parentIdx ), start, end );
00197 }

void ForwardingProxyModel::sourceColumnsInserted ( const QModelIndex &  parentIdx,
int  start,
int  end 
) [protected, virtual, slot]

Called after columns have been inserted into the source model.

See also:
QAbstractItemModel::columnsInserted()

Definition at line 181 of file kdganttforwardingproxymodel.cpp.

Referenced by setSourceModel().

00182 {
00183     Q_UNUSED( parentIdx );
00184     Q_UNUSED( start );
00185     Q_UNUSED( end );
00186     endInsertColumns();
00187 }

void ForwardingProxyModel::sourceColumnsRemoved ( const QModelIndex &  parentIdx,
int  start,
int  end 
) [protected, virtual, slot]

Called after columns have been removed from the source model.

See also:
QAbstractItemModel::columnsRemoved()

Definition at line 202 of file kdganttforwardingproxymodel.cpp.

Referenced by setSourceModel().

00203 {
00204     Q_UNUSED( parentIdx );
00205     Q_UNUSED( start );
00206     Q_UNUSED( end );
00207     endRemoveColumns();
00208 }

void ForwardingProxyModel::sourceDataChanged ( const QModelIndex &  from,
const QModelIndex &  to 
) [protected, virtual, slot]

Called when the data in an existing item in the source model changes.

See also:
QAbstractItemModel::dataChanged()

Reimplemented in KDGantt::SummaryHandlingProxyModel.

Definition at line 162 of file kdganttforwardingproxymodel.cpp.

References mapFromSource().

Referenced by setSourceModel().

00163 {
00164   //qDebug() << "ForwardingProxyModel::sourceDataChanged("<<from<<to<<")";
00165     emit dataChanged( mapFromSource( from ), mapFromSource( to ) );
00166 }

void ForwardingProxyModel::sourceLayoutAboutToBeChanged (  )  [protected, virtual, slot]

Called just before the layout of the source model is changed.

See also:
QAbstractItemModel::layoutAboutToBeChanged()

Definition at line 144 of file kdganttforwardingproxymodel.cpp.

Referenced by setSourceModel().

00145 {
00146   //qDebug() << "ForwardingProxyModel::sourceLayoutAboutToBeChanged()";
00147     emit layoutAboutToBeChanged();
00148 }

void ForwardingProxyModel::sourceLayoutChanged (  )  [protected, virtual, slot]

Called when the layout of the source model has changed.

See also:
QAbstractItemModel::layoutChanged()

Reimplemented in KDGantt::SummaryHandlingProxyModel.

Definition at line 153 of file kdganttforwardingproxymodel.cpp.

Referenced by setSourceModel().

00154 {
00155   //qDebug() << "ForwardingProxyModel::sourceLayoutChanged()";
00156     reset();
00157 }

void ForwardingProxyModel::sourceModelAboutToBeReset (  )  [protected, virtual, slot]

Called when the source model is about to be reset.

See also:
QAbstractItemModel::modelAboutToBeReset()

Definition at line 126 of file kdganttforwardingproxymodel.cpp.

Referenced by setSourceModel().

00127 {
00128     // The matching signal is emitted be reset()
00129 }

void ForwardingProxyModel::sourceModelReset (  )  [protected, virtual, slot]

Called when the source model is reset

See also:
QAbstractItemModel::modelReset()

Reimplemented in KDGantt::SummaryHandlingProxyModel.

Definition at line 134 of file kdganttforwardingproxymodel.cpp.

Referenced by setSourceModel().

00135 {
00136   //qDebug() << "ForwardingProxyModel::sourceModelReset()";
00137     reset();
00138 }

void ForwardingProxyModel::sourceRowsAboutToBeInserted ( const QModelIndex &  parentIdx,
int  start,
int  end 
) [protected, virtual, slot]

Called just before rows are inserted into the source model.

See also:
QAbstractItemModel::rowsAboutToBeInserted()

Reimplemented in KDGantt::SummaryHandlingProxyModel.

Definition at line 213 of file kdganttforwardingproxymodel.cpp.

References mapFromSource().

Referenced by setSourceModel().

00214 {
00215     beginInsertRows( mapFromSource( parentIdx ), start, end );
00216 }

void ForwardingProxyModel::sourceRowsAboutToBeRemoved ( const QModelIndex &  parentIdx,
int  start,
int  end 
) [protected, virtual, slot]

Called just before rows are removed from the source model.

See also:
QAbstractItemModel::rowsAboutToBeRemoved()

Reimplemented in KDGantt::SummaryHandlingProxyModel.

Definition at line 232 of file kdganttforwardingproxymodel.cpp.

References mapFromSource().

Referenced by setSourceModel().

00233 {
00234     beginRemoveRows( mapFromSource( parentIdx ), start, end );
00235 }

void ForwardingProxyModel::sourceRowsInserted ( const QModelIndex &  parentIdx,
int  start,
int  end 
) [protected, virtual, slot]

Called after rows have been inserted into the source model.

See also:
QAbstractItemModel::rowsInserted()

Definition at line 221 of file kdganttforwardingproxymodel.cpp.

Referenced by setSourceModel().

00222 {
00223     Q_UNUSED( parentIdx );
00224     Q_UNUSED( start );
00225     Q_UNUSED( end );
00226     endInsertRows();
00227 }

void ForwardingProxyModel::sourceRowsRemoved ( const QModelIndex &  parentIdx,
int  start,
int  end 
) [protected, virtual, slot]

Called after rows have been removed from the source model.

See also:
QAbstractItemModel::rowsRemoved()

Definition at line 240 of file kdganttforwardingproxymodel.cpp.

Referenced by setSourceModel().

00241 {
00242     Q_UNUSED( parentIdx );
00243     Q_UNUSED( start );
00244     Q_UNUSED( end );
00245     endRemoveRows();
00246 }


The documentation for this class was generated from the following files:
Generated on Thu Mar 4 23:27:07 2010 for KD Chart 2 by  doxygen 1.5.4