KD Chart API Documentation 3.1
Loading...
Searching...
No Matches
kdganttforwardingproxymodel.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
12
13#include <QStringList>
14#include <cassert>
15
16using namespace KDGantt;
17
19
27
31
34{
35 if (!sourceIndex.isValid())
36 return QModelIndex();
37 assert(sourceIndex.model() == sourceModel());
38
39 // Create an index that preserves the internal pointer from the source;
40 // this way KDDataConverterProxyModel preserves the structure of the source model
41 return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
42}
43#ifdef __GNUC__
44#if __GNUC__ > 3
45#define ATTRIBUTE __attribute__((__may_alias__))
46#endif
47#else
48#define ATTRIBUTE
49#endif
50namespace {
51// Think this is ugly? Well, it's not from me, it comes from QProxyModel
52struct ATTRIBUTE KDPrivateModelIndex
53{
54 int r, c;
55 void *p;
56 const QAbstractItemModel *m;
57};
58}
59
62{
63 if (!proxyIndex.isValid())
64 return QModelIndex();
65 assert(proxyIndex.model() == this);
66 // So here we need to create a source index which holds that internal pointer.
67 // No way to pass it to sourceModel()->index... so we have to do the ugly way:
69 auto *hack = reinterpret_cast<KDPrivateModelIndex *>(&sourceIndex);
70 hack->r = proxyIndex.row();
71 hack->c = proxyIndex.column();
72 hack->p = proxyIndex.internalPointer();
73 hack->m = sourceModel();
74 assert(sourceIndex.isValid());
75 return sourceIndex;
76}
77
83{
84 if (sourceModel())
85 sourceModel()->disconnect(this);
87
88 if (!model)
89 return;
90
95
98
107
116}
117
122{
123 // The matching signal is emitted be reset()
124}
125
130{
131 // qDebug() << "ForwardingProxyModel::sourceModelReset()";
134}
135
141{
142 // qDebug() << "ForwardingProxyModel::sourceLayoutAboutToBeChanged()";
144}
145
150{
151 // qDebug() << "ForwardingProxyModel::sourceLayoutChanged()";
154}
155
160{
161 // qDebug() << "ForwardingProxyModel::sourceDataChanged("<<from<<to<<")";
163}
164
169 int start,
170 int end)
171{
173}
174
178void ForwardingProxyModel::sourceColumnsInserted(const QModelIndex &parentIdx, int start, int end)
179{
181 Q_UNUSED(start);
182 Q_UNUSED(end);
184}
185
190 int start,
191 int end)
192{
194}
195
199void ForwardingProxyModel::sourceColumnsRemoved(const QModelIndex &parentIdx, int start, int end)
200{
202 Q_UNUSED(start);
203 Q_UNUSED(end);
205}
206
210void ForwardingProxyModel::sourceRowsAboutToBeInserted(const QModelIndex &parentIdx, int start, int end)
211{
213}
214
218void ForwardingProxyModel::sourceRowsInserted(const QModelIndex &parentIdx, int start, int end)
219{
221 Q_UNUSED(start);
222 Q_UNUSED(end);
224}
225
229void ForwardingProxyModel::sourceRowsAboutToBeRemoved(const QModelIndex &parentIdx, int start, int end)
230{
232}
233
237void ForwardingProxyModel::sourceRowsRemoved(const QModelIndex &parentIdx, int start, int end)
238{
240 Q_UNUSED(start);
241 Q_UNUSED(end);
243}
244
247{
248 return sourceModel()->rowCount(mapToSource(idx));
249}
250
253{
254 return sourceModel()->columnCount(mapToSource(idx));
255}
256
258QModelIndex ForwardingProxyModel::index(int row, int column, const QModelIndex &parent) const
259{
260 return mapFromSource(sourceModel()->index(row, column, mapToSource(parent)));
261}
262
268
270bool ForwardingProxyModel::setData(const QModelIndex &index, const QVariant &value, int role)
271{
272 // qDebug() << "ForwardingProxyModel::setData( " << index<<value<< role<<")";
273 return sourceModel()->setData(mapToSource(index), value, role);
274}
275
276QMimeData *ForwardingProxyModel::mimeData(const QModelIndexList &indexes) const
277{
278 QModelIndexList source_indexes;
279 for (int i = 0; i < indexes.count(); ++i)
280 source_indexes << mapToSource(indexes.at(i));
281 return sourceModel()->mimeData(source_indexes);
282}
283
284bool ForwardingProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
285{
286 if ((row == -1) && (column == -1))
287 return sourceModel()->dropMimeData(data, action, -1, -1, mapToSource(parent));
288 int source_destination_row = -1;
291 if (row == rowCount(parent)) {
294 } else {
295 QModelIndex proxy_index = index(row, column, parent);
299 source_parent = source_index.parent();
300 }
302}
303
305{
306 return sourceModel()->mimeTypes();
307}
308
310{
311 return sourceModel()->supportedDropActions();
312}
313
314#include "moc_kdganttforwardingproxymodel.cpp"
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
Converts indexes in the source model to indexes in the proxy model.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
Converts indexes in the proxy model to indexes in the source model.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
ForwardingProxyModel(QObject *parent=nullptr)
Constructor.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
virtual void sourceModelAboutToBeReset()
Called when the source model is about to be reset.
virtual void sourceRowsRemoved(const QModelIndex &, int start, int end)
Called after rows have been removed from the source model.
virtual void sourceColumnsAboutToBeInserted(const QModelIndex &idx, int start, int end)
Called just before columns are inserted into the source model.
virtual void sourceLayoutAboutToBeChanged()
Called just before the layout of the source model is changed.
virtual void sourceDataChanged(const QModelIndex &from, const QModelIndex &to)
Called when the data in an existing item in the source model changes.
Qt::DropActions supportedDropActions() const override
virtual void sourceColumnsAboutToBeRemoved(const QModelIndex &idx, int start, int end)
Called just before columns are removed from the source model.
virtual void sourceLayoutChanged()
Called when the layout of the source model has changed.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
int rowCount(const QModelIndex &idx=QModelIndex()) const override
virtual void sourceColumnsRemoved(const QModelIndex &idx, int start, int end)
Called after columns have been removed from the source model.
virtual void sourceModelReset()
Called when the source model is reset.
void setSourceModel(QAbstractItemModel *model) override
Sets the model to be used as the source model for this proxy.
virtual void sourceRowsInserted(const QModelIndex &idx, int start, int end)
Called after rows have been inserted into the source model.
int columnCount(const QModelIndex &idx=QModelIndex()) const override
virtual void sourceRowsAboutToBeRemoved(const QModelIndex &, int start, int end)
Called just before rows are removed from the source model.
virtual void sourceColumnsInserted(const QModelIndex &idx, int start, int end)
Called after columns have been inserted into the source model.
virtual void sourceRowsAboutToBeInserted(const QModelIndex &idx, int start, int end)
Called just before rows are inserted into the source model.
QMimeData * mimeData(const QModelIndexList &indexes) const override
QAbstractProxyModel BASE
void beginInsertColumns(const QModelIndex &parent, int first, int last)
void beginInsertRows(const QModelIndex &parent, int first, int last)
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
void beginRemoveRows(const QModelIndex &parent, int first, int last)
void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last)
void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
void columnsInserted(const QModelIndex &parent, int first, int last)
void columnsRemoved(const QModelIndex &parent, int first, int last)
QModelIndex createIndex(int row, int column, void *ptr) const const
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
void layoutAboutToBeChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
void layoutChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
void modelAboutToBeReset()
void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
void rowsInserted(const QModelIndex &parent, int first, int last)
void rowsRemoved(const QModelIndex &parent, int first, int last)
virtual QVariant data(const QModelIndex &proxyIndex, int role) const const override
virtual void setSourceModel(QAbstractItemModel *sourceModel)
int row() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
T qobject_cast(QObject *object)
DropAction

© 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