Typo found by Yuri Chornoivan
[kdepim.git] / kdgantt / kdganttproxymodel.cpp
blob0cfc7a01cd2f0124d07f878dd7ba1b7ec471d8bf
1 /****************************************************************************
2 ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Gantt library.
5 **
6 ** This file may be used under the terms of the GNU General Public
7 ** License versions 2.0 or 3.0 as published by the Free Software
8 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
9 ** included in the packaging of this file. Alternatively you may (at
10 ** your option) use any later version of the GNU General Public
11 ** License if such license has been publicly approved by
12 ** Klarälvdalens Datakonsult AB (or its successors, if any).
13 **
14 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
15 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
16 ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
17 ** not expressly granted herein.
18 **
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 **********************************************************************/
23 #include "kdganttproxymodel.h"
24 #include "kdganttproxymodel_p.h"
27 using namespace KDGantt;
29 typedef ForwardingProxyModel BASE;
31 ProxyModel::Private::Private( ProxyModel* _q )
32 #if 0
33 : calendarMode( false )
34 #endif
36 Q_UNUSED( _q ); // for now
38 //columnMap[Qt::DisplayRole] = 0; Separate ItemNameRole ??
39 columnMap[ItemTypeRole] = 1;
40 columnMap[StartTimeRole] = 2;
41 columnMap[EndTimeRole] = 3;
42 columnMap[TaskCompletionRole] = 4;
43 columnMap[LegendRole] = 5;
45 roleMap[Qt::DisplayRole] = Qt::DisplayRole;
46 roleMap[ItemTypeRole] = Qt::DisplayRole;
47 roleMap[StartTimeRole] = Qt::DisplayRole;
48 roleMap[EndTimeRole] = Qt::DisplayRole;
49 roleMap[TaskCompletionRole] = Qt::DisplayRole;
50 roleMap[LegendRole] = Qt::DisplayRole;
53 ProxyModel::ProxyModel( QObject* parent )
54 : BASE( parent ), _d( new Private( this ) )
56 init();
59 ProxyModel::~ProxyModel()
61 delete _d; _d = 0;
64 #define d d_func()
66 void ProxyModel::init()
70 QModelIndex ProxyModel::mapFromSource( const QModelIndex& sourceIdx ) const
72 if( sourceIdx.isValid() ) {
73 #if 0
74 if ( calendarMode() ) {
75 const QAbstractItemModel* model = sourceIdx.model();
76 if ( model->hasChildren( sourceIdx ) ) {
77 return BASE::mapFromSource( model->index( sourceIdx.row(),0,sourceIdx.parent()));
78 } else {
79 // Map children to columns
80 return BASE::mapFromSource( model->index( sourceIdx.row(),0,sourceIdx.parent()))
81 .child( 0, sourceIdx.column() );
84 #endif
85 return BASE::mapFromSource( sourceIdx );
87 else return QModelIndex();
90 QModelIndex ProxyModel::mapToSource( const QModelIndex& proxyIdx ) const
92 if( proxyIdx.isValid() ) {
93 #if 0
94 if ( calendarMode() && proxyIdx.column() > 0 ) {
95 return BASE::mapToSource( proxyIdx.model()->index( proxyIdx.column(), 0, proxyIdx ) );
97 #endif
98 return BASE::mapToSource( proxyIdx );
100 else return QModelIndex();
103 void ProxyModel::setColumn( int ganttrole, int col )
105 d->columnMap[ganttrole] = col;
108 int ProxyModel::column( int ganttrole ) const
110 return d->columnMap[ganttrole];
113 void ProxyModel::setRole( int ganttrole, int role )
115 d->roleMap[ganttrole] = role;
118 int ProxyModel::role( int ganttrole ) const
120 return d->roleMap[ganttrole];
123 #if 0
124 void ProxyModel::setCalendarMode( bool enable )
126 if ( d->calendarMode != enable ) {
127 d->calendarMode = enable;
128 reset();
132 bool ProxyModel::calendarMode() const
134 return d->calendarMode;
136 #endif
138 int ProxyModel::rowCount( const QModelIndex& proxyIndex ) const
140 // TODO
141 return BASE::rowCount( proxyIndex );
144 int ProxyModel::columnCount( const QModelIndex& proxyIndex ) const
146 return qMin( sourceModel()->columnCount( mapToSource( proxyIndex ) ), 1 );
149 QVariant ProxyModel::data( const QModelIndex& proxyIdx, int role ) const
151 int srole = role;
152 int scol = proxyIdx.column();
153 QHash<int, int>::const_iterator it = d->roleMap.find( role );
154 if ( it != d->roleMap.end() ) srole = *it;
155 it = d->columnMap.find( role );
156 if ( it != d->columnMap.end() ) scol = *it;
158 //qDebug() << "mapping role"<<static_cast<ItemDataRole>(role)<<"to"<<static_cast<ItemDataRole>(srole);
159 //qDebug() << "mapping column"<<proxyIdx.column()<<"to"<<scol;
161 const QAbstractItemModel* model = sourceModel();
162 return model->data( model->index( proxyIdx.row(), scol, mapToSource( proxyIdx.parent() ) ), srole );
165 bool ProxyModel::setData( const QModelIndex& proxyIdx, const QVariant& value, int role )
167 int srole = role;
168 int scol = proxyIdx.column();
169 QHash<int, int>::const_iterator it = d->roleMap.find( role );
170 if ( it != d->roleMap.end() ) srole = *it;
171 it = d->columnMap.find( role );
172 if ( it != d->columnMap.end() ) scol = *it;
174 QAbstractItemModel* model = sourceModel();
175 return model->setData( model->index( proxyIdx.row(), scol, mapToSource( proxyIdx.parent() ) ), value, srole );
178 #include "moc_kdganttproxymodel.cpp"