summaryrefslogtreecommitdiffstats
path: root/src/graphs2d/piechart/qpiemodelmapper_p.h
blob: 50ffcb727be80f54d1dd29b5ae015f82846e8495 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

//  W A R N I N G
//  -------------
//
// This file is not part of the QtGraphs API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
#ifndef QPIEMODELMAPPER_P_H
#define QPIEMODELMAPPER_P_H
#include <QtGraphs/qpiemodelmapper.h>
#include <private/qobject_p.h>

QT_BEGIN_NAMESPACE

class QPieSlice;
class QPieSeries;
class QAbstractItemModel;

class QPieModelMapperPrivate : public QObjectPrivate
{
    Q_DECLARE_PUBLIC(QPieModelMapper)

public:
    explicit QPieModelMapperPrivate();
    ~QPieModelMapperPrivate() override;

    void onSliceLabelChanged(const QPieSlice *slice);
    void onSliceValueChanged(const QPieSlice *slice);
public Q_SLOTS:
    // for the model
    void onModelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
    void onModelRowsAdded(QModelIndex parent, qsizetype start, qsizetype end);
    void onModelRowsRemoved(QModelIndex parent, qsizetype start, qsizetype end);
    void onModelColumnsAdded(QModelIndex parent, qsizetype start, qsizetype end);
    void onModelColumnsRemoved(QModelIndex parent, qsizetype start, qsizetype end);
    void handleModelDestroyed();

    // for the series
    void onSlicesAdded(const QList<QPieSlice *> &slices);
    void onSlicesRemoved(const QList<QPieSlice *> &slices);
    void handleSeriesDestroyed();

    void initializePieFromModel();

private:
    QPieSlice *pieSlice(QModelIndex index) const;
    bool isLabelIndex(QModelIndex index) const;
    bool isValueIndex(QModelIndex index) const;
    QModelIndex valueModelIndex(qsizetype sliceIndex);
    QModelIndex labelModelIndex(qsizetype sliceIndex);
    void insertData(qsizetype start, qsizetype end);
    void removeData(qsizetype start, qsizetype end);

    void blockModelSignals(bool block = true);
    void blockSeriesSignals(bool block = true);

private:
    QPieSeries *m_series = nullptr;
    QList<QPieSlice *> m_slices;
    QAbstractItemModel *m_model = nullptr;
    qsizetype m_first = 0;
    qsizetype m_count = -1;
    Qt::Orientation m_orientation = Qt::Vertical;
    qsizetype m_valuesSection = -1;
    qsizetype m_labelsSection = -1;
    bool m_seriesSignalsBlock = false;
    bool m_modelSignalsBlock = false;

    Q_DISABLE_COPY_MOVE(QPieModelMapperPrivate)
};

QT_END_NAMESPACE

#endif // QPIEMODELMAPPER_P_H