KDGantt::SummaryHandlingProxyModel Class Reference

#include <kdganttsummaryhandlingproxymodel.h>

Inheritance diagram for KDGantt::SummaryHandlingProxyModel:

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

Collaboration graph
[legend]

List of all members.


Detailed Description

Proxy model that supports summary gantt items.

This proxy model provides the functionality of summary items. A summary item is an item with type KDGantt::TypeSummary and zero or more children in the model that it summarizes. GraphicsView itself does not dictate any policy for summary items, instead the logic for making the summary items start and end points span it's children is provided by this proxy.

The start and end times of a summary is the min/max of the start/end times of it's children.

See also:
GraphicsView::setModel

Definition at line 31 of file kdganttsummaryhandlingproxymodel.h.


Public Member Functions

int columnCount (const QModelIndex &idx=QModelIndex()) const
QVariant data (const QModelIndex &proxyIndex, int role=Qt::DisplayRole) const
Qt::ItemFlags flags (const QModelIndex &idx) const
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)
 SummaryHandlingProxyModel (QObject *parent=0)
virtual ~SummaryHandlingProxyModel ()

Protected Slots

virtual void sourceColumnsInserted (const QModelIndex &idx, int start, int end)
virtual void sourceColumnsRemoved (const QModelIndex &idx, int start, int end)
virtual void sourceLayoutAboutToBeChanged ()
virtual void sourceModelAboutToBeReset ()
virtual void sourceRowsInserted (const QModelIndex &idx, int start, int end)
virtual void sourceRowsRemoved (const QModelIndex &, int start, int end)

Protected Member Functions

void sourceColumnsAboutToBeInserted (const QModelIndex &idx, int start, int end)
void sourceColumnsAboutToBeRemoved (const QModelIndex &idx, int start, int end)
void sourceDataChanged (const QModelIndex &from, const QModelIndex &to)
void sourceLayoutChanged ()
void sourceModelReset ()
void sourceRowsAboutToBeInserted (const QModelIndex &idx, int start, int end)
void sourceRowsAboutToBeRemoved (const QModelIndex &, int start, int end)

Constructor & Destructor Documentation

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

Constructor. Creates a new SummaryHandlingProxyModel with parent parent

Definition at line 124 of file kdganttsummaryhandlingproxymodel.cpp.

References StockDiagram::init().

00125     : BASE( parent ), _d( new Private )
00126 {
00127     init();
00128 }

SummaryHandlingProxyModel::~SummaryHandlingProxyModel (  )  [virtual]

Definition at line 131 of file kdganttsummaryhandlingproxymodel.cpp.

00132 {
00133 }


Member Function Documentation

int ForwardingProxyModel::columnCount ( const QModelIndex &  idx = QModelIndex()  )  const [inherited]

See also:
QAbstractItemModel::columnCount

Reimplemented in KDGantt::ProxyModel.

Definition at line 255 of file kdganttforwardingproxymodel.cpp.

References KDGantt::ForwardingProxyModel::mapToSource().

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

QVariant SummaryHandlingProxyModel::data ( const QModelIndex &  proxyIndex,
int  role = Qt::DisplayRole 
) const

See also:
QAbstractItemModel::data

Definition at line 229 of file kdganttsummaryhandlingproxymodel.cpp.

References d, KDGantt::EndTimeRole, KDGantt::ForwardingProxyModel::mapToSource(), and KDGantt::StartTimeRole.

Referenced by KDAB_SCOPED_UNITTEST_SIMPLE().

00230 {
00231   //qDebug() << "SummaryHandlingProxyModel::data("<<proxyIndex<<role<<")";
00232     const QModelIndex sidx = mapToSource( proxyIndex );
00233     const QAbstractItemModel* model = sourceModel();
00234     if ( d->isSummary(sidx) && ( role==StartTimeRole || role==EndTimeRole )) {
00235       //qDebug() << "requested summary";
00236         QPair<QDateTime,QDateTime> result;
00237         if ( d->cacheLookup( sidx, &result ) ) {
00238           //qDebug() << "SummaryHandlingProxyModel::data(): Looking up summary for " << proxyIndex << role;
00239             switch( role ) {
00240             case StartTimeRole: return result.first;
00241             case EndTimeRole: return result.second;
00242             default: /* fall thru */;
00243             }
00244         } else {
00245             d->insertInCache( this, sidx );
00246             return data( proxyIndex, role ); /* TODO: Optimise */
00247         }
00248     }
00249     return model->data( sidx, role );
00250 }

