• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kdgantt2

  • sources
  • kde-4.12
  • kdepim
  • kdgantt2
kdganttproxymodel.cpp
Go to the documentation of this file.
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 distributed and/or modified under the terms of the
7  ** GNU General Public License version 2 as published by the Free Software
8  ** Foundation and appearing in the file LICENSE.GPL included in the
9  ** packaging of this file.
10  **
11  ** Licensees holding valid commercial KD Gantt licenses may use this file in
12  ** accordance with the KD Gantt Commercial License Agreement provided with
13  ** the Software.
14  **
15  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17  **
18  ** See http://www.kdab.net/kdgantt for
19  ** information about KD Gantt Commercial License Agreements.
20  **
21  ** Contact info@kdab.net if any conditions of this
22  ** licensing are not clear to you.
23  **
24  **********************************************************************/
25 #include "kdganttproxymodel.h"
26 #include "kdganttproxymodel_p.h"
27 
28 
29 using namespace KDGantt;
30 
31 typedef ForwardingProxyModel BASE;
32 
33 ProxyModel::Private::Private( ProxyModel* _q )
34 #if 0
35  : calendarMode( false )
36 #endif
37 {
38  Q_UNUSED( _q ); // for now
39 
40  columnMap[Qt::DisplayRole] = 0;
41  columnMap[ItemTypeRole] = 1;
42  columnMap[StartTimeRole] = 2;
43  columnMap[EndTimeRole] = 3;
44  columnMap[TaskCompletionRole] = 4;
45  columnMap[LegendRole] = 5;
46 
47  roleMap[Qt::DisplayRole] = Qt::DisplayRole;
48  roleMap[ItemTypeRole] = Qt::DisplayRole;
49  roleMap[StartTimeRole] = Qt::DisplayRole;
50  roleMap[EndTimeRole] = Qt::DisplayRole;
51  roleMap[TaskCompletionRole] = Qt::DisplayRole;
52  roleMap[LegendRole] = Qt::DisplayRole;
53 }
54 
55 ProxyModel::ProxyModel( QObject* parent )
56  : BASE( parent ), _d( new Private( this ) )
57 {
58  init();
59 }
60 
61 ProxyModel::~ProxyModel()
62 {
63  delete _d; _d = 0;
64 }
65 
66 #define d d_func()
67 
68 void ProxyModel::init()
69 {
70 }
71 
72 QModelIndex ProxyModel::mapFromSource( const QModelIndex& sourceIdx ) const
73 {
74 #if 0
75  if( sourceIdx.isValid() ) {
76  if ( calendarMode() ) {
77  const QAbstractItemModel* model = sourceIdx.model();
78  if ( model->hasChildren( sourceIdx ) ) {
79  return BASE::mapFromSource( model->index( sourceIdx.row(),0,sourceIdx.parent()));
80  } else {
81  // Map children to columns
82  return BASE::mapFromSource( model->index( sourceIdx.row(),0,sourceIdx.parent()))
83  .child( 0, sourceIdx.column() );
84  }
85  }
86  return BASE::mapFromSource( sourceIdx.model()->index( sourceIdx.row(),0,sourceIdx.parent()));
87  }
88  else return QModelIndex();
89 #else
90  return BASE::mapFromSource( sourceIdx.model()?sourceIdx.model()->index( sourceIdx.row(),0,sourceIdx.parent()):QModelIndex());
91 #endif
92 }
93 
94 QModelIndex ProxyModel::mapToSource( const QModelIndex& proxyIdx ) const
95 {
96 #if 0
97  if( proxyIdx.isValid() ) {
98  if ( calendarMode() && proxyIdx.column() > 0 ) {
99  return BASE::mapToSource( proxyIdx.model()->index( proxyIdx.column(), 0, proxyIdx ) );
100  }
101  return BASE::mapToSource( proxyIdx );
102  }
103  else return QModelIndex();
104 #else
105  return BASE::mapToSource( proxyIdx );
106 #endif
107 }
108 
109 void ProxyModel::setColumn( int ganttrole, int col )
110 {
111  d->columnMap[ganttrole] = col;
112 }
113 
114 int ProxyModel::column( int ganttrole ) const
115 {
116  return d->columnMap[ganttrole];
117 }
118 
119 void ProxyModel::setRole( int ganttrole, int role )
120 {
121  d->roleMap[ganttrole] = role;
122 }
123 
124 int ProxyModel::role( int ganttrole ) const
125 {
126  return d->roleMap[ganttrole];
127 }
128 
129 #if 0
130 void ProxyModel::setCalendarMode( bool enable )
131 {
132  if ( d->calendarMode != enable ) {
133  d->calendarMode = enable;
134  reset();
135  }
136 }
137 
138 bool ProxyModel::calendarMode() const
139 {
140  return d->calendarMode;
141 }
142 #endif
143 
144 int ProxyModel::rowCount( const QModelIndex& proxyIndex ) const
145 {
146  // TODO
147  return BASE::rowCount( proxyIndex );
148 }
149 
150 int ProxyModel::columnCount( const QModelIndex& proxyIndex ) const
151 {
152  return qMin( sourceModel()->columnCount( mapToSource( proxyIndex ) ), 1 );
153 }
154 
155 QVariant ProxyModel::data( const QModelIndex& proxyIdx, int role ) const
156 {
157  int srole = role;
158  int scol = proxyIdx.column();
159  QHash<int, int>::const_iterator it = d->roleMap.find( role );
160  if ( it != d->roleMap.end() ) srole = *it;
161  it = d->columnMap.find( role );
162  if ( it != d->columnMap.end() ) scol = *it;
163 
164 #if 0
165  qDebug() << "mapping role"<<static_cast<ItemDataRole>(role)<<"to"<<static_cast<ItemDataRole>(srole);
166  qDebug() << "mapping column"<<proxyIdx.column()<<"to"<<scol
167  << "value="<<sourceModel()->data( sourceModel()->index( proxyIdx.row(), scol, mapToSource( proxyIdx.parent() ) ), srole );
168 #endif
169 
170  const QAbstractItemModel* model = sourceModel();
171  return model->data( model->index( proxyIdx.row(), scol, mapToSource( proxyIdx.parent() ) ), srole );
172 }
173 
174 bool ProxyModel::setData( const QModelIndex& proxyIdx, const QVariant& value, int role )
175 {
176  int srole = role;
177  int scol = proxyIdx.column();
178  QHash<int, int>::const_iterator it = d->roleMap.constFind( role );
179  if ( it != d->roleMap.constEnd() ) srole = *it;
180  it = d->columnMap.constFind( role );
181  if ( it != d->columnMap.constEnd() ) scol = *it;
182 
183  QAbstractItemModel* model = sourceModel();
184  return model->setData( model->index( proxyIdx.row(), scol, mapToSource( proxyIdx.parent() ) ), value, srole );
185 }
186 
187 #include "moc_kdganttproxymodel.cpp"
KDGantt::StartTimeRole
Definition: kdganttglobal.h:204
KDGantt::ForwardingProxyModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: kdganttforwardingproxymodel.cpp:261
QObject
BASE
ForwardingProxyModel BASE
Definition: kdganttproxymodel.cpp:31
KDGantt::ProxyModel::setData
bool setData(const QModelIndex &idx, const QVariant &value, int role=Qt::EditRole)
Definition: kdganttproxymodel.cpp:174
KDGantt::ProxyModel::mapToSource
QModelIndex mapToSource(const QModelIndex &proxyIdx) const
Definition: kdganttproxymodel.cpp:94
KDGantt::ProxyModel::columnCount
int columnCount(const QModelIndex &idx) const
Definition: kdganttproxymodel.cpp:150
KDGantt::ProxyModel::Private::Private
Private(ProxyModel *_q)
Definition: kdganttproxymodel.cpp:33
KDGantt::ItemTypeRole
Definition: kdganttglobal.h:207
KDGantt::ProxyModel::mapFromSource
QModelIndex mapFromSource(const QModelIndex &idx) const
Definition: kdganttproxymodel.cpp:72
KDGantt::ItemDataRole
ItemDataRole
Definition: kdganttglobal.h:202
kdganttproxymodel_p.h
KDGantt::LegendRole
Definition: kdganttglobal.h:208
KDGantt::ProxyModel::rowCount
int rowCount(const QModelIndex &idx) const
Definition: kdganttproxymodel.cpp:144
KDGantt::EndTimeRole
Definition: kdganttglobal.h:205
QAbstractProxyModel
KDGantt::ProxyModel
Definition: kdganttproxymodel.h:31
kdganttproxymodel.h
KDGantt::ForwardingProxyModel
Definition: kdganttforwardingproxymodel.h:33
KDGantt::TaskCompletionRole
Definition: kdganttglobal.h:206
KDGantt::ProxyModel::Private
Definition: kdganttproxymodel_p.h:29
KDGantt::ProxyModel::ProxyModel
ProxyModel(QObject *parent=0)
Definition: kdganttproxymodel.cpp:55
KDGantt::ProxyModel::~ProxyModel
virtual ~ProxyModel()
Definition: kdganttproxymodel.cpp:61
KDGantt::ProxyModel::data
QVariant data(const QModelIndex &idx, int role=Qt::DisplayRole) const
Definition: kdganttproxymodel.cpp:155
KDGantt::ProxyModel::column
int column(int ganttrole) const
Definition: kdganttproxymodel.cpp:114
KDGantt::ProxyModel::setColumn
void setColumn(int ganttrole, int col)
Definition: kdganttproxymodel.cpp:109
KDGantt::ProxyModel::setRole
void setRole(int ganttrole, int role)
Definition: kdganttproxymodel.cpp:119
KDGantt::ProxyModel::role
int role(int ganttrole) const
Definition: kdganttproxymodel.cpp:124
d
#define d
Definition: kdganttproxymodel.cpp:66
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:05 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdgantt2

Skip menu "kdgantt2"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal