kdgantt
kdganttproxymodel.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "kdganttproxymodel.h"
00024 #include "kdganttproxymodel_p.h"
00025
00026
00027 using namespace KDGantt;
00028
00029 typedef ForwardingProxyModel BASE;
00030
00031 ProxyModel::Private::Private( ProxyModel* _q )
00032 #if 0
00033 : calendarMode( false )
00034 #endif
00035 {
00036 Q_UNUSED( _q );
00037
00038 columnMap[Qt::DisplayRole] = 0;
00039 columnMap[ItemTypeRole] = 1;
00040 columnMap[StartTimeRole] = 2;
00041 columnMap[EndTimeRole] = 3;
00042 columnMap[TaskCompletionRole] = 4;
00043 columnMap[LegendRole] = 5;
00044
00045 roleMap[Qt::DisplayRole] = Qt::DisplayRole;
00046 roleMap[ItemTypeRole] = Qt::DisplayRole;
00047 roleMap[StartTimeRole] = Qt::DisplayRole;
00048 roleMap[EndTimeRole] = Qt::DisplayRole;
00049 roleMap[TaskCompletionRole] = Qt::DisplayRole;
00050 roleMap[LegendRole] = Qt::DisplayRole;
00051 }
00052
00053 ProxyModel::ProxyModel( QObject* parent )
00054 : BASE( parent ), _d( new Private( this ) )
00055 {
00056 init();
00057 }
00058
00059 ProxyModel::~ProxyModel()
00060 {
00061 delete _d; _d = 0;
00062 }
00063
00064 #define d d_func()
00065
00066 void ProxyModel::init()
00067 {
00068 }
00069
00070 QModelIndex ProxyModel::mapFromSource( const QModelIndex& sourceIdx ) const
00071 {
00072 if( sourceIdx.isValid() ) {
00073 #if 0
00074 if ( calendarMode() ) {
00075 const QAbstractItemModel* model = sourceIdx.model();
00076 if ( model->hasChildren( sourceIdx ) ) {
00077 return BASE::mapFromSource( model->index( sourceIdx.row(),0,sourceIdx.parent()));
00078 } else {
00079
00080 return BASE::mapFromSource( model->index( sourceIdx.row(),0,sourceIdx.parent()))
00081 .child( 0, sourceIdx.column() );
00082 }
00083 }
00084 #endif
00085 return BASE::mapFromSource( sourceIdx.model()->index( sourceIdx.row(),0,sourceIdx.parent()));
00086 }
00087 else return QModelIndex();
00088 }
00089
00090 QModelIndex ProxyModel::mapToSource( const QModelIndex& proxyIdx ) const
00091 {
00092 if( proxyIdx.isValid() ) {
00093 #if 0
00094 if ( calendarMode() && proxyIdx.column() > 0 ) {
00095 return BASE::mapToSource( proxyIdx.model()->index( proxyIdx.column(), 0, proxyIdx ) );
00096 }
00097 #endif
00098 return BASE::mapToSource( proxyIdx );
00099 }
00100 else return QModelIndex();
00101 }
00102
00103 void ProxyModel::setColumn( int ganttrole, int col )
00104 {
00105 d->columnMap[ganttrole] = col;
00106 }
00107
00108 int ProxyModel::column( int ganttrole ) const
00109 {
00110 return d->columnMap[ganttrole];
00111 }
00112
00113 void ProxyModel::setRole( int ganttrole, int role )
00114 {
00115 d->roleMap[ganttrole] = role;
00116 }
00117
00118 int ProxyModel::role( int ganttrole ) const
00119 {
00120 return d->roleMap[ganttrole];
00121 }
00122
00123 #if 0
00124 void ProxyModel::setCalendarMode( bool enable )
00125 {
00126 if ( d->calendarMode != enable ) {
00127 d->calendarMode = enable;
00128 reset();
00129 }
00130 }
00131
00132 bool ProxyModel::calendarMode() const
00133 {
00134 return d->calendarMode;
00135 }
00136 #endif
00137
00138 int ProxyModel::rowCount( const QModelIndex& proxyIndex ) const
00139 {
00140
00141 return BASE::rowCount( proxyIndex );
00142 }
00143
00144 int ProxyModel::columnCount( const QModelIndex& proxyIndex ) const
00145 {
00146 return qMin( sourceModel()->columnCount( mapToSource( proxyIndex ) ), 1 );
00147 }
00148
00149 QVariant ProxyModel::data( const QModelIndex& proxyIdx, int role ) const
00150 {
00151 int srole = role;
00152 int scol = proxyIdx.column();
00153 QHash<int, int>::const_iterator it = d->roleMap.find( role );
00154 if ( it != d->roleMap.end() ) srole = *it;
00155 it = d->columnMap.find( role );
00156 if ( it != d->columnMap.end() ) scol = *it;
00157
00158
00159
00160
00161 const QAbstractItemModel* model = sourceModel();
00162 return model->data( model->index( proxyIdx.row(), scol, mapToSource( proxyIdx.parent() ) ), srole );
00163 }
00164
00165 bool ProxyModel::setData( const QModelIndex& proxyIdx, const QVariant& value, int role )
00166 {
00167 int srole = role;
00168 int scol = proxyIdx.column();
00169 QHash<int, int>::const_iterator it = d->roleMap.find( role );
00170 if ( it != d->roleMap.end() ) srole = *it;
00171 it = d->columnMap.find( role );
00172 if ( it != d->columnMap.end() ) scol = *it;
00173
00174 QAbstractItemModel* model = sourceModel();
00175 return model->setData( model->index( proxyIdx.row(), scol, mapToSource( proxyIdx.parent() ) ), value, srole );
00176 }
00177
00178 #include "moc_kdganttproxymodel.cpp"