Qt::ItemFlags SummaryHandlingProxyModel::flags ( const QModelIndex &  idx  )  const

See also:
QAbstractItemModel::flags

Definition at line 217 of file kdganttsummaryhandlingproxymodel.cpp.

References d, and KDGantt::ForwardingProxyModel::mapToSource().

Referenced by KDAB_SCOPED_UNITTEST_SIMPLE().

00218 {
00219     const QModelIndex sidx = mapToSource( idx );
00220     const QAbstractItemModel* model = sourceModel();
00221     Qt::ItemFlags f = model->flags( sidx );
00222     if ( d->isSummary(sidx) ) {
00223         f &= !Qt::ItemIsEditable;
00224     }
00225     return f;
00226 }

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

See also:
QAbstractItemModel::index

Definition at line 261 of file kdganttforwardingproxymodel.cpp.

References KDGantt::ForwardingProxyModel::mapFromSource(), and KDGantt::ForwardingProxyModel::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 [inherited]

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 KDGantt::ForwardingProxyModel::index(), KDGantt::ForwardingProxyModel::parent(), setData(), KDGantt::ForwardingProxyModel::sourceColumnsAboutToBeInserted(), KDGantt::ForwardingProxyModel::sourceColumnsAboutToBeRemoved(), sourceDataChanged(), KDGantt::ForwardingProxyModel::sourceDataChanged(), KDGantt::ForwardingProxyModel::sourceRowsAboutToBeInserted(), and KDGantt::ForwardingProxyModel::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 [inherited]

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 KDGantt::ForwardingProxyModel::columnCount(), data(), flags(), KDGantt::ForwardingProxyModel::index(), KDGantt::ForwardingProxyModel::parent(), KDGantt::ForwardingProxyModel::rowCount(), setData(), and KDGantt::ForwardingProxyModel::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 [inherited]

See also:
QAbstractItemModel::parent

Definition at line 267 of file kdganttforwardingproxymodel.cpp.

References KDGantt::ForwardingProxyModel::mapFromSource(), and KDGantt::ForwardingProxyModel::mapToSource().

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

int ForwardingProxyModel::rowCount ( const QModelIndex &  idx = QModelIndex()  )  const [inherited]

See also:
QAbstractItemModel::rowCount

Reimplemented in KDGantt::ProxyModel.

Definition at line 249 of file kdganttforwardingproxymodel.cpp.

References KDGantt::ForwardingProxyModel::mapToSource().

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

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

See also:
QAbstractItemModel::setData

Reimplemented from KDGantt::ForwardingProxyModel.

Definition at line 253 of file kdganttsummaryhandlingproxymodel.cpp.

References d, KDGantt::EndTimeRole, KDGantt::ForwardingProxyModel::mapFromSource(), KDGantt::ForwardingProxyModel::mapToSource(), and KDGantt::StartTimeRole.

00254 {
00255     QAbstractItemModel* model = sourceModel();
00256     if ( role==StartTimeRole || role==EndTimeRole ) {
00257         QModelIndex parentIdx = mapToSource( index );
00258         do {
00259             if ( d->isSummary(parentIdx) ) {
00260               //qDebug() << "removing " << parentIdx << "from cache";
00261                 d->removeFromCache( parentIdx );
00262                 QModelIndex proxyParentIdx = mapFromSource( parentIdx );
00263                 emit dataChanged( proxyParentIdx, proxyParentIdx );
00264             }
00265         } while ( ( parentIdx=model->parent( parentIdx ) ) != QModelIndex() );
00266     }
00267     return BASE::setData( index, value, role );
00268 }

void SummaryHandlingProxyModel::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 from KDGantt::ForwardingProxyModel.

Definition at line 153 of file kdganttsummaryhandlingproxymodel.cpp.

References d.

Referenced by KDAB_SCOPED_UNITTEST_SIMPLE().

00154 {
00155     BASE::setSourceModel( model );
00156     d->clearCache();
00157 }

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

Called just before columns are inserted into the source model.

See also:
QAbstractItemModel::columnsAboutToBeInserted()

Reimplemented from KDGantt::ForwardingProxyModel.

Definition at line 188 of file kdganttsummaryhandlingproxymodel.cpp.

References d.

00191 {
00192     BASE::sourceColumnsAboutToBeInserted( parentIdx, start, end );
00193     d->clearCache();
00194 }

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

Called just before columns are removed from the source model.

See also:
QAbstractItemModel::columnsAboutToBeRemoved()

