KD Chart API Documentation 3.1
Loading...
Searching...
No Matches
kdganttproxymodel.cpp
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of the KD Chart library.
4**
5** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6**
7** SPDX-License-Identifier: MIT
8**
9****************************************************************************/
10
11#include "kdganttproxymodel.h"
12#include "kdganttproxymodel_p.h"
13
14using namespace KDGantt;
15
17
18ProxyModel::Private::Private(ProxyModel *_q)
19#if 0
20 : calendarMode( false )
21#endif
22{
23 Q_UNUSED(_q); // for now
24
25 columnMap[Qt::DisplayRole] = 0;
26 columnMap[ItemTypeRole] = 1;
27 columnMap[StartTimeRole] = 2;
28 columnMap[EndTimeRole] = 3;
29 columnMap[TaskCompletionRole] = 4;
30 columnMap[LegendRole] = 5;
31
35 roleMap[EndTimeRole] = EndTimeRole;
37 roleMap[LegendRole] = Qt::DisplayRole;
38}
39
41 : BASE(parent)
42 , _d(new Private(this))
43{
44 init();
45}
46
48{
49 delete _d;
50 _d = nullptr;
51}
52
53#define d d_func()
54
55void ProxyModel::init()
56{
57}
58
60{
61#if 0
62 if ( sourceIdx.isValid() ) {
63 if ( calendarMode() ) {
64 const QAbstractItemModel* model = sourceIdx.model();
65 if ( model->hasChildren( sourceIdx ) ) {
66 return BASE::mapFromSource( model->index( sourceIdx.row(),0,sourceIdx.parent()));
67 } else {
68 // Map children to columns
69 return BASE::mapFromSource( model->index( sourceIdx.row(),0,sourceIdx.parent()))
70 .child( 0, sourceIdx.column() );
71 }
72 }
73 return BASE::mapFromSource( sourceIdx.model()->index( sourceIdx.row(),0,sourceIdx.parent()));
74 }
75 else return QModelIndex();
76#else
77 return BASE::mapFromSource(sourceIdx.model() ? sourceIdx.model()->index(sourceIdx.row(), 0, sourceIdx.parent()) : QModelIndex());
78#endif
79}
80
82{
83#if 0
84 if ( proxyIdx.isValid() ) {
85 if ( calendarMode() && proxyIdx.column() > 0 ) {
86 return BASE::mapToSource( proxyIdx.model()->index( proxyIdx.column(), 0, proxyIdx ) );
87 }
89 }
90 else return QModelIndex();
91#else
93#endif
94}
95
96void ProxyModel::setColumn(int ganttrole, int col)
97{
98 d->columnMap[ganttrole] = col;
99}
100
101int ProxyModel::column(int ganttrole) const
102{
103 return d->columnMap[ganttrole];
104}
105
106void ProxyModel::setRole(int ganttrole, int role)
107{
108 d->roleMap[ganttrole] = role;
109}
110
111int ProxyModel::role(int ganttrole) const
112{
113 return d->roleMap[ganttrole];
114}
115
116#if 0
117void ProxyModel::setCalendarMode( bool enable )
118{
119 if ( d->calendarMode != enable ) {
120 d->calendarMode = enable;
121 reset();
122 }
123}
124
125bool ProxyModel::calendarMode() const
126{
127 return d->calendarMode;
128}
129#endif
130
131int ProxyModel::rowCount(const QModelIndex &proxyIndex) const
132{
133 // TODO
135}
136
137int ProxyModel::columnCount(const QModelIndex &proxyIndex) const
138{
140}
141
142QVariant ProxyModel::data(const QModelIndex &proxyIdx, int role) const
143{
144 int srole = role;
145 int scol = proxyIdx.column();
146 QHash<int, int>::const_iterator it = d->roleMap.find(role);
147 if (it != d->roleMap.end())
148 srole = *it;
149 it = d->columnMap.find(role);
150 if (it != d->columnMap.end())
151 scol = *it;
152
153#if 0
154 qDebug() << "mapping "<<static_cast<ItemDataRole>(role)<<", "<<proxyIdx.column()
155 << " => " << static_cast<ItemDataRole>(srole)<<", " << scol
156 << "value="
157 << sourceModel()->data( sourceModel()->index( proxyIdx.row(), scol,
158 mapToSource( proxyIdx.parent() ) ), srole );
159#endif
160
161 const QAbstractItemModel *model = sourceModel();
162 return model->data(model->index(proxyIdx.row(), scol, mapToSource(proxyIdx.parent())), srole);
163}
164
165bool ProxyModel::setData(const QModelIndex &proxyIdx, const QVariant &value, int role)
166{
167 int srole = role;
168 int scol = proxyIdx.column();
169 QHash<int, int>::const_iterator it = d->roleMap.constFind(role);
170 if (it != d->roleMap.constEnd())
171 srole = *it;
172 it = d->columnMap.constFind(role);
173 if (it != d->columnMap.constEnd())
174 scol = *it;
175
177 return model->setData(model->index(proxyIdx.row(), scol, mapToSource(proxyIdx.parent())), value, srole);
178}
179
180#include "moc_kdganttproxymodel.cpp"
int role(int ganttrole) const
void setRole(int ganttrole, int role)
int column(int ganttrole) const
QVariant data(const QModelIndex &idx, int role=Qt::DisplayRole) const override
int columnCount(const QModelIndex &idx) const override
void setColumn(int ganttrole, int col)
QModelIndex mapFromSource(const QModelIndex &idx) const override
Converts indexes in the source model to indexes in the proxy model.
QModelIndex mapToSource(const QModelIndex &proxyIdx) const override
Converts indexes in the proxy model to indexes in the source model.
int rowCount(const QModelIndex &idx) const override
ProxyModel(QObject *parent=nullptr)
bool setData(const QModelIndex &idx, const QVariant &value, int role=Qt::EditRole) override
ForwardingProxyModel BASE
ItemDataRole
KDGantt::KDGanttRoleBase The base value used for the KDGantt role enum values.
@ TaskCompletionRole
virtual QVariant data(const QModelIndex &index, int role) const const=0
virtual bool hasChildren(const QModelIndex &parent) const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual int rowCount(const QModelIndex &parent) const const=0
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const const=0
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const const=0
QModelIndex child(int row, int column) const const
T qobject_cast(QObject *object)
DisplayRole

© 2001 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-chart/
Generated on Thu Apr 11 2024 00:04:50 for KD Chart API Documentation by doxygen 1.9.8