24 #include "kdganttproxymodel_p.h" 33 : calendarMode(
false )
38 columnMap[Qt::DisplayRole] = 0;
45 roleMap[Qt::DisplayRole] = Qt::DisplayRole;
54 :
BASE( parent ), _d( new Private( this ) )
66 void ProxyModel::init()
73 if ( sourceIdx.isValid() ) {
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()));
80 return BASE::mapFromSource( model->index( sourceIdx.row(),0,sourceIdx.parent()))
81 .child( 0, sourceIdx.column() );
84 return BASE::mapFromSource( sourceIdx.model()->index( sourceIdx.row(),0,sourceIdx.parent()));
86 else return QModelIndex();
88 return BASE::mapFromSource( sourceIdx.model()?sourceIdx.model()->index( sourceIdx.row(),0,sourceIdx.parent()):QModelIndex());
95 if ( proxyIdx.isValid() ) {
96 if ( calendarMode() && proxyIdx.column() > 0 ) {
97 return BASE::mapToSource( proxyIdx.model()->index( proxyIdx.column(), 0, proxyIdx ) );
99 return BASE::mapToSource( proxyIdx );
101 else return QModelIndex();
103 return BASE::mapToSource( proxyIdx );
109 d->columnMap[ganttrole] = col;
114 return d->columnMap[ganttrole];
119 d->roleMap[ganttrole] =
role;
124 return d->roleMap[ganttrole];
128 void ProxyModel::setCalendarMode(
bool enable )
130 if (
d->calendarMode != enable ) {
131 d->calendarMode = enable;
136 bool ProxyModel::calendarMode()
const 138 return d->calendarMode;
145 return BASE::rowCount( proxyIndex );
156 int scol = proxyIdx.column();
157 QHash<int, int>::const_iterator it =
d->roleMap.find( role );
158 if ( it !=
d->roleMap.end() ) srole = *it;
159 it =
d->columnMap.find( role );
160 if ( it !=
d->columnMap.end() ) scol = *it;
163 qDebug() <<
"mapping "<<
static_cast<ItemDataRole>(
role)<<
", "<<proxyIdx.column()
164 <<
" => " <<
static_cast<ItemDataRole>(srole)<<
", " << scol
166 << sourceModel()->data( sourceModel()->
index( proxyIdx.row(), scol,
170 const QAbstractItemModel* model = sourceModel();
171 return model->data( model->index( proxyIdx.row(), scol,
mapToSource( proxyIdx.parent() ) ), srole );
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;
183 QAbstractItemModel* model = sourceModel();
184 return model->setData( model->index( proxyIdx.row(), scol,
mapToSource( proxyIdx.parent() ) ), value, srole );
187 #include "moc_kdganttproxymodel.cpp"
ProxyModel(QObject *parent=0)
int rowCount(const QModelIndex &idx) const override
int role(int ganttrole) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
ForwardingProxyModel BASE
QModelIndex mapFromSource(const QModelIndex &idx) const override
void setRole(int ganttrole, int role)
bool setData(const QModelIndex &idx, const QVariant &value, int role=Qt::EditRole) override
Class only listed here to document inheritance of some KDChart classes.
int column(int ganttrole) const
void setColumn(int ganttrole, int col)
int columnCount(const QModelIndex &idx) const override
QModelIndex mapToSource(const QModelIndex &proxyIdx) const override
QVariant data(const QModelIndex &idx, int role=Qt::DisplayRole) const override
Class only listed here to document inheritance of some KDChart classes.