Reimplemented from KDGantt::ForwardingProxyModel.

Definition at line 196 of file kdganttsummaryhandlingproxymodel.cpp.

References d.

00199 {
00200     BASE::sourceColumnsAboutToBeRemoved( parentIdx, start, end );
00201     d->clearCache();
00202 }

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

Called after columns have been inserted into the source model.

See also:
QAbstractItemModel::columnsInserted()

Definition at line 181 of file kdganttforwardingproxymodel.cpp.

Referenced by KDGantt::ForwardingProxyModel::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, inherited]

Called after columns have been removed from the source model.

See also:
QAbstractItemModel::columnsRemoved()

Definition at line 202 of file kdganttforwardingproxymodel.cpp.

Referenced by KDGantt::ForwardingProxyModel::setSourceModel().

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

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

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

See also:
QAbstractItemModel::dataChanged()

Reimplemented from KDGantt::ForwardingProxyModel.

Definition at line 171 of file kdganttsummaryhandlingproxymodel.cpp.

References d, KDGantt::ItemTypeRole, KDGantt::ForwardingProxyModel::mapFromSource(), and KDGantt::TypeSummary.

00172 {
00173     QAbstractItemModel* model = sourceModel();
00174     QModelIndex parentIdx = from;
00175     do {
00176         const QModelIndex& dataIdx = parentIdx;
00177         if ( model->data( dataIdx, ItemTypeRole )==TypeSummary ) {
00178             //qDebug() << "removing " << parentIdx << "from cache";
00179             d->removeFromCache( dataIdx );
00180             QModelIndex proxyDataIdx = mapFromSource( dataIdx );
00181             emit dataChanged( proxyDataIdx, proxyDataIdx );
00182         }
00183     } while ( ( parentIdx=model->parent( parentIdx ) ) != QModelIndex() );
00184 
00185     BASE::sourceDataChanged( from, to );
00186 }

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

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 KDGantt::ForwardingProxyModel::setSourceModel().

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

void SummaryHandlingProxyModel::sourceLayoutChanged (  )  [protected, virtual]

Called when the layout of the source model has changed.

See also:
QAbstractItemModel::layoutChanged()

Reimplemented from KDGantt::ForwardingProxyModel.

Definition at line 165 of file kdganttsummaryhandlingproxymodel.cpp.

References d.

00166 {
00167     d->clearCache();
00168     BASE::sourceLayoutChanged();
00169 }

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

Called when the source model is about to be reset.

See also:
QAbstractItemModel::modelAboutToBeReset()

Definition at line 126 of file kdganttforwardingproxymodel.cpp.

Referenced by KDGantt::ForwardingProxyModel::setSourceModel().

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

void SummaryHandlingProxyModel::sourceModelReset (  )  [protected, virtual]

Called when the source model is reset

See also:
QAbstractItemModel::modelReset()

Reimplemented from KDGantt::ForwardingProxyModel.

Definition at line 159 of file kdganttsummaryhandlingproxymodel.cpp.

References d.

00160 {
00161     d->clearCache();
00162     BASE::sourceModelReset();
00163 }

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

Called just before rows are inserted into the source model.

See also:
QAbstractItemModel::rowsAboutToBeInserted()

Reimplemented from KDGantt::ForwardingProxyModel.

Definition at line 204 of file kdganttsummaryhandlingproxymodel.cpp.

References d.

00205 {
00206     BASE::sourceRowsAboutToBeInserted( parentIdx, start, end );
00207     d->clearCache();
00208 }

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

Called just before rows are removed from the source model.

See also:
QAbstractItemModel::rowsAboutToBeRemoved()

Reimplemented from KDGantt::ForwardingProxyModel.

Definition at line 210 of file kdganttsummaryhandlingproxymodel.cpp.

References d.

00211 {
00212     BASE::sourceRowsAboutToBeRemoved( parentIdx, start, end );
00213     d->clearCache();
00214 }

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

Called after rows have been inserted into the source model.

See also:
QAbstractItemModel::rowsInserted()

Definition at line 221 of file kdganttforwardingproxymodel.cpp.

Referenced by KDGantt::ForwardingProxyModel::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, inherited]

Called after rows have been removed from the source model.

See also:
QAbstractItemModel::rowsRemoved()

Definition at line 240 of file kdganttforwardingproxymodel.cpp.

Referenced by KDGantt::ForwardingProxyModel::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:20 2010 for KD Chart 2 by  doxygen 1.5.4