KD Chart API Documentation 3.1
Loading...
Searching...
No Matches
KDChartAbstractProxyModel.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 <QDebug>
14
15#include <KDABLibFakes>
16
17#ifdef __GNUC__
18#if __GNUC__ > 3
19#define MAY_ALIAS __attribute__((__may_alias__))
20#endif
21#else
22#define MAY_ALIAS
23#endif
24
25namespace KDChart {
26
33
34// Allows access to QModelIndex's private data via type punning and a compatible data layout.
35// Due to inlining in Qt and no d-pointer, it is safe to assume that the layout won't change except
36// between major Qt versions. As it happens, the layout is the same in Qt4 and Qt5.
37// The only change is void * -> quintptr.
38struct MAY_ALIAS KDPrivateModelIndex
39{
40 int r, c;
41 void *p;
42 const QAbstractItemModel *m;
43};
44
46{
47 if (!sourceIndex.isValid())
48 return QModelIndex();
49 // qDebug() << "sourceIndex.model()="<<sourceIndex.model();
50 // qDebug() << "model()="<<sourceModel();
51 Q_ASSERT(sourceIndex.model() == sourceModel());
52
53 // Create an index that preserves the internal pointer from the source;
54 // this way AbstractProxyModel preserves the structure of the source model
55 return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
56}
57
59{
60 if (!sourceModel() || !proxyIndex.isValid())
61 return QModelIndex();
62 if (proxyIndex.model() != this)
63 qDebug() << proxyIndex.model() << this;
64 Q_ASSERT(proxyIndex.model() == this);
65 // So here we need to create a source index which holds that internal pointer.
66 // No way to pass it to sourceModel()->index... so we have to do the ugly way:
68 auto *hack = reinterpret_cast<KDPrivateModelIndex *>(&sourceIndex);
69 hack->r = proxyIndex.row();
70 hack->c = proxyIndex.column();
71 hack->p = proxyIndex.internalPointer();
72 hack->m = sourceModel();
73 Q_ASSERT(sourceIndex.isValid());
74 return sourceIndex;
75}
76
77QModelIndex AbstractProxyModel::index(int row, int col, const QModelIndex &index) const
78{
79 if (!sourceModel())
80 return QModelIndex();
82}
83
90}
#define MAY_ALIAS
QModelIndex index(int row, int col, const QModelIndex &index) const override
Reimplemented for internal purposes.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
Reimplemented for internal purposes.
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
Reimplemented for internal purposes.
AbstractProxyModel(QObject *parent=nullptr)
QModelIndex createIndex(int row, int column, void *ptr) const const
int row() const const
QObject * parent() const const
T qobject_cast(QObject *object)

© 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 Wed May 1 2024 00:01:10 for KD Chart API Documentation by doxygen 1.9.8