1 | // Copyright (C) 2024 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | // W A R N I N G |
5 | // ------------- |
6 | // |
7 | // This file is not part of the QtGraphs API. It exists purely as an |
8 | // implementation detail. This header file may change from version to |
9 | // version without notice, or even be removed. |
10 | // |
11 | // We mean it. |
12 | #ifndef QPIEMODELMAPPER_P_H |
13 | #define QPIEMODELMAPPER_P_H |
14 | #include <QtGraphs/qpiemodelmapper.h> |
15 | #include <private/qobject_p.h> |
16 | |
17 | QT_BEGIN_NAMESPACE |
18 | |
19 | class QPieSlice; |
20 | class QPieSeries; |
21 | class QAbstractItemModel; |
22 | |
23 | class QPieModelMapperPrivate : public QObjectPrivate |
24 | { |
25 | Q_DECLARE_PUBLIC(QPieModelMapper) |
26 | |
27 | public: |
28 | explicit QPieModelMapperPrivate(); |
29 | ~QPieModelMapperPrivate() override; |
30 | |
31 | void onSliceLabelChanged(const QPieSlice *slice); |
32 | void onSliceValueChanged(const QPieSlice *slice); |
33 | public Q_SLOTS: |
34 | // for the model |
35 | void onModelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
36 | void onModelRowsAdded(QModelIndex parent, qsizetype start, qsizetype end); |
37 | void onModelRowsRemoved(QModelIndex parent, qsizetype start, qsizetype end); |
38 | void onModelColumnsAdded(QModelIndex parent, qsizetype start, qsizetype end); |
39 | void onModelColumnsRemoved(QModelIndex parent, qsizetype start, qsizetype end); |
40 | void handleModelDestroyed(); |
41 | |
42 | // for the series |
43 | void onSlicesAdded(const QList<QPieSlice *> &slices); |
44 | void onSlicesRemoved(const QList<QPieSlice *> &slices); |
45 | void handleSeriesDestroyed(); |
46 | |
47 | void initializePieFromModel(); |
48 | |
49 | private: |
50 | QPieSlice *pieSlice(QModelIndex index) const; |
51 | bool isLabelIndex(QModelIndex index) const; |
52 | bool isValueIndex(QModelIndex index) const; |
53 | QModelIndex valueModelIndex(qsizetype sliceIndex); |
54 | QModelIndex labelModelIndex(qsizetype sliceIndex); |
55 | void insertData(qsizetype start, qsizetype end); |
56 | void removeData(qsizetype start, qsizetype end); |
57 | |
58 | void blockModelSignals(bool block = true); |
59 | void blockSeriesSignals(bool block = true); |
60 | |
61 | private: |
62 | QPieSeries *m_series = nullptr; |
63 | QList<QPieSlice *> m_slices; |
64 | QAbstractItemModel *m_model = nullptr; |
65 | qsizetype m_first = 0; |
66 | qsizetype m_count = -1; |
67 | Qt::Orientation m_orientation = Qt::Vertical; |
68 | qsizetype m_valuesSection = -1; |
69 | qsizetype m_labelsSection = -1; |
70 | bool m_seriesSignalsBlock = false; |
71 | bool m_modelSignalsBlock = false; |
72 | |
73 | Q_DISABLE_COPY_MOVE(QPieModelMapperPrivate) |
74 | }; |
75 | |
76 | QT_END_NAMESPACE |
77 | |
78 | #endif // QPIEMODELMAPPER_P_H |
79 | |