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

source code of qtcharts/src/charts/layout/polarchartlayout.cpp