#include <kdganttsummaryhandlingproxymodel.h>
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.
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) |
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().
SummaryHandlingProxyModel::~SummaryHandlingProxyModel | ( | ) | [virtual] |
int ForwardingProxyModel::columnCount | ( | const QModelIndex & | idx = QModelIndex() |
) | const [inherited] |
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 |
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 |
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] |
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] |
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] |
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 | |||
) |
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.
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.
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.
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.
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.
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.
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.
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.
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.
Definition at line 126 of file kdganttforwardingproxymodel.cpp.
Referenced by KDGantt::ForwardingProxyModel::setSourceModel().
void SummaryHandlingProxyModel::sourceModelReset | ( | ) | [protected, virtual] |
Called when the source model is reset
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.
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.
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.
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.
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 }