1// Copyright (C) 2021 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 Qt Chart 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
13#ifndef QLEGEND_P_H
14#define QLEGEND_P_H
15
16#include <QtCharts/QLegend>
17#include <QtCharts/private/qchartglobal_p.h>
18#include <QtCore/qlist.h>
19#include <QtCore/qhash.h>
20
21QT_BEGIN_NAMESPACE
22
23class QChart;
24class ChartPresenter;
25class QAbstractSeries;
26class LegendLayout;
27class LegendMoveResizeHandler;
28class QLegendMarker;
29
30class Q_CHARTS_PRIVATE_EXPORT QLegendPrivate : public QObject
31{
32 Q_OBJECT
33public:
34 QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q);
35 ~QLegendPrivate();
36
37 void setOffset(const QPointF &offset);
38 QPointF offset() const;
39 int roundness(qreal size);
40
41 QGraphicsItemGroup* items() { return m_items; }
42
43 QList<QLegendMarker*> markers(QAbstractSeries *series = 0);
44 qreal maxMarkerWidth() const;
45
46 static QObject *relatedObject(const QLegendMarker *l);
47
48public Q_SLOTS:
49 void handleSeriesAdded(QAbstractSeries *series);
50 void handleSeriesRemoved(QAbstractSeries *series);
51 void handleSeriesVisibleChanged();
52 void handleCountChanged();
53
54private:
55 // Internal helpers
56 void insertMarkerHelper(QLegendMarker *marker);
57 void addMarkers(const QList<QLegendMarker *> &markers);
58 void removeMarkerHelper(QLegendMarker *marker);
59 void removeMarkers(const QList<QLegendMarker *> &markers);
60 void decorateMarker(QLegendMarker *marker);
61 void decorateMarkers(const QList<QLegendMarker *> &markers);
62 void updateToolTips();
63
64private:
65 QLegend *q_ptr;
66 ChartPresenter *m_presenter;
67 LegendLayout *m_layout;
68 LegendMoveResizeHandler *m_resizer;
69 QChart *m_chart;
70 QGraphicsItemGroup *m_items;
71 Qt::Alignment m_alignment;
72 QBrush m_brush;
73 QPen m_pen;
74 QFont m_font;
75 QBrush m_labelBrush;
76
77 qreal m_diameter;
78 bool m_attachedToChart;
79 bool m_backgroundVisible;
80 bool m_reverseMarkers;
81 bool m_showToolTips;
82 bool m_interactive;
83 QLegend::MarkerShape m_markerShape;
84
85 QList<QLegendMarker *> m_markers;
86 QList<QAbstractSeries *> m_series;
87
88 QHash<QGraphicsItem *, QLegendMarker *> m_markerHash;
89
90 friend class QLegend;
91 friend class LegendMarkerItem;
92 friend class LegendLayout;
93 friend class QLegendMarkerPrivate;
94 friend class LegendScroller;
95 friend class LegendMoveResizeHandler;
96};
97
98QT_END_NAMESPACE
99
100#endif
101

source code of qtcharts/src/charts/legend/qlegend_p.h