1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses |
5 | |
6 | #include <private/polarchartlayout_p.h> |
7 | #include <private/chartpresenter_p.h> |
8 | #include <private/polarchartaxis_p.h> |
9 | #include <QtCore/QDebug> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | PolarChartLayout::PolarChartLayout(ChartPresenter *presenter) |
14 | : AbstractChartLayout(presenter) |
15 | { |
16 | } |
17 | |
18 | PolarChartLayout::~PolarChartLayout() |
19 | { |
20 | } |
21 | |
22 | QRectF PolarChartLayout::calculateAxisGeometry(const QRectF &geometry, |
23 | const QList<ChartAxisElement *> &axes, |
24 | bool update) const |
25 | { |
26 | // How to handle multiple angular/radial axes? |
27 | qreal axisRadius = geometry.height() / 2.0; |
28 | if (geometry.width() < geometry.height()) |
29 | axisRadius = geometry.width() / 2.0; |
30 | |
31 | int titleHeight = 0; |
32 | foreach (ChartAxisElement *chartAxis, axes) { |
33 | if (!chartAxis->isVisible()) |
34 | continue; |
35 | |
36 | PolarChartAxis *polarChartAxis = static_cast<PolarChartAxis *>(chartAxis); |
37 | qreal radius = polarChartAxis->preferredAxisRadius(maxSize: geometry.size()); |
38 | if (radius < axisRadius) |
39 | axisRadius = radius; |
40 | |
41 | if (chartAxis->axis()->orientation() == Qt::Horizontal |
42 | && chartAxis->axis()->isTitleVisible() |
43 | && !chartAxis->axis()->titleText().isEmpty()) { |
44 | // If axis has angular title, adjust geometry down by the space title takes |
45 | QRectF dummyRect = ChartPresenter::textBoundingRect(font: chartAxis->axis()->titleFont(), text: chartAxis->axis()->titleText()); |
46 | titleHeight = (dummyRect.height() / 2.0) + chartAxis->titlePadding(); |
47 | } |
48 | } |
49 | |
50 | QRectF axisRect; |
51 | axisRect.setSize(QSizeF(axisRadius * 2.0, axisRadius * 2.0)); |
52 | axisRect.moveCenter(p: geometry.center()); |
53 | axisRect.adjust(xp1: 0, yp1: titleHeight, xp2: 0, yp2: titleHeight); |
54 | |
55 | if (update) { |
56 | foreach (ChartAxisElement *chartAxis, axes) |
57 | chartAxis->setGeometry(axis: axisRect, grid: QRectF()); |
58 | } |
59 | |
60 | return axisRect; |
61 | } |
62 | |
63 | QRectF PolarChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxisElement *> &axes) const |
64 | { |
65 | Q_UNUSED(axes); |
66 | return minimum; |
67 | } |
68 | |
69 | QT_END_NAMESPACE |
70 |