1// Copyright (C) 2016 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 LEGENDLAYOUT_H
14#define LEGENDLAYOUT_H
15#include <QtWidgets/QGraphicsLayout>
16#include <QtCharts/QChartGlobal>
17#include <QtCharts/private/qchartglobal_p.h>
18
19QT_BEGIN_NAMESPACE
20
21class QLegend;
22class LegendMarkerItem;
23
24class Q_CHARTS_PRIVATE_EXPORT LegendLayout : public QGraphicsLayout
25{
26public:
27
28 LegendLayout(QLegend *legend);
29 virtual ~LegendLayout();
30
31 void setGeometry(const QRectF &rect) override;
32
33 void setOffset(qreal x, qreal y);
34 QPointF offset() const;
35
36 void invalidate() override;
37protected:
38 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
39 int count() const override { return 0; }
40 QGraphicsLayoutItem *itemAt(int) const override { return 0; };
41 void removeAt(int) override {};
42
43private:
44 void setAttachedGeometry(const QRectF &rect);
45 void setDettachedGeometry(const QRectF &rect);
46
47 struct LegendWidthStruct {
48 LegendMarkerItem *item;
49 qreal width;
50 };
51 static bool widthLongerThan(const LegendWidthStruct *item1,
52 const LegendWidthStruct *item2);
53
54private:
55 QLegend *m_legend;
56 qreal m_offsetX;
57 qreal m_offsetY;
58 qreal m_minOffsetX;
59 qreal m_minOffsetY;
60 qreal m_maxOffsetX;
61 qreal m_maxOffsetY;
62 qreal m_width;
63 qreal m_height;
64};
65
66QT_END_NAMESPACE
67
68#endif
69

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